mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-15 01:24:59 +00:00
Compare commits
19
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
114ccf1ffb | ||
|
|
0e5c9f320e | ||
|
|
43f10b5e84 | ||
|
|
673cf548cc | ||
|
|
acd079b9ac | ||
|
|
3a8c2bd8cf | ||
|
|
00a55f6888 | ||
|
|
f2895a469d | ||
|
|
181c71d245 | ||
|
|
58c6b7bdf3 | ||
|
|
7bba5bea50 | ||
|
|
c8bfb67045 | ||
|
|
798cdef6af | ||
|
|
f5ed7a61b2 | ||
|
|
f0aece4dc8 | ||
|
|
c6f4044193 | ||
|
|
d8f43c0544 | ||
|
|
eb0cda2d71 | ||
|
|
604209fd91 |
No files matched your search
+2
-1
@@ -6,7 +6,8 @@ dependencies {
|
||||
compileOnlyApi('com.github.GTNewHorizons:Angelica:2.1.19:api')
|
||||
devOnlyNonPublishable('com.github.GTNewHorizons:NotEnoughItems:2.8.93-GTNH:dev')
|
||||
compileOnly('com.github.GTNewHorizons:inventory-tweaks:1.7.1:api')
|
||||
compileOnly('com.github.GTNewHorizons:BuildCraft:7.1.57:api')
|
||||
compileOnly('com.github.GTNewHorizons:BuildCraft:7.1.59:api')
|
||||
compileOnly('net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev')
|
||||
compileOnly('curse.maven:craftguide-75557:2459320')
|
||||
devOnlyNonPublishable('net.xonich.mc:NoHotbarNeeded:0.0.3:dev')
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
#This file is generated by updateDaemonJvm
|
||||
toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/1630f7ebef05444cb27a2709ea0249b3/redirect
|
||||
toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/cf726b4a1c84b50457225f9bba6d7650/redirect
|
||||
toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect
|
||||
toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/1630f7ebef05444cb27a2709ea0249b3/redirect
|
||||
toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/cf726b4a1c84b50457225f9bba6d7650/redirect
|
||||
toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect
|
||||
toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/c2dd35c9d0aaf0ba6ad0791320f99dfc/redirect
|
||||
toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/e5810bd7fd1f8a586644409d395a7e55/redirect
|
||||
toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/1630f7ebef05444cb27a2709ea0249b3/redirect
|
||||
toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/cf726b4a1c84b50457225f9bba6d7650/redirect
|
||||
toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect
|
||||
toolchainUrl.WINDOWS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/7b3c4877c0749019e6805bb61e421497/redirect
|
||||
toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/8e1d9ee5d0f13e442218f6884a306da1/redirect
|
||||
toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/d76df094a9cbbabd3b08251f9e61444a/redirect
|
||||
toolchainVersion=25
|
||||
@@ -15,6 +15,7 @@ import forestry.api.core.Tabs;
|
||||
import forestry.apiculture.gui.GuiBeealyzer;
|
||||
import forestry.apiculture.inventory.ItemInventoryBeealyzer;
|
||||
import forestry.core.gui.ContainerAlyzer;
|
||||
import forestry.core.inventory.ItemLocation;
|
||||
import forestry.core.items.ItemWithGui;
|
||||
|
||||
public class ItemBeealyzer extends ItemWithGui {
|
||||
@@ -24,13 +25,13 @@ public class ItemBeealyzer extends ItemWithGui {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc) {
|
||||
ItemInventoryBeealyzer inventory = new ItemInventoryBeealyzer(player, heldItem);
|
||||
return new GuiBeealyzer(player, inventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc) {
|
||||
ItemInventoryBeealyzer inventory = new ItemInventoryBeealyzer(player, heldItem);
|
||||
return new ContainerAlyzer(inventory, player);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import forestry.apiculture.gui.ContainerHabitatLocator;
|
||||
import forestry.apiculture.gui.GuiHabitatLocator;
|
||||
import forestry.apiculture.inventory.ItemInventoryHabitatLocator;
|
||||
import forestry.apiculture.render.TextureHabitatLocator;
|
||||
import forestry.core.inventory.ItemLocation;
|
||||
import forestry.core.items.ItemWithGui;
|
||||
import forestry.core.utils.StringUtil;
|
||||
|
||||
@@ -81,12 +82,12 @@ public class ItemHabitatLocator extends ItemWithGui {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc) {
|
||||
return new GuiHabitatLocator(player, new ItemInventoryHabitatLocator(player, heldItem));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc) {
|
||||
return new ContainerHabitatLocator(player, new ItemInventoryHabitatLocator(player, heldItem));
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import forestry.api.core.Tabs;
|
||||
import forestry.apiculture.gui.ContainerImprinter;
|
||||
import forestry.apiculture.gui.GuiImprinter;
|
||||
import forestry.apiculture.inventory.ItemInventoryImprinter;
|
||||
import forestry.core.inventory.ItemLocation;
|
||||
import forestry.core.items.ItemWithGui;
|
||||
|
||||
public class ItemImprinter extends ItemWithGui {
|
||||
@@ -24,12 +25,12 @@ public class ItemImprinter extends ItemWithGui {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc) {
|
||||
return new GuiImprinter(player.inventory, new ItemInventoryImprinter(player, heldItem));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc) {
|
||||
return new ContainerImprinter(player.inventory, new ItemInventoryImprinter(player, heldItem));
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import forestry.api.core.Tabs;
|
||||
import forestry.arboriculture.gui.GuiTreealyzer;
|
||||
import forestry.arboriculture.inventory.ItemInventoryTreealyzer;
|
||||
import forestry.core.gui.ContainerAlyzer;
|
||||
import forestry.core.inventory.ItemLocation;
|
||||
import forestry.core.items.ItemWithGui;
|
||||
|
||||
public class ItemTreealyzer extends ItemWithGui {
|
||||
@@ -24,12 +25,12 @@ public class ItemTreealyzer extends ItemWithGui {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc) {
|
||||
return new GuiTreealyzer(player, new ItemInventoryTreealyzer(player, heldItem));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc) {
|
||||
return new ContainerAlyzer(new ItemInventoryTreealyzer(player, heldItem), player);
|
||||
}
|
||||
}
|
||||
@@ -36,8 +36,7 @@ public abstract class ContainerForestry extends Container {
|
||||
// Player inventory
|
||||
for (int row = 0; row < 3; row++) {
|
||||
for (int column = 0; column < 9; column++) {
|
||||
addSlotToContainer(
|
||||
new Slot(playerInventory, column + row * 9 + 9, xInv + column * 18, yInv + row * 18));
|
||||
addNormalSlot(playerInventory, column + row * 9 + 9, xInv + column * 18, yInv + row * 18);
|
||||
}
|
||||
}
|
||||
// Player hotbar
|
||||
@@ -46,6 +45,10 @@ public abstract class ContainerForestry extends Container {
|
||||
}
|
||||
}
|
||||
|
||||
protected void addNormalSlot(InventoryPlayer playerInventory, int slot, int x, int y) {
|
||||
addSlotToContainer(new Slot(playerInventory, slot, x, y));
|
||||
}
|
||||
|
||||
protected void addHotbarSlot(InventoryPlayer playerInventory, int slot, int x, int y) {
|
||||
addSlotToContainer(new Slot(playerInventory, slot, x, y));
|
||||
}
|
||||
|
||||
@@ -26,6 +26,17 @@ public abstract class ContainerItemInventory<I extends ItemInventory> extends Co
|
||||
addPlayerInventory(playerInventory, xInv, yInv);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addNormalSlot(InventoryPlayer playerInventory, int slot, int x, int y) {
|
||||
ItemStack stackInSlot = playerInventory.getStackInSlot(slot);
|
||||
|
||||
if (inventory.isParentItemInventory(stackInSlot)) {
|
||||
addSlotToContainer(new SlotLocked(playerInventory, slot, x, y));
|
||||
} else {
|
||||
addSlotToContainer(new Slot(playerInventory, slot, x, y));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addHotbarSlot(InventoryPlayer playerInventory, int slot, int x, int y) {
|
||||
ItemStack stackInSlot = playerInventory.getStackInSlot(slot);
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.gui;
|
||||
|
||||
import static forestry.core.inventory.ItemLocation.Type.PLAYER_INVENTORY;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -18,6 +22,7 @@ import net.minecraft.world.World;
|
||||
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.core.inventory.ItemLocation;
|
||||
|
||||
public class GuiHandler implements IGuiHandler {
|
||||
|
||||
@@ -39,6 +44,20 @@ public class GuiHandler implements IGuiHandler {
|
||||
entityplayer.openGui(ForestryAPI.instance, guiData, entityplayer.worldObj, 0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens gui for item placed in player's inventory.
|
||||
*
|
||||
* @param entityPlayer Player.
|
||||
* @param guiHandler GUI handler for item.
|
||||
* @param data Data for item.
|
||||
* @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);
|
||||
}
|
||||
|
||||
public static void openGui(EntityPlayer entityplayer, IGuiHandlerTile guiHandler) {
|
||||
openGui(entityplayer, guiHandler, (short) 0);
|
||||
}
|
||||
@@ -56,8 +75,32 @@ public class GuiHandler implements IGuiHandler {
|
||||
}
|
||||
|
||||
private static int encodeGuiData(IGuiHandlerForestry guiHandler, short data) {
|
||||
return encodeGuiData(guiHandler, data, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes data required for GUI handler to function properly. Because of minecraft implementation we are limited to
|
||||
* 32 bits.
|
||||
*
|
||||
* @param guiHandler GUI handler.
|
||||
* @param data High bits which were encoded by GUI handler.
|
||||
* @param invSlotIdx Slot index in the player's inventory should be in range [0,40).
|
||||
* @return Encoded data.
|
||||
*/
|
||||
private static int encodeGuiData(IGuiHandlerForestry guiHandler, short data, int invSlotIdx) {
|
||||
// inventory slot idx will be encoded in third byte
|
||||
// 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) {
|
||||
throw new IllegalArgumentException("Inventory slot index should be in range [-1, 40)");
|
||||
}
|
||||
|
||||
int invData = invSlotIdx == -1 ? 0 : (0x40 | invSlotIdx);
|
||||
|
||||
GuiId guiId = GuiIdRegistry.getGuiIdForGuiHandler(guiHandler);
|
||||
return data << 16 | guiId.getId();
|
||||
|
||||
return data << 16 | invData << 8 | guiId.getId();
|
||||
}
|
||||
|
||||
private static GuiId decodeGuiID(int guiData) {
|
||||
@@ -69,8 +112,24 @@ public class GuiHandler implements IGuiHandler {
|
||||
return (short) (guiId >> 16);
|
||||
}
|
||||
|
||||
private static int decodeInvSlotIdx(int guiData) {
|
||||
boolean invEncoded = (0x00_00_40_00 & guiData) != 0;
|
||||
|
||||
return invEncoded ? (guiData & 0x00_00_3F_00) >> 8 : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getClientGuiElement(int guiData, EntityPlayer player, World world, int x, int y, int z) {
|
||||
return getGuiElement(false, guiData, player, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getServerGuiElement(int guiData, EntityPlayer player, World world, int x, int y, int z) {
|
||||
return getGuiElement(true, guiData, player, world, x, y, z);
|
||||
}
|
||||
|
||||
private @Nullable Object getGuiElement(boolean isServerSide, int guiData, EntityPlayer player, World world, int x,
|
||||
int y, int z) {
|
||||
GuiId guiId = decodeGuiID(guiData);
|
||||
if (guiId == null) {
|
||||
return null;
|
||||
@@ -79,11 +138,25 @@ public class GuiHandler implements IGuiHandler {
|
||||
|
||||
switch (guiId.getGuiType()) {
|
||||
case Item: {
|
||||
ItemStack heldItem = player.getCurrentEquippedItem();
|
||||
int slotIdx = decodeInvSlotIdx(guiData);
|
||||
ItemStack heldItem;
|
||||
ItemLocation loc;
|
||||
if (slotIdx == -1) {
|
||||
heldItem = player.getCurrentEquippedItem();
|
||||
loc = ItemLocation.HELD_BY_PLAYER;
|
||||
} else {
|
||||
heldItem = player.inventory.getStackInSlot(slotIdx);
|
||||
loc = new ItemLocation(PLAYER_INVENTORY, slotIdx);
|
||||
}
|
||||
|
||||
if (heldItem != null) {
|
||||
Item item = heldItem.getItem();
|
||||
if (guiId.getGuiHandlerClass().isInstance(item)) {
|
||||
return ((IGuiHandlerItem) item).getGui(player, heldItem, data);
|
||||
if (isServerSide) {
|
||||
return ((IGuiHandlerItem) item).getContainer(player, heldItem, data, loc);
|
||||
}
|
||||
|
||||
return ((IGuiHandlerItem) item).getGui(player, heldItem, data, loc);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -91,6 +164,9 @@ public class GuiHandler implements IGuiHandler {
|
||||
case Tile: {
|
||||
TileEntity tileEntity = world.getTileEntity(x, y, z);
|
||||
if (guiId.getGuiHandlerClass().isInstance(tileEntity)) {
|
||||
if (isServerSide) {
|
||||
return ((IGuiHandlerTile) tileEntity).getContainer(player, data);
|
||||
}
|
||||
return ((IGuiHandlerTile) tileEntity).getGui(player, data);
|
||||
}
|
||||
break;
|
||||
@@ -98,6 +174,9 @@ public class GuiHandler implements IGuiHandler {
|
||||
case Entity: {
|
||||
Entity entity = world.getEntityByID(x);
|
||||
if (guiId.getGuiHandlerClass().isInstance(entity)) {
|
||||
if (isServerSide) {
|
||||
return ((IGuiHandlerEntity) entity).getContainer(player, data);
|
||||
}
|
||||
return ((IGuiHandlerEntity) entity).getGui(player, data);
|
||||
}
|
||||
break;
|
||||
@@ -105,41 +184,4 @@ public class GuiHandler implements IGuiHandler {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getServerGuiElement(int guiData, EntityPlayer player, World world, int x, int y, int z) {
|
||||
GuiId guiId = decodeGuiID(guiData);
|
||||
if (guiId == null) {
|
||||
return null;
|
||||
}
|
||||
short data = decodeGuiData(guiData);
|
||||
|
||||
switch (guiId.getGuiType()) {
|
||||
case Item: {
|
||||
ItemStack heldItem = player.getCurrentEquippedItem();
|
||||
if (heldItem != null) {
|
||||
Item item = heldItem.getItem();
|
||||
if (guiId.getGuiHandlerClass().isInstance(item)) {
|
||||
return ((IGuiHandlerItem) item).getContainer(player, heldItem, data);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Tile: {
|
||||
TileEntity tileEntity = world.getTileEntity(x, y, z);
|
||||
if (guiId.getGuiHandlerClass().isInstance(tileEntity)) {
|
||||
return ((IGuiHandlerTile) tileEntity).getContainer(player, data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Entity: {
|
||||
Entity entity = world.getEntityByID(x);
|
||||
if (guiId.getGuiHandlerClass().isInstance(entity)) {
|
||||
return ((IGuiHandlerEntity) entity).getContainer(player, data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -119,6 +119,13 @@ public class GuiIdRegistry {
|
||||
classMap.put(tileGuiHandlerClass, guiId);
|
||||
idMap.put(guiId.getId(), guiId);
|
||||
}
|
||||
|
||||
if (idMap.size() > 256) {
|
||||
// see {@link GuiHandler.encodeGuiData(forestry.core.gui.IGuiHandlerForestry, short, int)}
|
||||
throw new IllegalStateException(
|
||||
"Current implementation can't have more than different 256 GUI handlers "
|
||||
+ "because its id is coded by 8 bits");
|
||||
}
|
||||
}
|
||||
|
||||
public static GuiId getGuiIdForGuiHandler(IGuiHandlerForestry guiHandler) {
|
||||
|
||||
@@ -11,9 +11,11 @@ package forestry.core.gui;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.core.inventory.ItemLocation;
|
||||
|
||||
public interface IGuiHandlerItem extends IGuiHandlerForestry {
|
||||
|
||||
Object getGui(EntityPlayer player, ItemStack heldItem, int data);
|
||||
Object getGui(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc);
|
||||
|
||||
Object getContainer(EntityPlayer player, ItemStack heldItem, int data);
|
||||
Object getContainer(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc);
|
||||
}
|
||||
@@ -28,11 +28,17 @@ public abstract class ItemInventory implements IInventory, IFilterSlotDelegate {
|
||||
private final EntityPlayer player;
|
||||
private final ItemStack parent;
|
||||
private final ItemStack[] inventoryStacks;
|
||||
private final ItemLocation location;
|
||||
|
||||
public ItemInventory(EntityPlayer player, int size, ItemStack parent) {
|
||||
this(player, size, parent, ItemLocation.UNKNOWN);
|
||||
}
|
||||
|
||||
public ItemInventory(EntityPlayer player, int size, ItemStack parent, ItemLocation loc) {
|
||||
this.player = player;
|
||||
this.parent = parent;
|
||||
this.inventoryStacks = new ItemStack[size];
|
||||
this.location = loc;
|
||||
|
||||
setUID(); // Set a uid to identify the itemstack on SMP
|
||||
|
||||
@@ -79,7 +85,10 @@ public abstract class ItemInventory implements IInventory, IFilterSlotDelegate {
|
||||
}
|
||||
|
||||
public boolean isParentItemEquipped() {
|
||||
return isSameItemInventory(player.getCurrentEquippedItem(), parent);
|
||||
return switch (location.type()) {
|
||||
case HELD_BY_PLAYER, UNKNOWN -> isSameItemInventory(player.getCurrentEquippedItem(), parent);
|
||||
case PLAYER_INVENTORY -> true;
|
||||
};
|
||||
}
|
||||
|
||||
public EntityPlayer getPlayer() {
|
||||
@@ -92,7 +101,11 @@ public abstract class ItemInventory implements IInventory, IFilterSlotDelegate {
|
||||
}
|
||||
|
||||
protected ItemStack getParent() {
|
||||
ItemStack equipped = player.getCurrentEquippedItem();
|
||||
ItemStack equipped = switch (location.type()) {
|
||||
case HELD_BY_PLAYER, UNKNOWN -> player.getCurrentEquippedItem();
|
||||
case PLAYER_INVENTORY -> player.inventory.getStackInSlot(location.slotIdx());
|
||||
};
|
||||
|
||||
if (isSameItemInventory(equipped, parent)) {
|
||||
return equipped;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package forestry.core.inventory;
|
||||
|
||||
/**
|
||||
* Location of items in inventory.
|
||||
*/
|
||||
public class ItemLocation {
|
||||
|
||||
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);
|
||||
|
||||
private final Type type;
|
||||
private final int slotIdx;
|
||||
|
||||
public ItemLocation(Type type, int slotIdx) {
|
||||
this.type = type;
|
||||
this.slotIdx = slotIdx;
|
||||
}
|
||||
|
||||
public Type type() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int slotIdx() {
|
||||
return slotIdx;
|
||||
}
|
||||
}
|
||||
@@ -15,16 +15,17 @@ import forestry.core.circuits.ContainerSolderingIron;
|
||||
import forestry.core.circuits.GuiSolderingIron;
|
||||
import forestry.core.circuits.ISolderingIron;
|
||||
import forestry.core.inventory.ItemInventorySolderingIron;
|
||||
import forestry.core.inventory.ItemLocation;
|
||||
|
||||
public class ItemSolderingIron extends ItemWithGui implements ISolderingIron {
|
||||
|
||||
@Override
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc) {
|
||||
return new GuiSolderingIron(player, new ItemInventorySolderingIron(player, heldItem));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc) {
|
||||
return new ContainerSolderingIron(player, new ItemInventorySolderingIron(player, heldItem));
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ package forestry.food.items;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.core.inventory.ItemLocation;
|
||||
import forestry.core.items.ItemWithGui;
|
||||
import forestry.food.gui.ContainerInfuser;
|
||||
import forestry.food.gui.GuiInfuser;
|
||||
@@ -19,12 +20,12 @@ import forestry.food.inventory.ItemInventoryInfuser;
|
||||
public class ItemInfuser extends ItemWithGui {
|
||||
|
||||
@Override
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc) {
|
||||
return new GuiInfuser(player.inventory, new ItemInventoryInfuser(player, heldItem));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc) {
|
||||
return new ContainerInfuser(player.inventory, new ItemInventoryInfuser(player, heldItem));
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.core.Tabs;
|
||||
import forestry.core.gui.ContainerAlyzer;
|
||||
import forestry.core.inventory.ItemLocation;
|
||||
import forestry.core.items.ItemWithGui;
|
||||
import forestry.lepidopterology.gui.GuiFlutterlyzer;
|
||||
import forestry.lepidopterology.inventory.ItemInventoryFlutterlyzer;
|
||||
@@ -24,12 +25,12 @@ public class ItemFlutterlyzer extends ItemWithGui {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc) {
|
||||
return new GuiFlutterlyzer(player, new ItemInventoryFlutterlyzer(player, heldItem));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc) {
|
||||
return new ContainerAlyzer(new ItemInventoryFlutterlyzer(player, heldItem), player);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ package forestry.mail.items;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.core.inventory.ItemLocation;
|
||||
import forestry.core.items.ItemWithGui;
|
||||
import forestry.mail.gui.ContainerCatalogue;
|
||||
import forestry.mail.gui.GuiCatalogue;
|
||||
@@ -18,12 +19,12 @@ import forestry.mail.gui.GuiCatalogue;
|
||||
public class ItemCatalogue extends ItemWithGui {
|
||||
|
||||
@Override
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc) {
|
||||
return new GuiCatalogue(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc) {
|
||||
return new ContainerCatalogue(player);
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import net.minecraft.world.World;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import forestry.api.mail.ILetter;
|
||||
import forestry.core.inventory.ItemLocation;
|
||||
import forestry.core.items.ItemWithGui;
|
||||
import forestry.core.utils.StringUtil;
|
||||
import forestry.mail.Letter;
|
||||
@@ -87,12 +88,12 @@ public class ItemLetter extends ItemWithGui {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc) {
|
||||
return new GuiLetter(player, new ItemInventoryLetter(player, heldItem));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc) {
|
||||
return new ContainerLetter(player, new ItemInventoryLetter(player, heldItem));
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.core.gui.ContainerItemInventory;
|
||||
import forestry.core.gui.slots.SlotFilteredInventory;
|
||||
import forestry.core.inventory.ItemLocation;
|
||||
import forestry.storage.inventory.ItemInventoryBackpack;
|
||||
|
||||
public class ContainerBackpack extends ContainerItemInventory<ItemInventoryBackpack> {
|
||||
@@ -39,9 +40,9 @@ public class ContainerBackpack extends ContainerItemInventory<ItemInventoryBackp
|
||||
}
|
||||
}
|
||||
|
||||
public ContainerBackpack(EntityPlayer player, Size size, ItemStack parent) {
|
||||
public ContainerBackpack(EntityPlayer player, Size size, ItemStack parent, ItemLocation loc) {
|
||||
super(
|
||||
new ItemInventoryBackpack(player, size.getSize(), parent),
|
||||
new ItemInventoryBackpack(player, size.getSize(), parent, loc),
|
||||
player.inventory,
|
||||
8,
|
||||
11 + size.startY + size.rows * 18);
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.storage.IBackpackDefinition;
|
||||
import forestry.core.inventory.ItemInventory;
|
||||
import forestry.core.inventory.ItemLocation;
|
||||
import forestry.storage.items.ItemBackpack;
|
||||
|
||||
public class ItemInventoryBackpack extends ItemInventory {
|
||||
@@ -13,7 +14,11 @@ public class ItemInventoryBackpack extends ItemInventory {
|
||||
private final IBackpackDefinition backpackDefinition;
|
||||
|
||||
public ItemInventoryBackpack(EntityPlayer player, int size, ItemStack parent) {
|
||||
super(player, size, parent);
|
||||
this(player, size, parent, ItemLocation.UNKNOWN);
|
||||
}
|
||||
|
||||
public ItemInventoryBackpack(EntityPlayer player, int size, ItemStack parent, ItemLocation location) {
|
||||
super(player, size, parent, location);
|
||||
|
||||
if (parent == null) {
|
||||
throw new IllegalArgumentException("Parent cannot be null.");
|
||||
|
||||
@@ -13,6 +13,7 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.core.gui.GuiHandler;
|
||||
import forestry.core.gui.IPagedInventory;
|
||||
import forestry.core.inventory.ItemLocation;
|
||||
import forestry.storage.items.ItemBackpackNaturalist;
|
||||
|
||||
public class ItemInventoryBackpackPaged extends ItemInventoryBackpack implements IPagedInventory {
|
||||
@@ -20,8 +21,8 @@ public class ItemInventoryBackpackPaged extends ItemInventoryBackpack implements
|
||||
private final ItemBackpackNaturalist backpackNaturalist;
|
||||
|
||||
public ItemInventoryBackpackPaged(EntityPlayer player, int size, ItemStack itemstack,
|
||||
ItemBackpackNaturalist backpackNaturalist) {
|
||||
super(player, size, itemstack);
|
||||
ItemBackpackNaturalist backpackNaturalist, ItemLocation loc) {
|
||||
super(player, size, itemstack, loc);
|
||||
this.backpackNaturalist = backpackNaturalist;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import java.util.Locale;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -20,7 +21,9 @@ import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
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;
|
||||
@@ -31,6 +34,7 @@ import forestry.core.config.Config;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.gui.GuiHandler;
|
||||
import forestry.core.inventory.ItemInventory;
|
||||
import forestry.core.inventory.ItemLocation;
|
||||
import forestry.core.inventory.wrappers.IInvSlot;
|
||||
import forestry.core.inventory.wrappers.InventoryIterator;
|
||||
import forestry.core.items.ItemWithGui;
|
||||
@@ -44,7 +48,10 @@ import forestry.storage.gui.GuiBackpack;
|
||||
import forestry.storage.gui.GuiBackpackT2;
|
||||
import forestry.storage.inventory.ItemInventoryBackpack;
|
||||
|
||||
public class ItemBackpack extends ItemWithGui {
|
||||
@Optional.Interface(
|
||||
iface = "net.xonich.mc.nohotbarneeded.api.ActivatableFromInventoryServerSide",
|
||||
modid = "nohotbarneeded")
|
||||
public class ItemBackpack extends ItemWithGui implements ActivatableFromInventoryServerSide {
|
||||
|
||||
private final IBackpackDefinition definition;
|
||||
private final EnumBackpackType type;
|
||||
@@ -318,32 +325,32 @@ public class ItemBackpack extends ItemWithGui {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
if (data > EnumBackpackType.values().length) {
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc) {
|
||||
if (data >= EnumBackpackType.values().length) {
|
||||
return null;
|
||||
}
|
||||
EnumBackpackType type = EnumBackpackType.values()[data];
|
||||
switch (type) {
|
||||
case T1:
|
||||
return new GuiBackpack(new ContainerBackpack(player, ContainerBackpack.Size.DEFAULT, heldItem));
|
||||
return new GuiBackpack(new ContainerBackpack(player, ContainerBackpack.Size.DEFAULT, heldItem, loc));
|
||||
case T2:
|
||||
return new GuiBackpackT2(new ContainerBackpack(player, ContainerBackpack.Size.T2, heldItem));
|
||||
return new GuiBackpackT2(new ContainerBackpack(player, ContainerBackpack.Size.T2, heldItem, loc));
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
if (data > EnumBackpackType.values().length) {
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data, ItemLocation loc) {
|
||||
if (data >= EnumBackpackType.values().length) {
|
||||
return null;
|
||||
}
|
||||
EnumBackpackType type = EnumBackpackType.values()[data];
|
||||
switch (type) {
|
||||
case T1:
|
||||
return new ContainerBackpack(player, ContainerBackpack.Size.DEFAULT, heldItem);
|
||||
return new ContainerBackpack(player, ContainerBackpack.Size.DEFAULT, heldItem, loc);
|
||||
case T2:
|
||||
return new ContainerBackpack(player, ContainerBackpack.Size.T2, heldItem);
|
||||
return new ContainerBackpack(player, ContainerBackpack.Size.T2, heldItem, loc);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@@ -361,4 +368,10 @@ public class ItemBackpack extends ItemWithGui {
|
||||
public boolean showDurabilityBar(final ItemStack stack) {
|
||||
return Config.showBackpackDurability && ItemInventory.getOccupiedSlotCount(stack) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "nohotbarneeded")
|
||||
public void activateFromInventory(EntityPlayerMP player, int slotIdx) {
|
||||
GuiHandler.openGui(player, this, (short) type.ordinal(), slotIdx);
|
||||
}
|
||||
}
|
||||
@@ -9,14 +9,17 @@
|
||||
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;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.gui.GuiHandler;
|
||||
import forestry.core.gui.GuiNaturalistInventory;
|
||||
import forestry.core.inventory.ItemLocation;
|
||||
import forestry.storage.gui.ContainerNaturalistBackpack;
|
||||
import forestry.storage.inventory.ItemInventoryBackpackPaged;
|
||||
|
||||
@@ -35,23 +38,31 @@ public class ItemBackpackNaturalist extends ItemBackpack {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int page) {
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int page, ItemLocation loc) {
|
||||
ItemInventoryBackpackPaged inventory = new ItemInventoryBackpackPaged(
|
||||
player,
|
||||
Constants.SLOTS_BACKPACK_APIARIST,
|
||||
heldItem,
|
||||
this);
|
||||
this,
|
||||
loc);
|
||||
ContainerNaturalistBackpack container = new ContainerNaturalistBackpack(player, inventory, page);
|
||||
return new GuiNaturalistInventory(speciesRoot, player, container, inventory, page, 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int page) {
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int page, ItemLocation loc) {
|
||||
ItemInventoryBackpackPaged inventory = new ItemInventoryBackpackPaged(
|
||||
player,
|
||||
Constants.SLOTS_BACKPACK_APIARIST,
|
||||
heldItem,
|
||||
this);
|
||||
this,
|
||||
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