mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-17 10:55:06 +00:00
Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
114ccf1ffb | ||
|
|
0e5c9f320e | ||
|
|
43f10b5e84 | ||
|
|
673cf548cc | ||
|
|
3470c6c7d1 | ||
|
|
acd079b9ac | ||
|
|
3a8c2bd8cf | ||
|
|
00a55f6888 | ||
|
|
58c6b7bdf3 | ||
|
|
7bba5bea50 |
No files matched your search
@@ -8,7 +8,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.gui;
|
||||
|
||||
import static forestry.core.inventory.ItemLocation.TYPE.PLAYER_INVENTORY;
|
||||
import static forestry.core.inventory.ItemLocation.Type.PLAYER_INVENTORY;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -53,6 +53,7 @@ public class GuiHandler implements IGuiHandler {
|
||||
* @param invSlotIdx Index or slot in player inventory should be in range [0, 40).
|
||||
*/
|
||||
public static void openGui(EntityPlayer entityPlayer, IGuiHandlerItem guiHandler, short data, int invSlotIdx) {
|
||||
assert invSlotIdx >= 0 && invSlotIdx < 40 : "Incorrect inventory index is used: " + invSlotIdx;
|
||||
int guiData = encodeGuiData(guiHandler, data, invSlotIdx);
|
||||
entityPlayer.openGui(ForestryAPI.instance, guiData, entityPlayer.worldObj, 0, 0, 0);
|
||||
}
|
||||
@@ -88,7 +89,7 @@ public class GuiHandler implements IGuiHandler {
|
||||
*/
|
||||
private static int encodeGuiData(IGuiHandlerForestry guiHandler, short data, int invSlotIdx) {
|
||||
// inventory slot idx will be encoded in third byte
|
||||
// player have 40 different inventory which means that we need 6 bits to encode all values.
|
||||
// player inventory has 40 slots which means that we need 6 bits to encode all values.
|
||||
// first 2 bits are reserved for type currently values 0(heldItem) and 1(item inventory) have meaning,
|
||||
// 2 and 3 are reserved for possible extension.
|
||||
if (invSlotIdx < -1 || invSlotIdx >= 40) {
|
||||
|
||||
@@ -5,24 +5,24 @@ package forestry.core.inventory;
|
||||
*/
|
||||
public class ItemLocation {
|
||||
|
||||
public enum TYPE {
|
||||
public enum Type {
|
||||
UNKNOWN,
|
||||
HELD_BY_PLAYER,
|
||||
PLAYER_INVENTORY
|
||||
}
|
||||
|
||||
public static final ItemLocation UNKNOWN = new ItemLocation(TYPE.UNKNOWN, -1);
|
||||
public static final ItemLocation HELD_BY_PLAYER = new ItemLocation(TYPE.HELD_BY_PLAYER, -1);
|
||||
public static final ItemLocation UNKNOWN = new ItemLocation(Type.UNKNOWN, -1);
|
||||
public static final ItemLocation HELD_BY_PLAYER = new ItemLocation(Type.HELD_BY_PLAYER, -1);
|
||||
|
||||
private final TYPE type;
|
||||
private final Type type;
|
||||
private final int slotIdx;
|
||||
|
||||
public ItemLocation(TYPE type, int slotIdx) {
|
||||
public ItemLocation(Type type, int slotIdx) {
|
||||
this.type = type;
|
||||
this.slotIdx = slotIdx;
|
||||
}
|
||||
|
||||
public TYPE type() {
|
||||
public Type type() {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.xonich.mc.nohotbarneeded.api.ActivatableFromInventoryServerSide;
|
||||
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
@@ -47,6 +48,9 @@ import forestry.storage.gui.GuiBackpack;
|
||||
import forestry.storage.gui.GuiBackpackT2;
|
||||
import forestry.storage.inventory.ItemInventoryBackpack;
|
||||
|
||||
@Optional.Interface(
|
||||
iface = "net.xonich.mc.nohotbarneeded.api.ActivatableFromInventoryServerSide",
|
||||
modid = "nohotbarneeded")
|
||||
public class ItemBackpack extends ItemWithGui implements ActivatableFromInventoryServerSide {
|
||||
|
||||
private final IBackpackDefinition definition;
|
||||
@@ -322,7 +326,7 @@ public class ItemBackpack extends ItemWithGui implements ActivatableFromInventor
|
||||
|
||||
@Override
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc) {
|
||||
if (data > EnumBackpackType.values().length) {
|
||||
if (data >= EnumBackpackType.values().length) {
|
||||
return null;
|
||||
}
|
||||
EnumBackpackType type = EnumBackpackType.values()[data];
|
||||
@@ -338,7 +342,7 @@ public class ItemBackpack extends ItemWithGui implements ActivatableFromInventor
|
||||
|
||||
@Override
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc) {
|
||||
if (data > EnumBackpackType.values().length) {
|
||||
if (data >= EnumBackpackType.values().length) {
|
||||
return null;
|
||||
}
|
||||
EnumBackpackType type = EnumBackpackType.values()[data];
|
||||
@@ -366,6 +370,7 @@ public class ItemBackpack extends ItemWithGui implements ActivatableFromInventor
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "nohotbarneeded")
|
||||
public void activateFromInventory(EntityPlayerMP player, int slotIdx) {
|
||||
GuiHandler.openGui(player, this, (short) type.ordinal(), slotIdx);
|
||||
}
|
||||
|
||||
@@ -9,8 +9,10 @@
|
||||
package forestry.storage.items;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.api.storage.EnumBackpackType;
|
||||
import forestry.api.storage.IBackpackDefinition;
|
||||
@@ -57,4 +59,10 @@ public class ItemBackpackNaturalist extends ItemBackpack {
|
||||
loc);
|
||||
return new ContainerNaturalistBackpack(player, inventory, page);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "nohotbarneeded")
|
||||
public void activateFromInventory(EntityPlayerMP player, int slotIdx) {
|
||||
GuiHandler.openGui(player, this, /* page */(short) 0, slotIdx);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user