diff --git a/src/main/java/forestry/apiculture/GuiHandlerApiculture.java b/src/main/java/forestry/apiculture/GuiHandlerApiculture.java index 8931c23f9..5d45757de 100755 --- a/src/main/java/forestry/apiculture/GuiHandlerApiculture.java +++ b/src/main/java/forestry/apiculture/GuiHandlerApiculture.java @@ -90,7 +90,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase { return null; } - return new GuiHabitatLocator(player.inventory, new HabitatLocatorInventory(equipped)); + return new GuiHabitatLocator(player, new HabitatLocatorInventory(player, equipped)); case HygroregulatorGUI: return new GuiAlvearyHygroregulator(player.inventory, (TileAlvearyHygroregulator) getTileForestry(world, x, y, z)); @@ -156,7 +156,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase { return null; } - return new ContainerHabitatLocator(player.inventory, new HabitatLocatorInventory(equipped)); + return new ContainerHabitatLocator(player, new HabitatLocatorInventory(player, equipped)); case HygroregulatorGUI: return new ContainerAlvearyHygroregulator(player.inventory, (TileAlvearyHygroregulator) getTileForestry(world, x, y, z)); @@ -175,7 +175,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase { } } - private void synchApiaristTracker(World world, EntityPlayer player) { + private static void synchApiaristTracker(World world, EntityPlayer player) { BeeManager.beeRoot.getBreedingTracker(world, player.getGameProfile()).synchToPlayer(player); } } diff --git a/src/main/java/forestry/apiculture/gui/ContainerAlveary.java b/src/main/java/forestry/apiculture/gui/ContainerAlveary.java index 6e7c713bf..bbf4e6a2e 100755 --- a/src/main/java/forestry/apiculture/gui/ContainerAlveary.java +++ b/src/main/java/forestry/apiculture/gui/ContainerAlveary.java @@ -12,21 +12,17 @@ package forestry.apiculture.gui; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.Slot; import forestry.apiculture.gadgets.TileAlvearyPlain; -import forestry.core.gui.ContainerForestry; +import forestry.core.gui.ContainerTile; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; -public class ContainerAlveary extends ContainerForestry { - - private final TileAlvearyPlain tile; +public class ContainerAlveary extends ContainerTile { public ContainerAlveary(InventoryPlayer player, TileAlvearyPlain tile) { - super(tile); + super(tile, player, 8, 108); - this.tile = tile; tile.sendNetworkUpdate(); // Queen/Princess @@ -43,17 +39,6 @@ public class ContainerAlveary extends ContainerForestry { this.addSlotToContainer(new SlotOutput(tile, 6, 95, 65)); this.addSlotToContainer(new SlotOutput(tile, 7, 95, 39)); this.addSlotToContainer(new SlotOutput(tile, 8, 116, 26)); - - // Player inventory - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 9; j++) { - addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, 108 + i * 18)); - } - } - // Player hotbar - for (int i = 0; i < 9; i++) { - addSlotToContainer(new Slot(player, i, 8 + i * 18, 166)); - } } @Override @@ -68,5 +53,4 @@ public class ContainerAlveary extends ContainerForestry { tile.sendGUINetworkData(this, (ICrafting) crafter); } } - } diff --git a/src/main/java/forestry/apiculture/gui/ContainerAlvearyHygroregulator.java b/src/main/java/forestry/apiculture/gui/ContainerAlvearyHygroregulator.java index 90117754c..e7a0e9072 100755 --- a/src/main/java/forestry/apiculture/gui/ContainerAlvearyHygroregulator.java +++ b/src/main/java/forestry/apiculture/gui/ContainerAlvearyHygroregulator.java @@ -10,30 +10,18 @@ ******************************************************************************/ package forestry.apiculture.gui; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; +import net.minecraft.entity.player.InventoryPlayer; import forestry.apiculture.gadgets.TileAlvearyHygroregulator; import forestry.core.gui.ContainerLiquidTanks; import forestry.core.gui.slots.SlotFiltered; -public class ContainerAlvearyHygroregulator extends ContainerLiquidTanks { +public class ContainerAlvearyHygroregulator extends ContainerLiquidTanks { - public ContainerAlvearyHygroregulator(IInventory playerInventory, TileAlvearyHygroregulator tile) { - super(tile); + public ContainerAlvearyHygroregulator(InventoryPlayer playerInventory, TileAlvearyHygroregulator tile) { + super(tile, playerInventory, 8, 84); this.addSlotToContainer(new SlotFiltered(tile, TileAlvearyHygroregulator.SLOT_INPUT, 56, 38)); - - for (int i = 0; i < 3; ++i) { - for (int var4 = 0; var4 < 9; ++var4) { - this.addSlotToContainer(new Slot(playerInventory, var4 + i * 9 + 9, 8 + var4 * 18, 84 + i * 18)); - } - } - - for (int i = 0; i < 9; ++i) { - this.addSlotToContainer(new Slot(playerInventory, i, 8 + i * 18, 142)); - } - } } diff --git a/src/main/java/forestry/apiculture/gui/ContainerAlvearySieve.java b/src/main/java/forestry/apiculture/gui/ContainerAlvearySieve.java index 532bf2222..67d549a85 100755 --- a/src/main/java/forestry/apiculture/gui/ContainerAlvearySieve.java +++ b/src/main/java/forestry/apiculture/gui/ContainerAlvearySieve.java @@ -11,17 +11,16 @@ package forestry.apiculture.gui; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; import forestry.apiculture.gadgets.TileAlvearySieve; -import forestry.core.gui.ContainerForestry; +import forestry.core.gui.ContainerTile; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; -public class ContainerAlvearySieve extends ContainerForestry { +public class ContainerAlvearySieve extends ContainerTile { public ContainerAlvearySieve(InventoryPlayer player, TileAlvearySieve tile) { - super(tile); + super(tile, player, 8, 87); addSlotToContainer(new SlotOutput(tile, 0, 94, 52).setCrafter(tile)); addSlotToContainer(new SlotOutput(tile, 1, 115, 39).setCrafter(tile)); @@ -29,18 +28,5 @@ public class ContainerAlvearySieve extends ContainerForestry { addSlotToContainer(new SlotOutput(tile, 3, 94, 26).setCrafter(tile)); addSlotToContainer(new SlotFiltered(tile, TileAlvearySieve.SLOT_SIEVE, 43, 39).setCrafter(tile)); - - // Player inventory - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 9; j++) { - addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, 87 + i * 18)); - } - } - // Player hotbar - for (int i = 0; i < 9; i++) { - addSlotToContainer(new Slot(player, i, 8 + i * 18, 145)); - } - } - } diff --git a/src/main/java/forestry/apiculture/gui/ContainerAlvearySwarmer.java b/src/main/java/forestry/apiculture/gui/ContainerAlvearySwarmer.java index 1712cf23a..1ea937839 100755 --- a/src/main/java/forestry/apiculture/gui/ContainerAlvearySwarmer.java +++ b/src/main/java/forestry/apiculture/gui/ContainerAlvearySwarmer.java @@ -11,32 +11,19 @@ package forestry.apiculture.gui; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; import forestry.apiculture.gadgets.TileAlvearySwarmer; -import forestry.core.gui.ContainerForestry; +import forestry.core.gui.ContainerTile; import forestry.core.gui.slots.SlotFiltered; -public class ContainerAlvearySwarmer extends ContainerForestry { +public class ContainerAlvearySwarmer extends ContainerTile { public ContainerAlvearySwarmer(InventoryPlayer player, TileAlvearySwarmer tile) { - super(tile); + super(tile, player, 8, 87); this.addSlotToContainer(new SlotFiltered(tile, 0, 79, 52)); this.addSlotToContainer(new SlotFiltered(tile, 1, 100, 39)); this.addSlotToContainer(new SlotFiltered(tile, 2, 58, 39)); this.addSlotToContainer(new SlotFiltered(tile, 3, 79, 26)); - - // Player inventory - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 9; j++) { - addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, 87 + i * 18)); - } - } - // Player hotbar - for (int i = 0; i < 9; i++) { - addSlotToContainer(new Slot(player, i, 8 + i * 18, 145)); - } - } } diff --git a/src/main/java/forestry/apiculture/gui/ContainerApiary.java b/src/main/java/forestry/apiculture/gui/ContainerApiary.java index 2e4f4d959..8c0cdcb31 100755 --- a/src/main/java/forestry/apiculture/gui/ContainerApiary.java +++ b/src/main/java/forestry/apiculture/gui/ContainerApiary.java @@ -12,21 +12,17 @@ package forestry.apiculture.gui; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.Slot; import forestry.apiculture.gadgets.TileBeehouse; -import forestry.core.gui.ContainerForestry; +import forestry.core.gui.ContainerTile; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; -public class ContainerApiary extends ContainerForestry { - - private final TileBeehouse tile; +public class ContainerApiary extends ContainerTile { public ContainerApiary(InventoryPlayer player, TileBeehouse tile, boolean hasFrames) { - super(tile); + super(tile, player, 8, 108); - this.tile = tile; tile.sendNetworkUpdate(); // Queen/Princess @@ -50,17 +46,6 @@ public class ContainerApiary extends ContainerForestry { this.addSlotToContainer(new SlotOutput(tile, 6, 95, 65)); this.addSlotToContainer(new SlotOutput(tile, 7, 95, 39)); this.addSlotToContainer(new SlotOutput(tile, 8, 116, 26)); - - // Player inventory - for (int i1 = 0; i1 < 3; i1++) { - for (int l1 = 0; l1 < 9; l1++) { - addSlotToContainer(new Slot(player, l1 + i1 * 9 + 9, 8 + l1 * 18, 108 + i1 * 18)); - } - } - // Player hotbar - for (int j1 = 0; j1 < 9; j1++) { - addSlotToContainer(new Slot(player, j1, 8 + j1 * 18, 166)); - } } @Override diff --git a/src/main/java/forestry/apiculture/gui/ContainerHabitatLocator.java b/src/main/java/forestry/apiculture/gui/ContainerHabitatLocator.java index 504c2b14e..30279ae5b 100755 --- a/src/main/java/forestry/apiculture/gui/ContainerHabitatLocator.java +++ b/src/main/java/forestry/apiculture/gui/ContainerHabitatLocator.java @@ -10,7 +10,7 @@ ******************************************************************************/ package forestry.apiculture.gui; -import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.entity.player.EntityPlayer; import forestry.apiculture.items.ItemHabitatLocator.HabitatLocatorInventory; import forestry.core.gui.ContainerItemInventory; @@ -19,8 +19,8 @@ import forestry.core.gui.slots.SlotOutput; public class ContainerHabitatLocator extends ContainerItemInventory { - public ContainerHabitatLocator(InventoryPlayer inventoryplayer, HabitatLocatorInventory inventory) { - super(inventory); + public ContainerHabitatLocator(EntityPlayer player, HabitatLocatorInventory inventory) { + super(inventory, player.inventory, 8, 102); // Energy this.addSlotToContainer(new SlotFiltered(inventory, 2, 152, 8)); @@ -29,16 +29,5 @@ public class ContainerHabitatLocator extends ContainerItemInventory implements IGuiSelectable { - public final ImprinterInventory inventory; private boolean isNetSynced = false; public ContainerImprinter(InventoryPlayer inventoryplayer, ImprinterInventory inventory) { - super(inventory); + super(inventory, inventoryplayer, 8, 103); - this.inventory = inventory; // Input this.addSlotToContainer(new SlotFiltered(inventory, 0, 152, 12)); // Output this.addSlotToContainer(new SlotOutput(inventory, 1, 152, 72)); - - // Player inventory - for (int i1 = 0; i1 < 3; i1++) { - for (int l1 = 0; l1 < 9; l1++) { - addSlotToContainer(new Slot(inventoryplayer, l1 + i1 * 9 + 9, 8 + l1 * 18, 103 + i1 * 18)); - } - } - // Player hotbar - for (int j1 = 0; j1 < 9; j1++) { - addSlotToContainer(new Slot(inventoryplayer, j1, 8 + j1 * 18, 161)); - } } @Override @@ -69,7 +55,6 @@ public class ContainerImprinter extends ContainerForestry implements IGuiSelecta Proxies.common.dropItemPlayer(entityplayer, stack); inventory.setInventorySlotContents(i, null); } - } public void advanceSelection(int index, World world) { diff --git a/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java b/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java index 0f254d057..1bbb879e8 100755 --- a/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java +++ b/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java @@ -18,7 +18,6 @@ import java.util.Map; import java.util.Set; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.util.IIcon; import net.minecraft.util.StatCollector; import net.minecraft.world.biome.BiomeGenBase; @@ -103,8 +102,8 @@ public class GuiHabitatLocator extends GuiForestry biomesToSearch = new HashSet(); private final ItemHabitatLocator habitatLocator; - public HabitatLocatorInventory(ItemStack itemstack) { - super(ItemHabitatLocator.class, 3, itemstack); + public HabitatLocatorInventory(EntityPlayer player, ItemStack itemstack) { + super(player, 3, itemstack); this.habitatLocator = (ItemHabitatLocator) itemstack.getItem(); } @@ -130,7 +130,8 @@ public class ItemHabitatLocator extends ItemInventoried { ImmutableSet.Builder errorStates = ImmutableSet.builder(); - if (!BeeManager.beeRoot.isMember(inventoryStacks[SLOT_SPECIMEN])) { + ItemStack specimen = getStackInSlot(SLOT_SPECIMEN); + if (!BeeManager.beeRoot.isMember(specimen)) { errorStates.add(EnumErrorCode.NOTHINGANALYZE); } diff --git a/src/main/java/forestry/apiculture/items/ItemImprinter.java b/src/main/java/forestry/apiculture/items/ItemImprinter.java index a710e91e0..5e2a671c2 100755 --- a/src/main/java/forestry/apiculture/items/ItemImprinter.java +++ b/src/main/java/forestry/apiculture/items/ItemImprinter.java @@ -30,17 +30,14 @@ public class ItemImprinter extends ItemForestry { public static class ImprinterInventory extends ItemInventory { - private final short specimenSlot = 0; - private final short imprintedSlot = 1; + private static final short specimenSlot = 0; + private static final short imprintedSlot = 1; private int primaryIndex = 0; private int secondaryIndex = 0; - private final EntityPlayer player; - public ImprinterInventory(EntityPlayer player, ItemStack itemStack) { - super(ItemImprinter.class, 2, itemStack); - this.player = player; + super(player, 2, itemStack); } public void advancePrimary() { @@ -107,17 +104,18 @@ public class ItemImprinter extends ItemForestry { private void tryImprint() { - if (inventoryStacks[specimenSlot] == null) { + ItemStack specimen = getStackInSlot(specimenSlot); + if (specimen == null) { return; } // Only imprint bees - if (!BeeManager.beeRoot.isMember(inventoryStacks[specimenSlot])) { + if (!BeeManager.beeRoot.isMember(specimen)) { return; } // Needs space - if (inventoryStacks[imprintedSlot] != null) { + if (getStackInSlot(imprintedSlot) != null) { return; } @@ -128,10 +126,10 @@ public class ItemImprinter extends ItemForestry { NBTTagCompound nbttagcompound = new NBTTagCompound(); imprint.writeToNBT(nbttagcompound); - inventoryStacks[specimenSlot].setTagCompound(nbttagcompound); + specimen.setTagCompound(nbttagcompound); - inventoryStacks[imprintedSlot] = inventoryStacks[specimenSlot]; - inventoryStacks[specimenSlot] = null; + setInventorySlotContents(imprintedSlot, specimen); + setInventorySlotContents(specimenSlot, null); } @Override diff --git a/src/main/java/forestry/arboriculture/items/ItemTreealyzer.java b/src/main/java/forestry/arboriculture/items/ItemTreealyzer.java index cac0eada6..f6ca5c9a8 100755 --- a/src/main/java/forestry/arboriculture/items/ItemTreealyzer.java +++ b/src/main/java/forestry/arboriculture/items/ItemTreealyzer.java @@ -32,8 +32,7 @@ public class ItemTreealyzer extends ItemInventoried { public static class TreealyzerInventory extends AlyzerInventory implements IHintSource { public TreealyzerInventory(EntityPlayer player, ItemStack itemStack) { - super(ItemTreealyzer.class, 7, itemStack); - this.player = player; + super(player, 7, itemStack); } @Override @@ -42,13 +41,6 @@ public class ItemTreealyzer extends ItemInventoried { } private void tryAnalyze() { - - // Analyzed slot occupied, abort - if (inventoryStacks[SLOT_ANALYZE_1] != null || inventoryStacks[SLOT_ANALYZE_2] != null || inventoryStacks[SLOT_ANALYZE_3] != null - || inventoryStacks[SLOT_ANALYZE_4] != null || inventoryStacks[SLOT_ANALYZE_5] != null) { - return; - } - // Source slot to analyze empty if (getStackInSlot(SLOT_SPECIMEN) == null) { return; diff --git a/src/main/java/forestry/core/GuiHandler.java b/src/main/java/forestry/core/GuiHandler.java index 685955b1a..e07e78de2 100755 --- a/src/main/java/forestry/core/GuiHandler.java +++ b/src/main/java/forestry/core/GuiHandler.java @@ -48,7 +48,7 @@ public class GuiHandler extends GuiHandlerBase { if (equipped == null) { return null; } - return new GuiSolderingIron(player.inventory, new SolderingInventory(equipped)); + return new GuiSolderingIron(player, new SolderingInventory(player, equipped)); default: for (IGuiHandler handler : PluginManager.guiHandlers) { @@ -83,7 +83,7 @@ public class GuiHandler extends GuiHandlerBase { if (equipped == null) { return null; } - return new ContainerSolderingIron(player.inventory, new SolderingInventory(equipped)); + return new ContainerSolderingIron(player, new SolderingInventory(player, equipped)); default: for (IGuiHandler handler : PluginManager.guiHandlers) { diff --git a/src/main/java/forestry/core/circuits/ContainerSolderingIron.java b/src/main/java/forestry/core/circuits/ContainerSolderingIron.java index ddf0f48c5..77e543d6f 100755 --- a/src/main/java/forestry/core/circuits/ContainerSolderingIron.java +++ b/src/main/java/forestry/core/circuits/ContainerSolderingIron.java @@ -11,7 +11,6 @@ package forestry.core.circuits; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; import forestry.api.circuits.ICircuitLayout; import forestry.core.circuits.ItemSolderingIron.SolderingInventory; @@ -26,8 +25,8 @@ import forestry.core.proxy.Proxies; public class ContainerSolderingIron extends ContainerItemInventory implements IGuiSelectable { - public ContainerSolderingIron(InventoryPlayer inventoryplayer, SolderingInventory inventory) { - super(inventory); + public ContainerSolderingIron(EntityPlayer player, SolderingInventory inventory) { + super(inventory, player.inventory, 8, 123); // Input this.addSlotToContainer(new SlotFiltered(inventory, 0, 152, 12)); @@ -40,18 +39,6 @@ public class ContainerSolderingIron extends ContainerItemInventory { - public GuiSolderingIron(InventoryPlayer inventoryplayer, SolderingInventory inventory) { - super(Defaults.TEXTURE_PATH_GUI + "/solder.png", new ContainerSolderingIron(inventoryplayer, inventory), inventory); + public GuiSolderingIron(EntityPlayer player, SolderingInventory inventory) { + super(Defaults.TEXTURE_PATH_GUI + "/solder.png", new ContainerSolderingIron(player, inventory), inventory); xSize = 176; ySize = 205; diff --git a/src/main/java/forestry/core/circuits/ItemSolderingIron.java b/src/main/java/forestry/core/circuits/ItemSolderingIron.java index f6e673705..ad59601c6 100755 --- a/src/main/java/forestry/core/circuits/ItemSolderingIron.java +++ b/src/main/java/forestry/core/circuits/ItemSolderingIron.java @@ -108,9 +108,10 @@ public class ItemSolderingIron extends ItemForestry implements ISolderingIron { private static final short ingredientSlot1 = 2; private static final short ingredientSlotCount = 4; - public SolderingInventory(ItemStack itemStack) { - super(ItemSolderingIron.class, 6, itemStack); - init(); + public SolderingInventory(EntityPlayer player, ItemStack itemStack) { + super(player, 6, itemStack); + + layouts.setCurrent(ChipsetManager.circuitRegistry.getDefaultLayout()); } @Override @@ -118,10 +119,6 @@ public class ItemSolderingIron extends ItemForestry implements ISolderingIron { return 1; } - private void init() { - layouts.setCurrent(ChipsetManager.circuitRegistry.getDefaultLayout()); - } - public ICircuitLayout getLayout() { return layouts.getCurrent(); } @@ -143,7 +140,7 @@ public class ItemSolderingIron extends ItemForestry implements ISolderingIron { ArrayList circuits = new ArrayList(); for (short i = 0; i < type.sockets; i++) { - ItemStack ingredient = inventoryStacks[ingredientSlot1 + i]; + ItemStack ingredient = getStackInSlot(ingredientSlot1 + i); if (ingredient == null) { continue; } @@ -172,7 +169,7 @@ public class ItemSolderingIron extends ItemForestry implements ISolderingIron { return; } - ItemStack blank = inventoryStacks[blankSlot]; + ItemStack blank = getStackInSlot(blankSlot); // Requires blank slot if (blank == null) { return; @@ -180,7 +177,7 @@ public class ItemSolderingIron extends ItemForestry implements ISolderingIron { if (blank.stackSize > 1) { return; } - if (inventoryStacks[finishedSlot] != null) { + if (getStackInSlot(finishedSlot) != null) { return; } @@ -202,8 +199,12 @@ public class ItemSolderingIron extends ItemForestry implements ISolderingIron { } circuits = getCircuits(type, true); - inventoryStacks[finishedSlot] = ItemCircuitBoard.createCircuitboard(type, layouts.getCurrent(), circuits.toArray(new ICircuit[circuits.size()])); - inventoryStacks[blankSlot] = null; + + ICircuit[] circuitsArray = circuits.toArray(new ICircuit[circuits.size()]); + ItemStack circuitBoard = ItemCircuitBoard.createCircuitboard(type, layouts.getCurrent(), circuitsArray); + + setInventorySlotContents(finishedSlot, circuitBoard); + setInventorySlotContents(blankSlot, null); } public static int getCount(ICircuit circuit, ArrayList circuits) { @@ -229,7 +230,7 @@ public class ItemSolderingIron extends ItemForestry implements ISolderingIron { errorStates.add(EnumErrorCode.NOCIRCUITLAYOUT); } - ItemStack blankCircuitBoard = inventoryStacks[blankSlot]; + ItemStack blankCircuitBoard = getStackInSlot(blankSlot); if (blankCircuitBoard == null) { errorStates.add(EnumErrorCode.NOCIRCUITBOARD); @@ -238,7 +239,7 @@ public class ItemSolderingIron extends ItemForestry implements ISolderingIron { int circuitCount = 0; for (short i = 0; i < type.sockets; i++) { - if (inventoryStacks[ingredientSlot1 + i] != null) { + if (getStackInSlot(ingredientSlot1 + i) != null) { circuitCount++; } } diff --git a/src/main/java/forestry/core/gui/ContainerAlyzer.java b/src/main/java/forestry/core/gui/ContainerAlyzer.java index 25e808e08..3c2e1d6c3 100644 --- a/src/main/java/forestry/core/gui/ContainerAlyzer.java +++ b/src/main/java/forestry/core/gui/ContainerAlyzer.java @@ -1,7 +1,6 @@ package forestry.core.gui; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import forestry.core.gui.slots.SlotFiltered; @@ -11,7 +10,7 @@ import forestry.core.proxy.Proxies; public class ContainerAlyzer extends ContainerItemInventory { public ContainerAlyzer(AlyzerInventory inventory, EntityPlayer player) { - super(inventory); + super(inventory, player.inventory, 43, 156); final int xPosLeftSlots = 223; @@ -27,29 +26,6 @@ public class ContainerAlyzer extends ContainerItemInventory { this.addSlotToContainer(new SlotFiltered(inventory, AlyzerInventory.SLOT_ANALYZE_3, xPosLeftSlots, 93)); this.addSlotToContainer(new SlotFiltered(inventory, AlyzerInventory.SLOT_ANALYZE_4, xPosLeftSlots, 111)); this.addSlotToContainer(new SlotFiltered(inventory, AlyzerInventory.SLOT_ANALYZE_5, xPosLeftSlots, 129)); - - final int xPosPlayerInv = 43; - final int xSpacePlayerInv = 18; - final int yPosPlayerInv = 156; - final int ySpacePlayerInv = 18; - - // Player inventory - InventoryPlayer inventoryplayer = player.inventory; - - for (int i1 = 0; i1 < 3; i1++) { - for (int l1 = 0; l1 < 9; l1++) { - int slot = l1 + i1 * 9 + 9; - int x = xPosPlayerInv + (l1 * xSpacePlayerInv); - int y = yPosPlayerInv + (i1 * ySpacePlayerInv); - addSecuredSlot(inventoryplayer, slot, x, y); - } - } - // Player hotbar - for (int j1 = 0; j1 < 9; j1++) { - int x = xPosPlayerInv + (j1 * xSpacePlayerInv); - addSecuredSlot(inventoryplayer, j1, x, 214); - } - } @Override @@ -72,8 +48,6 @@ public class ContainerAlyzer extends ContainerItemInventory { Proxies.common.dropItemPlayer(entityplayer, stack); inventory.setInventorySlotContents(i, null); } - - inventory.onGuiSaved(entityplayer); } } diff --git a/src/main/java/forestry/core/gui/ContainerAnalyzer.java b/src/main/java/forestry/core/gui/ContainerAnalyzer.java index 6ebca9b88..ba82f06c5 100755 --- a/src/main/java/forestry/core/gui/ContainerAnalyzer.java +++ b/src/main/java/forestry/core/gui/ContainerAnalyzer.java @@ -11,17 +11,16 @@ package forestry.core.gui; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; import forestry.core.gadgets.TileAnalyzer; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; import forestry.core.gui.slots.SlotWorking; -public class ContainerAnalyzer extends ContainerLiquidTanks { +public class ContainerAnalyzer extends ContainerLiquidTanks { public ContainerAnalyzer(InventoryPlayer player, TileAnalyzer tile) { - super(tile); + super(tile, player, 8, 94); // Input buffer for (int i = 0; i < 3; i++) { @@ -42,18 +41,5 @@ public class ContainerAnalyzer extends ContainerLiquidTanks { addSlotToContainer(new SlotOutput(tile, TileAnalyzer.SLOT_OUTPUT_1 + i * 2 + k, 134 + k * 18, 48 + i * 18)); } } - - // Player inventory - for (int i1 = 0; i1 < 3; i1++) { - for (int l1 = 0; l1 < 9; l1++) { - addSlotToContainer(new Slot(player, l1 + i1 * 9 + 9, 8 + l1 * 18, 94 + i1 * 18)); - } - } - // Player hotbar - for (int j1 = 0; j1 < 9; j1++) { - addSlotToContainer(new Slot(player, j1, 8 + j1 * 18, 152)); - } - } - } diff --git a/src/main/java/forestry/core/gui/ContainerEscritoire.java b/src/main/java/forestry/core/gui/ContainerEscritoire.java index 384f2c738..a9a2dd239 100755 --- a/src/main/java/forestry/core/gui/ContainerEscritoire.java +++ b/src/main/java/forestry/core/gui/ContainerEscritoire.java @@ -11,7 +11,6 @@ package forestry.core.gui; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Slot; import forestry.core.gadgets.TileEscritoire; import forestry.core.gui.slots.SlotFiltered; @@ -21,42 +20,29 @@ import forestry.core.network.PacketPayload; import forestry.core.network.PacketUpdate; import forestry.core.proxy.Proxies; -public class ContainerEscritoire extends ContainerForestry implements IGuiSelectable { +public class ContainerEscritoire extends ContainerTile implements IGuiSelectable { - final EntityPlayer player; - final TileEscritoire tile; + private final EntityPlayer player; - public long lastUpdate; + private long lastUpdate; - public ContainerEscritoire(EntityPlayer player, TileEscritoire t) { - super(t); + public ContainerEscritoire(EntityPlayer player, TileEscritoire tile) { + super(tile, player.inventory, 34, 153); this.player = player; - this.tile = t; // Analyze slot - addSlotToContainer(new SlotFiltered(tile, TileEscritoire.SLOT_ANALYZE, 97, 67).setCrafter(tile)); + addSlotToContainer(new SlotFiltered(this.tile, TileEscritoire.SLOT_ANALYZE, 97, 67).setCrafter(this.tile)); for (int i = 0; i < TileEscritoire.SLOTS_INPUT_COUNT; i++) { - addSlotToContainer(new SlotFiltered(tile, TileEscritoire.SLOT_INPUT_1 + i, 17, 49 + i * 18).setBlockedTexture("slots/blocked_2")); + addSlotToContainer(new SlotFiltered(this.tile, TileEscritoire.SLOT_INPUT_1 + i, 17, 49 + i * 18).setBlockedTexture("slots/blocked_2")); } for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { - addSlotToContainer(new SlotOutput(tile, TileEscritoire.SLOT_RESULTS_1 + (i * 2) + j, 177 + j * 18, 85 + i * 18)); + addSlotToContainer(new SlotOutput(this.tile, TileEscritoire.SLOT_RESULTS_1 + (i * 2) + j, 177 + j * 18, 85 + i * 18)); } } - - // Player inventory - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 9; j++) { - addSlotToContainer(new Slot(player.inventory, j + i * 9 + 9, 34 + j * 18, 153 + i * 18)); - } - } - // Player hotbar - for (int k = 0; k < 9; k++) { - addSlotToContainer(new Slot(player.inventory, k, 34 + k * 18, 211)); - } } @Override diff --git a/src/main/java/forestry/core/gui/ContainerForestry.java b/src/main/java/forestry/core/gui/ContainerForestry.java old mode 100755 new mode 100644 index d8ae037a1..37b686910 --- a/src/main/java/forestry/core/gui/ContainerForestry.java +++ b/src/main/java/forestry/core/gui/ContainerForestry.java @@ -1,74 +1,65 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.core.gui; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; - -import forestry.core.gadgets.TileForestry; -import forestry.core.gui.slots.SlotForestry; -import forestry.core.interfaces.IRestrictedAccess; -import forestry.core.inventory.ItemInventory; -import forestry.core.utils.SlotHelper; - -public class ContainerForestry extends Container { - - private final IInventory inventoryAccess; - private final IRestrictedAccess restrictedAccess; - - public ContainerForestry(TileForestry tileForestry) { - this.inventoryAccess = tileForestry; - this.restrictedAccess = tileForestry; - } - - public ContainerForestry(ItemInventory itemInventory) { - this.inventoryAccess = itemInventory; - this.restrictedAccess = null; - } - - @Override - public ItemStack slotClick(int slotIndex, int button, int modifier, EntityPlayer player) { - if (!canAccess(player)) { - return null; - } - - Slot slot = (slotIndex < 0) ? null : (Slot) this.inventorySlots.get(slotIndex); - if (slot instanceof SlotForestry && ((SlotForestry) slot).isPhantom()) { - return SlotHelper.slotClickPhantom(slot, button, modifier, player); - } - - return super.slotClick(slotIndex, button, modifier, player); - } - - @Override - public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) { - if (!canAccess(player)) { - return null; - } - - return SlotHelper.transferStackInSlot(inventorySlots, player, slotIndex); - } - - private boolean canAccess(EntityPlayer player) { - return player != null && (restrictedAccess == null || restrictedAccess.allowsAlteration(player)); - } - - @Override - public final boolean canInteractWith(EntityPlayer entityplayer) { - if (inventoryAccess == null) { - return true; - } - return inventoryAccess.isUseableByPlayer(entityplayer); - } -} +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.gui; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import forestry.core.gui.slots.SlotForestry; +import forestry.core.utils.SlotHelper; + +public abstract class ContainerForestry extends Container { + + protected final void addPlayerInventory(InventoryPlayer playerInventory, int xInv, int yInv) { + // 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)); + } + } + // Player hotbar + for (int column = 0; column < 9; column++) { + addHotbarSlot(playerInventory, column, xInv + column * 18, yInv + 58); + } + } + + protected void addHotbarSlot(InventoryPlayer playerInventory, int slot, int x, int y) { + addSlotToContainer(new Slot(playerInventory, slot, x, y)); + } + + @Override + public ItemStack slotClick(int slotIndex, int button, int modifier, EntityPlayer player) { + if (!canAccess(player)) { + return null; + } + + Slot slot = (slotIndex < 0) ? null : (Slot) this.inventorySlots.get(slotIndex); + if (slot instanceof SlotForestry && ((SlotForestry) slot).isPhantom()) { + return SlotHelper.slotClickPhantom(slot, button, modifier, player); + } + + return super.slotClick(slotIndex, button, modifier, player); + } + + @Override + public final ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) { + if (!canAccess(player)) { + return null; + } + + return SlotHelper.transferStackInSlot(inventorySlots, player, slotIndex); + } + + protected abstract boolean canAccess(EntityPlayer player); +} diff --git a/src/main/java/forestry/core/gui/ContainerItemInventory.java b/src/main/java/forestry/core/gui/ContainerItemInventory.java index a1d51da23..ce63b7c0e 100755 --- a/src/main/java/forestry/core/gui/ContainerItemInventory.java +++ b/src/main/java/forestry/core/gui/ContainerItemInventory.java @@ -17,21 +17,22 @@ import net.minecraft.item.ItemStack; import forestry.core.gui.slots.SlotLocked; import forestry.core.inventory.ItemInventory; -import forestry.core.proxy.Proxies; -import forestry.core.utils.StackUtils; public abstract class ContainerItemInventory extends ContainerForestry { protected final I inventory; - public ContainerItemInventory(I inventory) { - super(inventory); + public ContainerItemInventory(I inventory, InventoryPlayer playerInventory, int xInv, int yInv) { this.inventory = inventory; + + addPlayerInventory(playerInventory, xInv, yInv); } - protected void addSecuredSlot(InventoryPlayer playerInventory, int slot, int x, int y) { + @Override + protected void addHotbarSlot(InventoryPlayer playerInventory, int slot, int x, int y) { ItemStack stackInSlot = playerInventory.getStackInSlot(slot); - if (StackUtils.isIdenticalItem(inventory.parent, stackInSlot)) { + + if (inventory.isParentItemInventory(stackInSlot)) { addSlotToContainer(new SlotLocked(playerInventory, slot, x, y)); } else { addSlotToContainer(new Slot(playerInventory, slot, x, y)); @@ -39,12 +40,12 @@ public abstract class ContainerItemInventory extends Co } @Override - public void onContainerClosed(EntityPlayer player) { - super.onContainerClosed(player); - if (!Proxies.common.isSimulating(player.worldObj)) { - return; - } + protected final boolean canAccess(EntityPlayer player) { + return canInteractWith(player); + } - inventory.onGuiSaved(player); + @Override + public final boolean canInteractWith(EntityPlayer entityplayer) { + return inventory.isUseableByPlayer(entityplayer); } } diff --git a/src/main/java/forestry/core/gui/ContainerLiquidTanks.java b/src/main/java/forestry/core/gui/ContainerLiquidTanks.java index d75c3e01f..384f6d120 100755 --- a/src/main/java/forestry/core/gui/ContainerLiquidTanks.java +++ b/src/main/java/forestry/core/gui/ContainerLiquidTanks.java @@ -12,6 +12,7 @@ package forestry.core.gui; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ICrafting; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -30,13 +31,10 @@ import forestry.core.network.PacketPayload; import forestry.core.network.PacketUpdate; import forestry.core.proxy.Proxies; -public class ContainerLiquidTanks extends ContainerForestry { +public class ContainerLiquidTanks extends ContainerTile { - private final ILiquidTankContainer tile; - - public ContainerLiquidTanks(T tile) { - super(tile); - this.tile = tile; + public ContainerLiquidTanks(T tile, InventoryPlayer playerInventory, int xInv, int yInv) { + super(tile, playerInventory, xInv, yInv); } @SideOnly(Side.CLIENT) diff --git a/src/main/java/forestry/core/gui/ContainerNaturalistInventory.java b/src/main/java/forestry/core/gui/ContainerNaturalistInventory.java index ac1aa64c7..a0e448ca4 100755 --- a/src/main/java/forestry/core/gui/ContainerNaturalistInventory.java +++ b/src/main/java/forestry/core/gui/ContainerNaturalistInventory.java @@ -12,19 +12,15 @@ package forestry.core.gui; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; import forestry.core.gadgets.TileNaturalistChest; import forestry.core.gui.slots.SlotFiltered; import forestry.core.network.PacketUpdate; -public class ContainerNaturalistInventory extends ContainerForestry implements IGuiSelectable { - - private final IPagedInventory inv; +public class ContainerNaturalistInventory extends ContainerTile implements IGuiSelectable { public ContainerNaturalistInventory(InventoryPlayer player, TileNaturalistChest tile, int page, int pageSize) { - super(tile); - this.inv = tile; + super(tile, player, 18, 120); // Inventory for (int x = 0; x < 5; x++) { @@ -32,22 +28,11 @@ public class ContainerNaturalistInventory extends ContainerForestry implements I addSlotToContainer(new SlotFiltered(tile, y + page * pageSize + x * 5, 100 + y * 18, 21 + x * 18)); } } - - // Player inventory - for (int i1 = 0; i1 < 3; i1++) { - for (int l1 = 0; l1 < 9; l1++) { - addSlotToContainer(new Slot(player, l1 + i1 * 9 + 9, 18 + l1 * 18, 120 + i1 * 18)); - } - } - // Player hotbar - for (int j1 = 0; j1 < 9; j1++) { - addSlotToContainer(new Slot(player, j1, 18 + j1 * 18, 178)); - } } @Override public void handleSelectionChange(EntityPlayer player, PacketUpdate packet) { - inv.flipPage(player, packet.payload.intPayload[0]); + tile.flipPage(player, packet.payload.intPayload[0]); } @Override diff --git a/src/main/java/forestry/core/gui/ContainerSocketed.java b/src/main/java/forestry/core/gui/ContainerSocketed.java index d29e78ac3..851337cb8 100755 --- a/src/main/java/forestry/core/gui/ContainerSocketed.java +++ b/src/main/java/forestry/core/gui/ContainerSocketed.java @@ -11,6 +11,7 @@ package forestry.core.gui; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; @@ -23,13 +24,10 @@ import forestry.core.network.PacketUpdate; import forestry.core.proxy.Proxies; import forestry.core.utils.StackUtils; -public class ContainerSocketed extends ContainerForestry { +public class ContainerSocketed extends ContainerTile { - private final ISocketable tile; - - public ContainerSocketed(TileForestry inventory, ISocketable tile) { - super(inventory); - this.tile = tile; + public ContainerSocketed(T tile, InventoryPlayer playerInventory, int xInv, int yInv) { + super(tile, playerInventory, xInv, yInv); } public void handleChipsetClick(int slot, EntityPlayer player, ItemStack itemstack) { diff --git a/src/main/java/forestry/core/gui/ContainerTile.java b/src/main/java/forestry/core/gui/ContainerTile.java new file mode 100644 index 000000000..6373f499e --- /dev/null +++ b/src/main/java/forestry/core/gui/ContainerTile.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.gui; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; + +import forestry.core.gadgets.TileForestry; + +public class ContainerTile extends ContainerForestry { + + protected final T tile; + + public ContainerTile(T tileForestry, InventoryPlayer playerInventory, int xInv, int yInv) { + this.tile = tileForestry; + + addPlayerInventory(playerInventory, xInv, yInv); + } + + @Override + protected final boolean canAccess(EntityPlayer player) { + return player != null && tile.allowsAlteration(player); + } + + @Override + public final boolean canInteractWith(EntityPlayer entityplayer) { + return tile.isUseableByPlayer(entityplayer); + } +} diff --git a/src/main/java/forestry/core/gui/slots/SlotCraftMatrix.java b/src/main/java/forestry/core/gui/slots/SlotCraftMatrix.java index b0ec35a61..0c5a91f03 100644 --- a/src/main/java/forestry/core/gui/slots/SlotCraftMatrix.java +++ b/src/main/java/forestry/core/gui/slots/SlotCraftMatrix.java @@ -27,7 +27,7 @@ public class SlotCraftMatrix extends SlotForestry { setPhantom(); this.eventHandler = container; this.slot = i; - stackLimit = 1; + setStackLimit(1); } @Override diff --git a/src/main/java/forestry/core/gui/slots/SlotForestry.java b/src/main/java/forestry/core/gui/slots/SlotForestry.java index b1611e3c1..4fb9ebab3 100755 --- a/src/main/java/forestry/core/gui/slots/SlotForestry.java +++ b/src/main/java/forestry/core/gui/slots/SlotForestry.java @@ -20,11 +20,11 @@ import forestry.core.gui.tooltips.ToolTip; public class SlotForestry extends Slot implements IToolTipProvider { - protected boolean isPhantom; - protected boolean isInfinite; - protected boolean canAdjustPhantom = true; - protected boolean canShift = true; - protected int stackLimit; + private boolean isPhantom; + private boolean isInfinite; + private boolean canAdjustPhantom = true; + private boolean canShift = true; + private int stackLimit; private ToolTip toolTips; public SlotForestry(IInventory inventory, int slotIndex, int xPos, int yPos) { @@ -62,11 +62,6 @@ public class SlotForestry extends Slot implements IToolTipProvider { return this; } - public SlotForestry setCanShift(boolean canShift) { - this.canShift = canShift; - return this; - } - public SlotForestry setStackLimit(int limit) { this.stackLimit = limit; return this; diff --git a/src/main/java/forestry/core/gui/slots/SlotLocked.java b/src/main/java/forestry/core/gui/slots/SlotLocked.java index b606299df..8cb1d7a31 100755 --- a/src/main/java/forestry/core/gui/slots/SlotLocked.java +++ b/src/main/java/forestry/core/gui/slots/SlotLocked.java @@ -19,7 +19,7 @@ public class SlotLocked extends SlotForestry { public SlotLocked(IInventory par1iInventory, int par2, int par3, int par4) { super(par1iInventory, par2, par3, par4); setCanAdjustPhantom(false); - setCanShift(false); + blockShift(); setPhantom(); } diff --git a/src/main/java/forestry/core/gui/slots/SlotWorking.java b/src/main/java/forestry/core/gui/slots/SlotWorking.java index a1bd1e6dd..fe817c886 100755 --- a/src/main/java/forestry/core/gui/slots/SlotWorking.java +++ b/src/main/java/forestry/core/gui/slots/SlotWorking.java @@ -18,7 +18,7 @@ public class SlotWorking extends SlotForestry { public SlotWorking(IInventory iinventory, int i, int j, int k) { super(iinventory, i, j, k); - setCanShift(false); + blockShift(); } @Override diff --git a/src/main/java/forestry/core/inventory/AlyzerInventory.java b/src/main/java/forestry/core/inventory/AlyzerInventory.java index aecd90b98..c1a9c3d95 100644 --- a/src/main/java/forestry/core/inventory/AlyzerInventory.java +++ b/src/main/java/forestry/core/inventory/AlyzerInventory.java @@ -3,7 +3,6 @@ package forestry.core.inventory; import com.google.common.collect.ImmutableSet; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import forestry.api.core.IErrorState; @@ -21,10 +20,11 @@ public abstract class AlyzerInventory extends ItemInventory implements IErrorSou public static final int SLOT_ANALYZE_5 = 6; public static final int SLOT_ENERGY = 5; - protected EntityPlayer player; + protected final EntityPlayer player; - public AlyzerInventory(Class itemClass, int size, ItemStack itemstack) { - super(itemClass, size, itemstack); + public AlyzerInventory(EntityPlayer player, int size, ItemStack itemstack) { + super(player, size, itemstack); + this.player = player; } protected static boolean isEnergy(ItemStack itemstack) { diff --git a/src/main/java/forestry/core/inventory/ItemInventory.java b/src/main/java/forestry/core/inventory/ItemInventory.java index 9830e8121..2f68ba4ec 100755 --- a/src/main/java/forestry/core/inventory/ItemInventory.java +++ b/src/main/java/forestry/core/inventory/ItemInventory.java @@ -12,33 +12,31 @@ package forestry.core.inventory; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import forestry.api.core.INBTTagable; import forestry.core.interfaces.IFilterSlotDelegate; -import forestry.core.utils.StackUtils; import forestry.core.utils.Utils; -public class ItemInventory implements IInventory, IFilterSlotDelegate, INBTTagable { +public abstract class ItemInventory implements IInventory, IFilterSlotDelegate { - public final Class itemClass; - public ItemStack parent; - protected ItemStack[] inventoryStacks; + private static final String KEY_ITEMS = "Items"; // legacy + private static final String KEY_SLOTS = "Slots"; + private static final String KEY_UID = "UID"; - public ItemInventory(Class itemClass, int size, ItemStack itemstack) { - this.itemClass = itemClass; + private final EntityPlayer player; + private final ItemStack parent; + private final ItemStack[] inventoryStacks; - inventoryStacks = new ItemStack[size]; + public ItemInventory(EntityPlayer player, int size, ItemStack parent) { + this.player = player; + this.parent = parent; + this.inventoryStacks = new ItemStack[size]; - parent = itemstack; + setUID(); // Set a uid to identify the itemstack on SMP - // Set an uid to identify the itemstack on SMP - setUID(false); - - readFromNBT(itemstack.getTagCompound()); + readFromNBT(parent.getTagCompound()); } public static int getOccupiedSlotCount(ItemStack itemStack) { @@ -47,9 +45,14 @@ public class ItemInventory implements IInventory, IFilterSlotDelegate, INBTTagab return 0; } + if (nbt.hasKey(KEY_SLOTS)) { + NBTTagCompound slotNbt = nbt.getCompoundTag(KEY_SLOTS); + return slotNbt.func_150296_c().size(); + } + int count = 0; - if (nbt.hasKey("Items")) { - NBTTagList nbttaglist = nbt.getTagList("Items", 10); + if (nbt.hasKey(KEY_ITEMS)) { // legacy since Forestry 3.6 + NBTTagList nbttaglist = nbt.getTagList(KEY_ITEMS, 10); for (int i = 0; i < nbttaglist.tagCount(); i++) { NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); ItemStack itemStack1 = ItemStack.loadItemStackFromNBT(nbttagcompound1); @@ -58,107 +61,172 @@ public class ItemInventory implements IInventory, IFilterSlotDelegate, INBTTagab } } } + return count; } - protected void setUID(boolean override) { + private void setUID() { + ItemStack parent = getParent(); + if (parent.getTagCompound() == null) { parent.setTagCompound(new NBTTagCompound()); } NBTTagCompound nbt = parent.getTagCompound(); - if (override || !nbt.hasKey("UID")) { - nbt.setInteger("UID", Utils.getUID()); + if (!nbt.hasKey(KEY_UID)) { + nbt.setInteger(KEY_UID, Utils.getUID()); } } - public void onGuiSaved(EntityPlayer player) { - parent = findParentInInventory(player); - if (parent != null) { - save(); - } + public boolean isParentItemInventory(ItemStack itemStack) { + ItemStack parent = getParent(); + return isSameItemInventory(parent, itemStack); } - public ItemStack findParentInInventory(EntityPlayer player) { - for (int i = 0; i < player.inventory.getSizeInventory(); i++) { - ItemStack stack = player.inventory.getStackInSlot(i); - if (StackUtils.isIdenticalItem(stack, parent)) { - return stack; - } + protected ItemStack getParent() { + ItemStack equipped = player.getCurrentEquippedItem(); + if (isSameItemInventory(equipped, parent)) { + return equipped; } return parent; } - public void save() { - NBTTagCompound nbt = parent.getTagCompound(); - if (nbt == null) { - nbt = new NBTTagCompound(); + private static boolean isSameItemInventory(ItemStack base, ItemStack comparison) { + if (base == null || comparison == null) { + return false; } - writeToNBT(nbt); - parent.setTagCompound(nbt); + + if (base.getItem() != comparison.getItem()) { + return false; + } + + if (!base.hasTagCompound() || !comparison.hasTagCompound()) { + return false; + } + + String baseUID = base.getTagCompound().getString(KEY_UID); + String comparisonUID = comparison.getTagCompound().getString(KEY_UID); + return baseUID != null && comparisonUID != null && baseUID.equals(comparisonUID); } - @Override public void readFromNBT(NBTTagCompound nbt) { if (nbt == null) { return; } - if (nbt.hasKey("Items")) { - NBTTagList nbttaglist = nbt.getTagList("Items", 10); - inventoryStacks = new ItemStack[getSizeInventory()]; - for (int i = 0; i < nbttaglist.tagCount(); i++) { - NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); - byte byte0 = nbttagcompound1.getByte("Slot"); - if (byte0 >= 0 && byte0 < inventoryStacks.length) { - inventoryStacks[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound1); + if (nbt.hasKey(KEY_SLOTS)) { + NBTTagCompound nbtSlots = nbt.getCompoundTag(KEY_SLOTS); + for (int i = 0; i < inventoryStacks.length; i++) { + String slotKey = getSlotNBTKey(i); + if (nbtSlots.hasKey(slotKey)) { + NBTTagCompound itemNbt = nbtSlots.getCompoundTag(slotKey); + ItemStack itemStack = ItemStack.loadItemStackFromNBT(itemNbt); + inventoryStacks[i] = itemStack; + } else { + inventoryStacks[i] = null; } } - } + } else { - } + // legacy since Forestry 3.6 + if (nbt.hasKey(KEY_ITEMS)) { + for (int i = 0; i < inventoryStacks.length; i++) { + inventoryStacks[i] = null; + } - @Override - public void writeToNBT(NBTTagCompound nbt) { + NBTTagList nbttaglist = nbt.getTagList(KEY_ITEMS, 10); + for (int i = 0; i < nbttaglist.tagCount(); i++) { + NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); + byte byte0 = nbttagcompound1.getByte("Slot"); + if (byte0 >= 0 && byte0 < inventoryStacks.length) { + ItemStack itemStack = ItemStack.loadItemStackFromNBT(nbttagcompound1); + inventoryStacks[byte0] = itemStack; + } + } - NBTTagList nbttaglist = new NBTTagList(); - for (int i = 0; i < inventoryStacks.length; i++) { - if (inventoryStacks[i] != null) { - NBTTagCompound nbttagcompound1 = new NBTTagCompound(); - nbttagcompound1.setByte("Slot", (byte) i); - inventoryStacks[i].writeToNBT(nbttagcompound1); - nbttaglist.appendTag(nbttagcompound1); + migrateToNewNBT(); } } - nbt.setTag("Items", nbttaglist); + } + private void migrateToNewNBT() { + ItemStack parent = getParent(); + if (parent == null) { + return; + } + + NBTTagCompound nbt = parent.getTagCompound(); + NBTTagCompound slotsNbt = new NBTTagCompound(); + for (int i = 0; i < getSizeInventory(); i++) { + ItemStack itemStack = getStackInSlot(i); + if (itemStack != null) { + String slotKey = getSlotNBTKey(i); + NBTTagCompound itemNbt = new NBTTagCompound(); + itemStack.writeToNBT(itemNbt); + slotsNbt.setTag(slotKey, itemNbt); + } + } + + nbt.setTag(KEY_SLOTS, slotsNbt); + nbt.removeTag(KEY_ITEMS); + } + + private static String getSlotNBTKey(int i) { + return Integer.toString(i, Character.MAX_RADIX); } @Override public ItemStack decrStackSize(int i, int j) { - if (inventoryStacks[i] == null) { + ItemStack stack = getStackInSlot(i); + if (stack == null) { return null; } - ItemStack product; - if (inventoryStacks[i].stackSize <= j) { - product = inventoryStacks[i]; - inventoryStacks[i] = null; - return product; + if (stack.stackSize <= j) { + setInventorySlotContents(i, null); + return stack; } else { - product = inventoryStacks[i].splitStack(j); - if (inventoryStacks[i].stackSize == 0) { - inventoryStacks[i] = null; - } - + ItemStack product = stack.splitStack(j); + setInventorySlotContents(i, stack); return product; } } @Override public void setInventorySlotContents(int i, ItemStack itemstack) { + if (itemstack != null && itemstack.stackSize == 0) { + itemstack = null; + } + inventoryStacks[i] = itemstack; + + ItemStack parent = getParent(); + + NBTTagCompound nbt = parent.getTagCompound(); + if (nbt == null) { + nbt = new NBTTagCompound(); + parent.setTagCompound(nbt); + } + + NBTTagCompound slotNbt; + if (!nbt.hasKey(KEY_SLOTS)) { + slotNbt = new NBTTagCompound(); + nbt.setTag(KEY_SLOTS, slotNbt); + } else { + slotNbt = nbt.getCompoundTag(KEY_SLOTS); + } + + String slotKey = getSlotNBTKey(i); + + if (itemstack == null) { + slotNbt.removeTag(slotKey); + } else { + NBTTagCompound itemNbt = new NBTTagCompound(); + itemstack.writeToNBT(itemNbt); + + slotNbt.setTag(slotKey, itemNbt); + } } @Override @@ -200,16 +268,6 @@ public class ItemInventory implements IInventory, IFilterSlotDelegate, INBTTagab return canSlotAccept(slotIndex, itemStack); } - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - return true; - } - - @Override - public boolean isLocked(int slotIndex) { - return false; - } - @Override public void openInventory() { } @@ -220,11 +278,23 @@ public class ItemInventory implements IInventory, IFilterSlotDelegate, INBTTagab @Override public ItemStack getStackInSlotOnClosing(int slot) { - if (inventoryStacks[slot] == null) { - return null; + ItemStack toReturn = getStackInSlot(slot); + + if (toReturn != null) { + setInventorySlotContents(slot, null); } - ItemStack toReturn = inventoryStacks[slot]; - inventoryStacks[slot] = null; + return toReturn; } + + /* Filter Slot Delegate */ + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + return true; + } + + @Override + public boolean isLocked(int slotIndex) { + return false; + } } diff --git a/src/main/java/forestry/core/inventory/ItemInventoryBackpack.java b/src/main/java/forestry/core/inventory/ItemInventoryBackpack.java index 6265f6579..7b5d65001 100644 --- a/src/main/java/forestry/core/inventory/ItemInventoryBackpack.java +++ b/src/main/java/forestry/core/inventory/ItemInventoryBackpack.java @@ -1,5 +1,6 @@ package forestry.core.inventory; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -10,8 +11,8 @@ public class ItemInventoryBackpack extends ItemInventory { private final IBackpackDefinition backpackDefinition; - public ItemInventoryBackpack(Class itemClass, int size, ItemStack itemstack) { - super(itemClass, size, itemstack); + public ItemInventoryBackpack(EntityPlayer player, int size, ItemStack parent) { + super(player, size, parent); if (parent == null) { throw new IllegalArgumentException("Parent cannot be null."); diff --git a/src/main/java/forestry/core/items/ItemInventoried.java b/src/main/java/forestry/core/items/ItemInventoried.java index b2149c034..152146409 100755 --- a/src/main/java/forestry/core/items/ItemInventoried.java +++ b/src/main/java/forestry/core/items/ItemInventoried.java @@ -19,10 +19,6 @@ import forestry.core.interfaces.IInventoriedItem; public abstract class ItemInventoried extends ItemForestry implements IInventoriedItem { - public ItemInventoried() { - super(); - } - @Override public boolean onDroppedByPlayer(ItemStack itemstack, EntityPlayer player) { if (itemstack != null && diff --git a/src/main/java/forestry/core/network/ForestryPacket.java b/src/main/java/forestry/core/network/ForestryPacket.java index a270285a1..7d07547c9 100755 --- a/src/main/java/forestry/core/network/ForestryPacket.java +++ b/src/main/java/forestry/core/network/ForestryPacket.java @@ -24,8 +24,6 @@ import net.minecraft.nbt.NBTTagCompound; import cpw.mods.fml.common.network.internal.FMLProxyPacket; import cpw.mods.fml.common.registry.GameData; -import forestry.core.proxy.Proxies; - import io.netty.buffer.Unpooled; public class ForestryPacket { @@ -68,7 +66,7 @@ public class ForestryPacket { short meta = data.readShort(); itemstack = new ItemStack(item, stackSize, meta); - if (item.isDamageable() || Proxies.common.needsTagCompoundSynched(item)) { + if (item.isDamageable() || item.getShareTag()) { itemstack.stackTagCompound = this.readNBTTagCompound(data); } } @@ -85,7 +83,7 @@ public class ForestryPacket { data.writeByte(itemstack.stackSize); data.writeShort(itemstack.getItemDamage()); - if (itemstack.getItem().isDamageable() || Proxies.common.needsTagCompoundSynched(itemstack.getItem())) { + if (itemstack.getItem().isDamageable() || itemstack.getItem().getShareTag()) { this.writeNBTTagCompound(itemstack.stackTagCompound, data); } } diff --git a/src/main/java/forestry/core/proxy/ClientProxyCommon.java b/src/main/java/forestry/core/proxy/ClientProxyCommon.java index 9fa3ff361..a85f241f2 100755 --- a/src/main/java/forestry/core/proxy/ClientProxyCommon.java +++ b/src/main/java/forestry/core/proxy/ClientProxyCommon.java @@ -75,11 +75,6 @@ public class ClientProxyCommon extends ProxyCommon { return getClientInstance().theWorld; } - @Override - public int getBlockModelIdEngine() { - return ForestryClient.blockModelIdEngine; - } - @Override public int getByBlockModelId() { return ForestryClient.byBlockModelId; diff --git a/src/main/java/forestry/core/proxy/ProxyCommon.java b/src/main/java/forestry/core/proxy/ProxyCommon.java index 9350ef71e..021da79eb 100755 --- a/src/main/java/forestry/core/proxy/ProxyCommon.java +++ b/src/main/java/forestry/core/proxy/ProxyCommon.java @@ -218,10 +218,6 @@ public class ProxyCommon { public void addEntityExplodeFX(World world, double d1, double d2, double d3, float f1, float f2, float f3) { } - public boolean needsTagCompoundSynched(Item item) { - return item.getShareTag(); - } - public void addBlockDestroyEffects(World world, int xCoord, int yCoord, int zCoord, Block block, int i) { sendFXSignal(PacketFXSignal.VisualFXType.BLOCK_DESTROY, PacketFXSignal.SoundFXType.BLOCK_DESTROY, world, xCoord, yCoord, zCoord, block, i); } @@ -255,14 +251,6 @@ public class ProxyCommon { return FMLClientHandler.instance().getClient(); } - public int getBlockModelIdEngine() { - return 0; - } - - public void closeGUI(EntityPlayer player) { - player.closeScreen(); - } - /* DEPENDENCY HANDLING */ public boolean isModLoaded(String modname) { return Loader.isModLoaded(modname); diff --git a/src/main/java/forestry/core/utils/ShapedRecipeCustom.java b/src/main/java/forestry/core/utils/ShapedRecipeCustom.java index 1710bf1f9..38596e907 100755 --- a/src/main/java/forestry/core/utils/ShapedRecipeCustom.java +++ b/src/main/java/forestry/core/utils/ShapedRecipeCustom.java @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.HashMap; import net.minecraft.block.Block; +import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -71,17 +72,30 @@ public class ShapedRecipeCustom implements IDescriptiveRecipe { } @Override - public boolean matches(InventoryCrafting inventorycrafting, World world) { + public boolean matches(InventoryCrafting inventoryCrafting, World world) { + return matches((IInventory) inventoryCrafting, world); + } + + public boolean matches(IInventory inventoryCrafting, World world) { ItemStack[][] resources = new ItemStack[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - resources[i][j] = inventorycrafting.getStackInRowAndColumn(i, j); + resources[i][j] = getStackInRowAndColumn(inventoryCrafting, i, j); } } return matches(resources); } + public ItemStack getStackInRowAndColumn(IInventory inventory, int i, int j) { + if (i >= 0 && i < width) { + int k = i + j * width; + return inventory.getStackInSlot(k); + } else { + return null; + } + } + public boolean matches(ItemStack[][] resources) { for (int i = 0; i <= 3 - width; i++) { diff --git a/src/main/java/forestry/core/utils/SlotHelper.java b/src/main/java/forestry/core/utils/SlotHelper.java index 540543520..5b63952eb 100644 --- a/src/main/java/forestry/core/utils/SlotHelper.java +++ b/src/main/java/forestry/core/utils/SlotHelper.java @@ -79,18 +79,22 @@ public class SlotHelper { } private static boolean shiftItemStack(List inventorySlots, ItemStack stackInSlot, int slotIndex, int numSlots) { - if (isInPlayerInventory(slotIndex, numSlots)) { + if (isInPlayerInventory(slotIndex)) { if (shiftToMachineInventory(inventorySlots, stackInSlot, numSlots)) { return true; } - if (isInPlayerHotbar(slotIndex, numSlots)) { - return shiftToPlayerInventoryNoHotbar(inventorySlots, stackInSlot, numSlots); + if (isInPlayerHotbar(slotIndex)) { + return shiftToPlayerInventoryNoHotbar(inventorySlots, stackInSlot); } else { - return shiftToHotbar(inventorySlots, stackInSlot, numSlots); + return shiftToHotbar(inventorySlots, stackInSlot); } } else { - return shiftToPlayerInventory(inventorySlots, stackInSlot, numSlots); + boolean shifted = shiftToHotbar(inventorySlots, stackInSlot); + if (!shifted) { + shifted = shiftToPlayerInventoryNoHotbar(inventorySlots, stackInSlot); + } + return shifted; } } @@ -139,10 +143,10 @@ public class SlotHelper { slot.putStack(phantomStack); } - private static boolean shiftItemStackToRange(List inventorySlots, ItemStack stackToShift, int start, int end) { + private static boolean shiftItemStackToRange(List inventorySlots, ItemStack stackToShift, int start, int count) { boolean changed = false; if (stackToShift.isStackable()) { - for (int slotIndex = start; stackToShift.stackSize > 0 && slotIndex < end; slotIndex++) { + for (int slotIndex = start; stackToShift.stackSize > 0 && slotIndex < start + count; slotIndex++) { Slot slot = (Slot) inventorySlots.get(slotIndex); ItemStack stackInSlot = slot.getStack(); if (stackInSlot != null && StackUtils.isIdenticalItem(stackInSlot, stackToShift)) { @@ -163,7 +167,7 @@ public class SlotHelper { } } if (stackToShift.stackSize > 0) { - for (int slotIndex = start; stackToShift.stackSize > 0 && slotIndex < end; slotIndex++) { + for (int slotIndex = start; stackToShift.stackSize > 0 && slotIndex < start + count; slotIndex++) { Slot slot = (Slot) inventorySlots.get(slotIndex); ItemStack stackInSlot = slot.getStack(); if (stackInSlot == null) { @@ -183,28 +187,22 @@ public class SlotHelper { private static final int playerInventorySize = 9 * 4; private static final int playerHotbarSize = 9; - private static boolean isInPlayerInventory(int slotIndex, int numSlots) { - return slotIndex >= numSlots - playerInventorySize; + private static boolean isInPlayerInventory(int slotIndex) { + return slotIndex < playerInventorySize; } - private static boolean isInPlayerHotbar(int slotIndex, int numSlots) { - return slotIndex >= numSlots - playerHotbarSize; + private static boolean isInPlayerHotbar(int slotIndex) { + return GuiUtil.isIndexInRange(slotIndex, playerInventorySize - playerHotbarSize, playerInventorySize); } - private static boolean shiftToPlayerInventory(List inventorySlots, ItemStack stackInSlot, int numSlots) { - int playerInventoryStart = numSlots - playerInventorySize; - return shiftItemStackToRange(inventorySlots, stackInSlot, playerInventoryStart, numSlots); + private static boolean shiftToPlayerInventoryNoHotbar(List inventorySlots, ItemStack stackInSlot) { + int playerHotbarStart = playerInventorySize - playerHotbarSize; + return shiftItemStackToRange(inventorySlots, stackInSlot, 0, playerHotbarStart); } - private static boolean shiftToPlayerInventoryNoHotbar(List inventorySlots, ItemStack stackInSlot, int numSlots) { - int playerInventoryStart = numSlots - playerInventorySize; - int playerHotbarStart = numSlots - playerHotbarSize; - return shiftItemStackToRange(inventorySlots, stackInSlot, playerInventoryStart, playerHotbarStart); - } - - private static boolean shiftToHotbar(List inventorySlots, ItemStack stackInSlot, int numSlots) { - int playerHotbarStart = numSlots - playerHotbarSize; - return shiftItemStackToRange(inventorySlots, stackInSlot, playerHotbarStart, numSlots); + private static boolean shiftToHotbar(List inventorySlots, ItemStack stackInSlot) { + int playerHotbarStart = playerInventorySize - playerHotbarSize; + return shiftItemStackToRange(inventorySlots, stackInSlot, playerHotbarStart, playerHotbarSize); } private static boolean shiftToMachineInventory(List inventorySlots, ItemStack stackToShift, int numSlots) { @@ -220,7 +218,7 @@ public class SlotHelper { // if mergeOnly = true, don't shift into empty slots. private static boolean shiftToMachineInventory(List inventorySlots, ItemStack stackToShift, int numSlots, boolean mergeOnly) { - for (int machineIndex = 0; machineIndex < numSlots - playerInventorySize; machineIndex++) { + for (int machineIndex = playerInventorySize; machineIndex < numSlots; machineIndex++) { Slot slot = (Slot) inventorySlots.get(machineIndex); if (mergeOnly && slot.getStack() == null) { continue; @@ -234,7 +232,7 @@ public class SlotHelper { if (!slot.isItemValid(stackToShift)) { continue; } - if (shiftItemStackToRange(inventorySlots, stackToShift, machineIndex, machineIndex + 1)) { + if (shiftItemStackToRange(inventorySlots, stackToShift, machineIndex, 1)) { return true; } } diff --git a/src/main/java/forestry/energy/gui/ContainerEngineBronze.java b/src/main/java/forestry/energy/gui/ContainerEngineBronze.java index a1408c663..6b8d65d1f 100755 --- a/src/main/java/forestry/energy/gui/ContainerEngineBronze.java +++ b/src/main/java/forestry/energy/gui/ContainerEngineBronze.java @@ -11,34 +11,17 @@ package forestry.energy.gui; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; import forestry.core.gui.ContainerLiquidTanks; import forestry.core.gui.slots.SlotFiltered; import forestry.energy.gadgets.EngineBronze; -public class ContainerEngineBronze extends ContainerLiquidTanks { - - protected final EngineBronze engine; +public class ContainerEngineBronze extends ContainerLiquidTanks { public ContainerEngineBronze(InventoryPlayer player, EngineBronze engine) { - super(engine); - - this.engine = engine; + super(engine, player, 8, 84); this.addSlotToContainer(new SlotFiltered(engine, EngineBronze.SLOT_CAN, 143, 40)); - - int i; - for (i = 0; i < 3; ++i) { - for (int var4 = 0; var4 < 9; ++var4) { - this.addSlotToContainer(new Slot(player, var4 + i * 9 + 9, 8 + var4 * 18, 84 + i * 18)); - } - } - - for (i = 0; i < 9; ++i) { - this.addSlotToContainer(new Slot(player, i, 8 + i * 18, 142)); - } - } } diff --git a/src/main/java/forestry/energy/gui/ContainerEngineCopper.java b/src/main/java/forestry/energy/gui/ContainerEngineCopper.java index cf4e91774..4d7442b55 100755 --- a/src/main/java/forestry/energy/gui/ContainerEngineCopper.java +++ b/src/main/java/forestry/energy/gui/ContainerEngineCopper.java @@ -12,21 +12,16 @@ package forestry.energy.gui; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.Slot; -import forestry.core.gui.ContainerForestry; +import forestry.core.gui.ContainerTile; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; import forestry.energy.gadgets.EngineCopper; -public class ContainerEngineCopper extends ContainerForestry { - - protected final EngineCopper engine; +public class ContainerEngineCopper extends ContainerTile { public ContainerEngineCopper(InventoryPlayer player, EngineCopper tile) { - super(tile); - - this.engine = tile; + super(tile, player, 8, 84); this.addSlotToContainer(new SlotFiltered(tile, 0, 44, 46)); @@ -34,23 +29,12 @@ public class ContainerEngineCopper extends ContainerForestry { this.addSlotToContainer(new SlotOutput(tile, 2, 98, 53)); this.addSlotToContainer(new SlotOutput(tile, 3, 116, 35)); this.addSlotToContainer(new SlotOutput(tile, 4, 116, 53)); - - for (int i = 0; i < 3; ++i) { - for (int j = 0; j < 9; ++j) { - this.addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); - } - } - - for (int i = 0; i < 9; ++i) { - this.addSlotToContainer(new Slot(player, i, 8 + i * 18, 142)); - } - } @Override public void updateProgressBar(int i, int j) { - if (engine != null) { - engine.getGUINetworkData(i, j); + if (tile != null) { + tile.getGUINetworkData(i, j); } } @@ -59,8 +43,7 @@ public class ContainerEngineCopper extends ContainerForestry { super.detectAndSendChanges(); for (Object crafter : crafters) { - engine.sendGUINetworkData(this, (ICrafting) crafter); + tile.sendGUINetworkData(this, (ICrafting) crafter); } } - } diff --git a/src/main/java/forestry/energy/gui/ContainerEngineTin.java b/src/main/java/forestry/energy/gui/ContainerEngineTin.java index cf9a746c6..4861efc56 100755 --- a/src/main/java/forestry/energy/gui/ContainerEngineTin.java +++ b/src/main/java/forestry/energy/gui/ContainerEngineTin.java @@ -12,33 +12,17 @@ package forestry.energy.gui; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.Slot; import forestry.core.gui.ContainerSocketed; import forestry.core.gui.slots.SlotFiltered; import forestry.energy.gadgets.EngineTin; -public class ContainerEngineTin extends ContainerSocketed { - - protected final EngineTin tile; +public class ContainerEngineTin extends ContainerSocketed { public ContainerEngineTin(InventoryPlayer player, EngineTin tile) { - super(tile, tile); - - this.tile = tile; + super(tile, player, 8, 84); this.addSlotToContainer(new SlotFiltered(tile, EngineTin.SLOT_BATTERY, 84, 53)); - - int i; - for (i = 0; i < 3; ++i) { - for (int j = 0; j < 9; ++j) { - this.addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); - } - } - - for (i = 0; i < 9; ++i) { - this.addSlotToContainer(new Slot(player, i, 8 + i * 18, 142)); - } } @Override diff --git a/src/main/java/forestry/energy/gui/ContainerGenerator.java b/src/main/java/forestry/energy/gui/ContainerGenerator.java index c2decf0b7..451e4cbd3 100755 --- a/src/main/java/forestry/energy/gui/ContainerGenerator.java +++ b/src/main/java/forestry/energy/gui/ContainerGenerator.java @@ -11,32 +11,16 @@ package forestry.energy.gui; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; import forestry.core.gui.ContainerLiquidTanks; import forestry.core.gui.slots.SlotFiltered; import forestry.energy.gadgets.MachineGenerator; -public class ContainerGenerator extends ContainerLiquidTanks { - - protected final MachineGenerator tile; +public class ContainerGenerator extends ContainerLiquidTanks { public ContainerGenerator(InventoryPlayer player, MachineGenerator tile) { - super(tile); - - this.tile = tile; + super(tile, player, 8, 84); this.addSlotToContainer(new SlotFiltered(tile, MachineGenerator.SLOT_CAN, 22, 38)); - - for (int i = 0; i < 3; ++i) { - for (int var4 = 0; var4 < 9; ++var4) { - this.addSlotToContainer(new Slot(player, var4 + i * 9 + 9, 8 + var4 * 18, 84 + i * 18)); - } - } - - for (int i = 0; i < 9; ++i) { - this.addSlotToContainer(new Slot(player, i, 8 + i * 18, 142)); - } } - } diff --git a/src/main/java/forestry/factory/gadgets/MachineCarpenter.java b/src/main/java/forestry/factory/gadgets/MachineCarpenter.java index d8f5db21a..c45ce470d 100755 --- a/src/main/java/forestry/factory/gadgets/MachineCarpenter.java +++ b/src/main/java/forestry/factory/gadgets/MachineCarpenter.java @@ -21,6 +21,7 @@ import java.util.Set; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; +import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; @@ -91,7 +92,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL return internal.getRecipeOutput(); } - public boolean matches(FluidStack resource, ItemStack item, InventoryCrafting inventorycrafting, World world) { + public boolean matches(FluidStack resource, ItemStack item, IInventory inventorycrafting, World world) { if (liquid != null) { if (resource == null || !resource.containsFluid(liquid)) { @@ -173,7 +174,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL } } - public static Recipe findMatchingRecipe(FluidStack liquid, ItemStack item, InventoryCrafting inventorycrafting, World world) { + public static Recipe findMatchingRecipe(FluidStack liquid, ItemStack item, IInventory inventorycrafting, World world) { for (Recipe recipe : recipes) { if (recipe.matches(liquid, item, inventorycrafting, world)) { return recipe; @@ -292,8 +293,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL } // Reset recipe according to contents - ContainerCarpenter container = new ContainerCarpenter(this); - setCurrentRecipe(RecipeManager.findMatchingRecipe(resourceTank.getFluid(), getBoxStack(), container.craftMatrix, worldObj)); + setCurrentRecipe(RecipeManager.findMatchingRecipe(resourceTank.getFluid(), getBoxStack(), craftingInventory, worldObj)); } public void setCurrentRecipe(@Nullable MachineCarpenter.Recipe currentRecipe) { @@ -321,8 +321,8 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL } if (currentRecipe == null) { - ContainerCarpenter container = new ContainerCarpenter(this); - setCurrentRecipe(MachineCarpenter.RecipeManager.findMatchingRecipe(resourceTank.getFluid(), getBoxStack(), container.craftMatrix, worldObj)); + Recipe recipe = MachineCarpenter.RecipeManager.findMatchingRecipe(resourceTank.getFluid(), getBoxStack(), craftingInventory, worldObj); + setCurrentRecipe(recipe); } setErrorCondition(currentRecipe == null, EnumErrorCode.NORECIPE); diff --git a/src/main/java/forestry/factory/gui/ContainerBottler.java b/src/main/java/forestry/factory/gui/ContainerBottler.java index e975147f5..b338da52e 100755 --- a/src/main/java/forestry/factory/gui/ContainerBottler.java +++ b/src/main/java/forestry/factory/gui/ContainerBottler.java @@ -11,37 +11,19 @@ package forestry.factory.gui; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; import forestry.core.gui.ContainerLiquidTanks; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; import forestry.factory.gadgets.MachineBottler; -public class ContainerBottler extends ContainerLiquidTanks { - - protected final MachineBottler tile; +public class ContainerBottler extends ContainerLiquidTanks { public ContainerBottler(InventoryPlayer player, MachineBottler tile) { - super(tile); - - this.tile = tile; + super(tile, player, 8, 84); this.addSlotToContainer(new SlotFiltered(tile, MachineBottler.SLOT_INPUT_EMPTY_CAN, 116, 19)); this.addSlotToContainer(new SlotOutput(tile, MachineBottler.SLOT_OUTPUT, 116, 55)); this.addSlotToContainer(new SlotFiltered(tile, MachineBottler.SLOT_INPUT_FULL_CAN, 26, 38)); - - int var3; - for (var3 = 0; var3 < 3; ++var3) { - for (int var4 = 0; var4 < 9; ++var4) { - this.addSlotToContainer(new Slot(player, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18)); - } - } - - for (var3 = 0; var3 < 9; ++var3) { - this.addSlotToContainer(new Slot(player, var3, 8 + var3 * 18, 142)); - } - } - } diff --git a/src/main/java/forestry/factory/gui/ContainerCarpenter.java b/src/main/java/forestry/factory/gui/ContainerCarpenter.java index f5146042d..226c624e8 100755 --- a/src/main/java/forestry/factory/gui/ContainerCarpenter.java +++ b/src/main/java/forestry/factory/gui/ContainerCarpenter.java @@ -25,19 +25,17 @@ import forestry.core.interfaces.IContainerCrafting; import forestry.core.proxy.Proxies; import forestry.factory.gadgets.MachineCarpenter; -public class ContainerCarpenter extends ContainerLiquidTanks implements IContainerCrafting { +public class ContainerCarpenter extends ContainerLiquidTanks implements IContainerCrafting { - private MachineCarpenter machine; private final IInventory craftingInventory; public final InventoryCraftingAuto craftMatrix; public final InventoryCraftResult craftResult; public ContainerCarpenter(InventoryPlayer inventoryplayer, MachineCarpenter tile) { - super(tile); + super(tile, inventoryplayer, 8, 136); - machine = tile; - machine.activeContainer = this; - craftingInventory = machine.getCraftingInventory(); + this.tile.activeContainer = this; + craftingInventory = this.tile.getCraftingInventory(); craftMatrix = new InventoryCraftingAuto(this, 3, 3); craftResult = new InventoryCraftResult(); @@ -45,16 +43,16 @@ public class ContainerCarpenter extends ContainerLiquidTanks implements IContain // Internal inventory for (int i = 0; i < 2; i++) { for (int k = 0; k < 9; k++) { - addSlotToContainer(new Slot(machine, MachineCarpenter.SLOT_INVENTORY_1 + k + i * 9, 8 + k * 18, 90 + i * 18)); + addSlotToContainer(new Slot(this.tile, MachineCarpenter.SLOT_INVENTORY_1 + k + i * 9, 8 + k * 18, 90 + i * 18)); } } // Liquid Input - this.addSlotToContainer(new SlotFiltered(machine, MachineCarpenter.SLOT_CAN_INPUT, 120, 20)); + this.addSlotToContainer(new SlotFiltered(this.tile, MachineCarpenter.SLOT_CAN_INPUT, 120, 20)); // Boxes - this.addSlotToContainer(new SlotFiltered(machine, MachineCarpenter.SLOT_BOX, 83, 20)); + this.addSlotToContainer(new SlotFiltered(this.tile, MachineCarpenter.SLOT_BOX, 83, 20)); // Product - this.addSlotToContainer(new SlotOutput(machine, MachineCarpenter.SLOT_PRODUCT, 120, 56)); + this.addSlotToContainer(new SlotOutput(this.tile, MachineCarpenter.SLOT_PRODUCT, 120, 56)); // CraftResult display addSlotToContainer(new SlotLocked(craftResult, 0, 80, 51)); @@ -66,29 +64,6 @@ public class ContainerCarpenter extends ContainerLiquidTanks implements IContain } } - // Player inventory - for (int i1 = 0; i1 < 3; i1++) { - for (int l1 = 0; l1 < 9; l1++) { - addSlotToContainer(new Slot(inventoryplayer, l1 + i1 * 9 + 9, 8 + l1 * 18, 136 + i1 * 18)); - } - } - // Player hotbar - for (int j1 = 0; j1 < 9; j1++) { - addSlotToContainer(new Slot(inventoryplayer, j1, 8 + j1 * 18, 194)); - } - - // Update crafting matrix with current contents of tileentity. - for (int i = 0; i < craftMatrix.getSizeInventory(); i++) { - craftMatrix.setInventorySlotContents(i, craftingInventory.getStackInSlot(i)); - } - } - - public ContainerCarpenter(MachineCarpenter tile) { - super(tile); - craftMatrix = new InventoryCraftingAuto(this, 3, 3); - craftResult = new InventoryCraftResult(); - craftingInventory = tile.getCraftingInventory(); - // Update crafting matrix with current contents of tileentity. for (int i = 0; i < craftMatrix.getSizeInventory(); i++) { craftMatrix.setInventorySlotContents(i, craftingInventory.getStackInSlot(i)); @@ -119,16 +94,16 @@ public class ContainerCarpenter extends ContainerLiquidTanks implements IContain } private void resetProductDisplay() { - if (machine != null) { - machine.resetProductDisplay(craftMatrix); + if (tile != null) { + tile.resetProductDisplay(craftMatrix); updateProductSlot(); } } private void updateProductSlot() { // Update crafting display - if (machine.currentRecipe != null) { - craftResult.setInventorySlotContents(0, machine.currentRecipe.getCraftingResult()); + if (tile.currentRecipe != null) { + craftResult.setInventorySlotContents(0, tile.currentRecipe.getCraftingResult()); } else { craftResult.setInventorySlotContents(0, null); } @@ -136,7 +111,7 @@ public class ContainerCarpenter extends ContainerLiquidTanks implements IContain @Override public void onContainerClosed(EntityPlayer entityplayer) { - machine.activeContainer = null; + tile.activeContainer = null; if (entityplayer == null) { return; } diff --git a/src/main/java/forestry/factory/gui/ContainerCentrifuge.java b/src/main/java/forestry/factory/gui/ContainerCentrifuge.java index 7177a08b6..bcab72064 100755 --- a/src/main/java/forestry/factory/gui/ContainerCentrifuge.java +++ b/src/main/java/forestry/factory/gui/ContainerCentrifuge.java @@ -12,21 +12,16 @@ package forestry.factory.gui; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.Slot; -import forestry.core.gui.ContainerForestry; +import forestry.core.gui.ContainerTile; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; import forestry.factory.gadgets.MachineCentrifuge; -public class ContainerCentrifuge extends ContainerForestry { - - protected final MachineCentrifuge tile; +public class ContainerCentrifuge extends ContainerTile { public ContainerCentrifuge(InventoryPlayer player, MachineCentrifuge tile) { - super(tile); - - this.tile = tile; + super(tile, player, 8, 84); // Resource this.addSlotToContainer(new SlotFiltered(tile, 0, 34, 37)); @@ -37,17 +32,6 @@ public class ContainerCentrifuge extends ContainerForestry { addSlotToContainer(new SlotOutput(tile, 1 + k + l * 3, 98 + k * 18, 19 + l * 18)); } } - - // Player inventory - for (int i1 = 0; i1 < 3; i1++) { - for (int l1 = 0; l1 < 9; l1++) { - addSlotToContainer(new Slot(player, l1 + i1 * 9 + 9, 8 + l1 * 18, 84 + i1 * 18)); - } - } - // Player hotbar - for (int j1 = 0; j1 < 9; j1++) { - addSlotToContainer(new Slot(player, j1, 8 + j1 * 18, 142)); - } } @Override diff --git a/src/main/java/forestry/factory/gui/ContainerFabricator.java b/src/main/java/forestry/factory/gui/ContainerFabricator.java index 0c6873eb6..dbdf9bbbe 100755 --- a/src/main/java/forestry/factory/gui/ContainerFabricator.java +++ b/src/main/java/forestry/factory/gui/ContainerFabricator.java @@ -21,10 +21,10 @@ import forestry.core.gui.slots.SlotOutput; import forestry.core.interfaces.IContainerCrafting; import forestry.factory.gadgets.MachineFabricator; -public class ContainerFabricator extends ContainerLiquidTanks implements IContainerCrafting { +public class ContainerFabricator extends ContainerLiquidTanks implements IContainerCrafting { public ContainerFabricator(InventoryPlayer playerInventory, MachineFabricator tile) { - super(tile); + super(tile, playerInventory, 8, 129); // Internal inventory for (int i = 0; i < 2; i++) { @@ -48,18 +48,6 @@ public class ContainerFabricator extends ContainerLiquidTanks implements IContai addSlotToContainer(new SlotCraftMatrix(this, tile.getCraftingInventory(), MachineFabricator.SLOT_CRAFTING_1 + k + l * 3, 67 + k * 18, 17 + l * 18)); } } - - // Player inventory - for (int i = 0; i < 3; i++) { - for (int k = 0; k < 9; k++) { - addSlotToContainer(new Slot(playerInventory, k + i * 9 + 9, 8 + k * 18, 129 + i * 18)); - } - } - // Player hotbar - for (int j = 0; j < 9; j++) { - addSlotToContainer(new Slot(playerInventory, j, 8 + j * 18, 187)); - } - } @Override diff --git a/src/main/java/forestry/factory/gui/ContainerFermenter.java b/src/main/java/forestry/factory/gui/ContainerFermenter.java index 552d85e5d..8387e6e61 100755 --- a/src/main/java/forestry/factory/gui/ContainerFermenter.java +++ b/src/main/java/forestry/factory/gui/ContainerFermenter.java @@ -11,38 +11,21 @@ package forestry.factory.gui; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; import forestry.core.gui.ContainerLiquidTanks; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; import forestry.factory.gadgets.MachineFermenter; -public class ContainerFermenter extends ContainerLiquidTanks { - - protected final MachineFermenter fermenter; +public class ContainerFermenter extends ContainerLiquidTanks { public ContainerFermenter(InventoryPlayer player, MachineFermenter fermenter) { - super(fermenter); - - this.fermenter = fermenter; + super(fermenter, player, 8, 84); this.addSlotToContainer(new SlotFiltered(fermenter, MachineFermenter.SLOT_RESOURCE, 85, 23)); this.addSlotToContainer(new SlotFiltered(fermenter, MachineFermenter.SLOT_FUEL, 75, 57)); this.addSlotToContainer(new SlotOutput(fermenter, MachineFermenter.SLOT_CAN_OUTPUT, 150, 58)); this.addSlotToContainer(new SlotFiltered(fermenter, MachineFermenter.SLOT_CAN_INPUT, 150, 22)); this.addSlotToContainer(new SlotFiltered(fermenter, MachineFermenter.SLOT_INPUT, 10, 40)); - - for (int i = 0; i < 3; ++i) { - for (int var4 = 0; var4 < 9; ++var4) { - this.addSlotToContainer(new Slot(player, var4 + i * 9 + 9, 8 + var4 * 18, 84 + i * 18)); - } - } - - for (int i = 0; i < 9; ++i) { - this.addSlotToContainer(new Slot(player, i, 8 + i * 18, 142)); - } - } - } diff --git a/src/main/java/forestry/factory/gui/ContainerMoistener.java b/src/main/java/forestry/factory/gui/ContainerMoistener.java index a3f03eb03..997dcbf78 100755 --- a/src/main/java/forestry/factory/gui/ContainerMoistener.java +++ b/src/main/java/forestry/factory/gui/ContainerMoistener.java @@ -12,7 +12,6 @@ package forestry.factory.gui; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; import forestry.core.gui.ContainerLiquidTanks; import forestry.core.gui.slots.SlotCraftAuto; @@ -21,14 +20,10 @@ import forestry.core.gui.slots.SlotWorking; import forestry.core.interfaces.IContainerCrafting; import forestry.factory.gadgets.MachineMoistener; -public class ContainerMoistener extends ContainerLiquidTanks implements IContainerCrafting { - - protected final MachineMoistener tile; +public class ContainerMoistener extends ContainerLiquidTanks implements IContainerCrafting { public ContainerMoistener(InventoryPlayer player, MachineMoistener tile) { - super(tile); - - this.tile = tile; + super(tile, player, 8, 8); // Stash for (int l = 0; l < 2; l++) { @@ -48,19 +43,6 @@ public class ContainerMoistener extends ContainerLiquidTanks implements IContain this.addSlotToContainer(new SlotFiltered(tile, 10, 143, 55)); // Boxes this.addSlotToContainer(new SlotCraftAuto(this, tile, 11, 143, 19)); - - // Player inventory - int var3; - for (var3 = 0; var3 < 3; ++var3) { - for (int var4 = 0; var4 < 9; ++var4) { - this.addSlotToContainer(new Slot(player, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18)); - } - } - - for (var3 = 0; var3 < 9; ++var3) { - this.addSlotToContainer(new Slot(player, var3, 8 + var3 * 18, 142)); - } - } @Override diff --git a/src/main/java/forestry/factory/gui/ContainerRaintank.java b/src/main/java/forestry/factory/gui/ContainerRaintank.java index 9d65b641f..a13bb873e 100755 --- a/src/main/java/forestry/factory/gui/ContainerRaintank.java +++ b/src/main/java/forestry/factory/gui/ContainerRaintank.java @@ -11,31 +11,18 @@ package forestry.factory.gui; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; import forestry.core.gui.ContainerLiquidTanks; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; import forestry.factory.gadgets.MachineRaintank; -public class ContainerRaintank extends ContainerLiquidTanks { +public class ContainerRaintank extends ContainerLiquidTanks { public ContainerRaintank(InventoryPlayer player, MachineRaintank tile) { - super(tile); + super(tile, player, 8, 84); this.addSlotToContainer(new SlotFiltered(tile, MachineRaintank.SLOT_RESOURCE, 116, 19)); this.addSlotToContainer(new SlotOutput(tile, MachineRaintank.SLOT_PRODUCT, 116, 55)); - - for (int i = 0; i < 3; ++i) { - for (int j = 0; j < 9; ++j) { - this.addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); - } - } - - for (int i = 0; i < 9; ++i) { - this.addSlotToContainer(new Slot(player, i, 8 + i * 18, 142)); - } - } - } diff --git a/src/main/java/forestry/factory/gui/ContainerSqueezer.java b/src/main/java/forestry/factory/gui/ContainerSqueezer.java index c477d1ce0..68c7f5a23 100755 --- a/src/main/java/forestry/factory/gui/ContainerSqueezer.java +++ b/src/main/java/forestry/factory/gui/ContainerSqueezer.java @@ -11,17 +11,16 @@ package forestry.factory.gui; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; import forestry.core.gui.ContainerLiquidTanks; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; import forestry.factory.gadgets.MachineSqueezer; -public class ContainerSqueezer extends ContainerLiquidTanks { +public class ContainerSqueezer extends ContainerLiquidTanks { public ContainerSqueezer(InventoryPlayer player, MachineSqueezer tile) { - super(tile); + super(tile, player, 8, 84); // Resource inventory for (int l = 0; l < 3; l++) { @@ -37,17 +36,5 @@ public class ContainerSqueezer extends ContainerLiquidTanks { this.addSlotToContainer(new SlotFiltered(tile, MachineSqueezer.SLOT_CAN_INPUT, 106, 55)); // Output slot this.addSlotToContainer(new SlotOutput(tile, MachineSqueezer.SLOT_CAN_OUTPUT, 140, 55)); - - // Player inventory - for (int i1 = 0; i1 < 3; i1++) { - for (int l1 = 0; l1 < 9; l1++) { - addSlotToContainer(new Slot(player, l1 + i1 * 9 + 9, 8 + l1 * 18, 84 + i1 * 18)); - } - } - // Player hotbar - for (int j1 = 0; j1 < 9; j1++) { - addSlotToContainer(new Slot(player, j1, 8 + j1 * 18, 142)); - } } - } diff --git a/src/main/java/forestry/factory/gui/ContainerStill.java b/src/main/java/forestry/factory/gui/ContainerStill.java index b58a2ad3e..ffb8a0a30 100755 --- a/src/main/java/forestry/factory/gui/ContainerStill.java +++ b/src/main/java/forestry/factory/gui/ContainerStill.java @@ -11,32 +11,19 @@ package forestry.factory.gui; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; import forestry.core.gui.ContainerLiquidTanks; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; import forestry.factory.gadgets.MachineStill; -public class ContainerStill extends ContainerLiquidTanks { +public class ContainerStill extends ContainerLiquidTanks { public ContainerStill(InventoryPlayer player, MachineStill tile) { - super(tile); + super(tile, player, 8, 84); this.addSlotToContainer(new SlotOutput(tile, MachineStill.SLOT_PRODUCT, 150, 54)); this.addSlotToContainer(new SlotFiltered(tile, MachineStill.SLOT_RESOURCE, 150, 18)); this.addSlotToContainer(new SlotFiltered(tile, MachineStill.SLOT_CAN, 10, 36)); - - for (int i = 0; i < 3; ++i) { - for (int j = 0; j < 9; ++j) { - this.addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); - } - } - - for (int i = 0; i < 9; ++i) { - this.addSlotToContainer(new Slot(player, i, 8 + i * 18, 142)); - } - } - } diff --git a/src/main/java/forestry/factory/gui/ContainerWorktable.java b/src/main/java/forestry/factory/gui/ContainerWorktable.java index f5361784f..c0bd94948 100755 --- a/src/main/java/forestry/factory/gui/ContainerWorktable.java +++ b/src/main/java/forestry/factory/gui/ContainerWorktable.java @@ -16,7 +16,7 @@ import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import forestry.core.gui.ContainerForestry; +import forestry.core.gui.ContainerTile; import forestry.core.gui.IGuiSelectable; import forestry.core.gui.slots.SlotCraftMatrix; import forestry.core.gui.slots.SlotCrafter; @@ -28,16 +28,14 @@ import forestry.core.proxy.Proxies; import forestry.core.utils.StackUtils; import forestry.factory.gadgets.TileWorktable; -public class ContainerWorktable extends ContainerForestry implements IContainerCrafting, IGuiSelectable { +public class ContainerWorktable extends ContainerTile implements IContainerCrafting, IGuiSelectable { private final EntityPlayer player; - private final TileWorktable tile; private final InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3); private long lastUpdate; public ContainerWorktable(EntityPlayer player, TileWorktable tile) { - super(tile); - this.tile = tile; + super(tile, player.inventory, 8, 136); IInventory craftingInventory = tile.getCraftingInventory(); IInventory internalInventory = tile.getInternalInventory(); @@ -59,17 +57,6 @@ public class ContainerWorktable extends ContainerForestry implements IContainerC // CraftResult display addSlotToContainer(new SlotCrafter(player, craftingInventory, tile, TileWorktable.SLOT_CRAFTING_RESULT, 77, 38)); - // Player inventory - for (int i1 = 0; i1 < 3; i1++) { - for (int l1 = 0; l1 < 9; l1++) { - addSlotToContainer(new Slot(player.inventory, l1 + i1 * 9 + 9, 8 + l1 * 18, 136 + i1 * 18)); - } - } - // Player hotbar - for (int j1 = 0; j1 < 9; j1++) { - addSlotToContainer(new Slot(player.inventory, j1, 8 + j1 * 18, 194)); - } - // Update crafting matrix with current contents of tileentity. updateMatrix(); updateRecipe(); diff --git a/src/main/java/forestry/factory/gui/InventoryCraftingAuto.java b/src/main/java/forestry/factory/gui/InventoryCraftingAuto.java index 85cacb7ed..8be0c737a 100755 --- a/src/main/java/forestry/factory/gui/InventoryCraftingAuto.java +++ b/src/main/java/forestry/factory/gui/InventoryCraftingAuto.java @@ -11,16 +11,19 @@ package forestry.factory.gui; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; +import forestry.core.interfaces.IContainerCrafting; + public class InventoryCraftingAuto extends InventoryCrafting { - private final ContainerCarpenter eventHandler; + private final IContainerCrafting eventHandler; public final ItemStack stackList[]; private final int inventoryWidth; - public InventoryCraftingAuto(ContainerCarpenter container, int i, int j) { + public InventoryCraftingAuto(T container, int i, int j) { super(container, i, j); int k = i * j; stackList = new ItemStack[k]; diff --git a/src/main/java/forestry/farming/gui/ContainerFarm.java b/src/main/java/forestry/farming/gui/ContainerFarm.java index d0fd0cc8d..176cad194 100755 --- a/src/main/java/forestry/farming/gui/ContainerFarm.java +++ b/src/main/java/forestry/farming/gui/ContainerFarm.java @@ -12,7 +12,6 @@ package forestry.farming.gui; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.Slot; import forestry.core.fluids.TankManager; import forestry.core.fluids.tanks.StandardTank; @@ -21,14 +20,10 @@ import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; import forestry.farming.gadgets.TileFarmPlain; -public class ContainerFarm extends ContainerSocketed { +public class ContainerFarm extends ContainerSocketed { - private final TileFarmPlain tile; - - public ContainerFarm(InventoryPlayer playerinventory, TileFarmPlain tile) { - super(tile, tile); - - this.tile = tile; + public ContainerFarm(InventoryPlayer playerInventory, TileFarmPlain tile) { + super(tile, playerInventory, 28, 138); // Resources for (int i = 0; i < 3; i++) { @@ -62,17 +57,6 @@ public class ContainerFarm extends ContainerSocketed { addSlotToContainer(new SlotFiltered(tile, TileFarmPlain.SLOT_FERTILIZER, 63, 95)); // Can Slot addSlotToContainer(new SlotFiltered(tile, TileFarmPlain.SLOT_CAN, 15, 95)); - - // Player inventory - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 9; j++) { - addSlotToContainer(new Slot(playerinventory, j + i * 9 + 9, 28 + j * 18, 138 + i * 18)); - } - } - // Player hotbar - for (int i = 0; i < 9; i++) { - addSlotToContainer(new Slot(playerinventory, i, 28 + i * 18, 196)); - } } @Override diff --git a/src/main/java/forestry/food/gui/ContainerInfuser.java b/src/main/java/forestry/food/gui/ContainerInfuser.java index 5a472bc76..f06eb22f6 100755 --- a/src/main/java/forestry/food/gui/ContainerInfuser.java +++ b/src/main/java/forestry/food/gui/ContainerInfuser.java @@ -12,22 +12,18 @@ package forestry.food.gui; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import forestry.core.gui.ContainerForestry; +import forestry.core.gui.ContainerItemInventory; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; import forestry.core.proxy.Proxies; import forestry.food.items.ItemInfuser.InfuserInventory; -public class ContainerInfuser extends ContainerForestry { - - private final InfuserInventory inventory; +public class ContainerInfuser extends ContainerItemInventory { public ContainerInfuser(InventoryPlayer inventoryplayer, InfuserInventory inventory) { - super(inventory); - this.inventory = inventory; + super(inventory, inventoryplayer, 8, 103); // Input this.addSlotToContainer(new SlotFiltered(inventory, 0, 152, 12)); @@ -40,17 +36,6 @@ public class ContainerInfuser extends ContainerForestry { this.addSlotToContainer(new SlotFiltered(inventory, 3, 12, 32)); this.addSlotToContainer(new SlotFiltered(inventory, 4, 12, 52)); this.addSlotToContainer(new SlotFiltered(inventory, 5, 12, 72)); - - // Player inventory - for (int i1 = 0; i1 < 3; i1++) { - for (int l1 = 0; l1 < 9; l1++) { - addSlotToContainer(new Slot(inventoryplayer, l1 + i1 * 9 + 9, 8 + l1 * 18, 103 + i1 * 18)); - } - } - // Player hotbar - for (int j1 = 0; j1 < 9; j1++) { - addSlotToContainer(new Slot(inventoryplayer, j1, 8 + j1 * 18, 161)); - } } @Override @@ -70,6 +55,5 @@ public class ContainerInfuser extends ContainerForestry { Proxies.common.dropItemPlayer(entityplayer, stack); inventory.setInventorySlotContents(i, null); } - } } diff --git a/src/main/java/forestry/food/items/ItemInfuser.java b/src/main/java/forestry/food/items/ItemInfuser.java index 1f02e3b3f..a8d766800 100755 --- a/src/main/java/forestry/food/items/ItemInfuser.java +++ b/src/main/java/forestry/food/items/ItemInfuser.java @@ -241,44 +241,45 @@ public class ItemInfuser extends ItemForestry { // / INVENTORY MANAGMENT public static class InfuserInventory extends ItemInventory { - private final short inputSlot = 0; - private final short outputSlot = 1; - private final short ingredientSlot1 = 2; - private final short ingredientSlotCount = 4; - private final EntityPlayer player; + private static final short inputSlot = 0; + private static final short outputSlot = 1; + private static final short ingredientSlot1 = 2; + private static final short ingredientSlotCount = 4; public InfuserInventory(EntityPlayer player, ItemStack itemStack) { - super(ItemInfuser.class, 6, itemStack); - this.player = player; + super(player, 6, itemStack); } private void trySeasoning() { // Need input - if (inventoryStacks[inputSlot] == null) { + ItemStack input = getStackInSlot(inputSlot); + if (input == null) { return; } // Output slot may not be occupied - if (inventoryStacks[outputSlot] != null) { + if (getStackInSlot(outputSlot) != null) { return; } // Need a valid base - if (!inventoryStacks[inputSlot].isItemEqual(ForestryItem.beverage.getItemStack())) { + if (!input.isItemEqual(ForestryItem.beverage.getItemStack())) { return; } // Create the seasoned item ItemStack[] ingredients = new ItemStack[4]; - System.arraycopy(inventoryStacks, ingredientSlot1, ingredients, 0, 4); + for (int i = 0; i < 4; i++) { + ingredients[i] = getStackInSlot(i + ingredientSlot1); + } // Only continue if there is anything to season if (!BeverageManager.infuserManager.hasMixtures(ingredients)) { return; } - ItemStack seasoned = BeverageManager.infuserManager.getSeasoned(inventoryStacks[inputSlot], ingredients); + ItemStack seasoned = BeverageManager.infuserManager.getSeasoned(input, ingredients); if (seasoned == null) { return; } @@ -289,23 +290,23 @@ public class ItemInfuser extends ItemForestry { ItemStack ghost = templ.copy(); for (int i = ingredientSlot1; i < this.getSizeInventory(); i++) { - if (inventoryStacks[i] == null) { + ItemStack ingredient = getStackInSlot(i); + if (ingredient == null) { continue; } if (ghost.stackSize <= 0) { break; } - if ((ghost.getItemDamage() >= 0 && inventoryStacks[i].isItemEqual(ghost)) - || (ghost.getItemDamage() < 0 && ghost.getItem() == inventoryStacks[i].getItem())) { + if ((ghost.getItemDamage() >= 0 && ingredient.isItemEqual(ghost)) + || (ghost.getItemDamage() < 0 && ghost.getItem() == ingredient.getItem())) { ItemStack removed = decrStackSize(i, 1); ghost.stackSize -= removed.stackSize; } } } decrStackSize(inputSlot, 1); - inventoryStacks[outputSlot] = seasoned; - + setInventorySlotContents(outputSlot, seasoned); } @Override diff --git a/src/main/java/forestry/lepidopterology/items/ItemFlutterlyzer.java b/src/main/java/forestry/lepidopterology/items/ItemFlutterlyzer.java index 1b098a71a..75e3cabf2 100755 --- a/src/main/java/forestry/lepidopterology/items/ItemFlutterlyzer.java +++ b/src/main/java/forestry/lepidopterology/items/ItemFlutterlyzer.java @@ -31,8 +31,7 @@ public class ItemFlutterlyzer extends ItemInventoried { public static class FlutterlyzerInventory extends AlyzerInventory implements IHintSource { public FlutterlyzerInventory(EntityPlayer player, ItemStack itemStack) { - super(ItemFlutterlyzer.class, 7, itemStack); - this.player = player; + super(player, 7, itemStack); } @Override @@ -41,13 +40,6 @@ public class ItemFlutterlyzer extends ItemInventoried { } private void tryAnalyze() { - - // Analyzed slot occupied, abort - if (inventoryStacks[SLOT_ANALYZE_1] != null || inventoryStacks[SLOT_ANALYZE_2] != null || inventoryStacks[SLOT_ANALYZE_3] != null - || inventoryStacks[SLOT_ANALYZE_4] != null || inventoryStacks[SLOT_ANALYZE_5] != null) { - return; - } - // Source slot to analyze empty if (getStackInSlot(SLOT_SPECIMEN) == null) { return; diff --git a/src/main/java/forestry/mail/GuiHandlerMail.java b/src/main/java/forestry/mail/GuiHandlerMail.java index 248fdb3a4..d1103ed3a 100755 --- a/src/main/java/forestry/mail/GuiHandlerMail.java +++ b/src/main/java/forestry/mail/GuiHandlerMail.java @@ -64,7 +64,7 @@ public class GuiHandlerMail extends GuiHandlerBase { } if (equipped.getItem() instanceof ItemLetter) { - return new GuiLetter(player, new LetterInventory(equipped)); + return new GuiLetter(player, new LetterInventory(player, equipped)); } else { return null; } @@ -110,7 +110,7 @@ public class GuiHandlerMail extends GuiHandlerBase { } if (equipped.getItem() instanceof ItemLetter) { - return new ContainerLetter(player, new LetterInventory(equipped)); + return new ContainerLetter(player, new LetterInventory(player, equipped)); } else { return null; } diff --git a/src/main/java/forestry/mail/Letter.java b/src/main/java/forestry/mail/Letter.java index 5f7a07ed7..983962a09 100755 --- a/src/main/java/forestry/mail/Letter.java +++ b/src/main/java/forestry/mail/Letter.java @@ -237,15 +237,15 @@ public class Letter implements ILetter, INBTTagable { @Override public String getRecipientString() { - String recipientString = ""; + StringBuilder recipientString = new StringBuilder(); for (IMailAddress address : recipient) { if (recipientString.length() > 0) { - recipientString += ", "; + recipientString.append(", "); } - recipientString += address.getName(); + recipientString.append(address.getName()); } - return recipientString; + return recipientString.toString(); } @Override diff --git a/src/main/java/forestry/mail/PacketHandlerMail.java b/src/main/java/forestry/mail/PacketHandlerMail.java index 7d70b987c..ea5140853 100755 --- a/src/main/java/forestry/mail/PacketHandlerMail.java +++ b/src/main/java/forestry/mail/PacketHandlerMail.java @@ -23,9 +23,9 @@ import forestry.core.proxy.Proxies; import forestry.mail.gui.ContainerCatalogue; import forestry.mail.gui.ContainerLetter; import forestry.mail.gui.ContainerTradeName; +import forestry.mail.gui.GuiMailboxInfo; import forestry.mail.network.PacketLetterInfo; import forestry.mail.network.PacketPOBoxInfo; -import forestry.plugins.PluginMail; public class PacketHandlerMail implements IPacketHandler { @@ -79,8 +79,7 @@ public class PacketHandlerMail implements IPacketHandler { } private void onPOBoxInfo(PacketPOBoxInfo packet) { - MailAddress address = new MailAddress(Proxies.common.getClientInstance().thePlayer.getGameProfile()); - PluginMail.proxy.setPOBoxInfo(Proxies.common.getRenderWorld(), address, packet.poboxInfo); + GuiMailboxInfo.instance.setPOBoxInfo(packet.poboxInfo); } private void onAddressSet(EntityPlayer player, PacketUpdate packet) { diff --git a/src/main/java/forestry/mail/PostRegistry.java b/src/main/java/forestry/mail/PostRegistry.java index 54e0239cc..6fc66c454 100755 --- a/src/main/java/forestry/mail/PostRegistry.java +++ b/src/main/java/forestry/mail/PostRegistry.java @@ -14,6 +14,7 @@ import java.io.File; import java.util.HashMap; import java.util.Map; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; @@ -29,8 +30,10 @@ import forestry.api.mail.IPostalCarrier; import forestry.api.mail.ITradeStation; import forestry.api.mail.PostManager; import forestry.core.config.ForestryItem; +import forestry.core.network.PacketIds; +import forestry.core.proxy.Proxies; import forestry.mail.items.ItemLetter; -import forestry.plugins.PluginMail; +import forestry.mail.network.PacketPOBoxInfo; public class PostRegistry implements IPostRegistry { @@ -69,7 +72,11 @@ public class PostRegistry implements IPostRegistry { world.setItemData(POBox.SAVE_NAME + address, pobox); pobox.markDirty(); cachedPOBoxes.put(address, pobox); - PluginMail.proxy.setPOBoxInfo(world, address, pobox.getPOBoxInfo()); + + EntityPlayer player = Proxies.common.getPlayer(world, address.getPlayerProfile()); + if (player != null) { + Proxies.net.sendToPlayer(new PacketPOBoxInfo(PacketIds.POBOX_INFO, pobox.getPOBoxInfo()), player); + } } return pobox; @@ -206,10 +213,10 @@ public class PostRegistry implements IPostRegistry { NBTTagCompound nbttagcompound = new NBTTagCompound(); letter.writeToNBT(nbttagcompound); - ItemStack mailstack = ForestryItem.letters.getItemStack(1, ItemLetter.encodeMeta(1, ItemLetter.getType(letter))); - mailstack.setTagCompound(nbttagcompound); + ItemStack letterStack = ItemLetter.createStampedLetterStack(letter); + letterStack.setTagCompound(nbttagcompound); - return mailstack; + return letterStack; } @Override diff --git a/src/main/java/forestry/mail/PostalCarrier.java b/src/main/java/forestry/mail/PostalCarrier.java index c2835a431..19a3848e8 100755 --- a/src/main/java/forestry/mail/PostalCarrier.java +++ b/src/main/java/forestry/mail/PostalCarrier.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.mail; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.world.World; @@ -24,9 +25,11 @@ import forestry.api.mail.IPostalCarrier; import forestry.api.mail.IPostalState; import forestry.api.mail.ITradeStation; import forestry.api.mail.PostManager; +import forestry.core.network.PacketIds; +import forestry.core.proxy.Proxies; import forestry.core.render.TextureManager; import forestry.core.utils.StringUtil; -import forestry.plugins.PluginMail; +import forestry.mail.network.PacketPOBoxInfo; public class PostalCarrier implements IPostalCarrier { @@ -63,7 +66,7 @@ public class PostalCarrier implements IPostalCarrier { } } - private IPostalState handleTradeLetter(World world, IPostOffice office, IMailAddress recipient, ItemStack letterstack, boolean doLodge) { + private static IPostalState handleTradeLetter(World world, IPostOffice office, IMailAddress recipient, ItemStack letterstack, boolean doLodge) { ITradeStation trade = PostManager.postRegistry.getTradeStation(world, recipient); if (trade == null) { return EnumDeliveryState.NO_MAILBOX; @@ -72,7 +75,7 @@ public class PostalCarrier implements IPostalCarrier { return trade.handleLetter(world, recipient, letterstack, doLodge); } - private EnumDeliveryState storeInPOBox(World world, IPostOffice office, IMailAddress recipient, ItemStack letterstack, boolean doLodge) { + private static EnumDeliveryState storeInPOBox(World world, IPostOffice office, IMailAddress recipient, ItemStack letterstack, boolean doLodge) { POBox pobox = PostRegistry.getPOBox(world, recipient); if (pobox == null) { @@ -82,7 +85,10 @@ public class PostalCarrier implements IPostalCarrier { if (!pobox.storeLetter(letterstack.copy())) { return EnumDeliveryState.MAILBOX_FULL; } else { - PluginMail.proxy.setPOBoxInfo(world, recipient, pobox.getPOBoxInfo()); + EntityPlayer player = Proxies.common.getPlayer(world, recipient.getPlayerProfile()); + if (player != null) { + Proxies.net.sendToPlayer(new PacketPOBoxInfo(PacketIds.POBOX_INFO, pobox.getPOBoxInfo()), player); + } } return EnumDeliveryState.OK; diff --git a/src/main/java/forestry/mail/SaveEventHandlerMail.java b/src/main/java/forestry/mail/SaveEventHandlerMail.java index 6c6020034..c29c9f6d8 100755 --- a/src/main/java/forestry/mail/SaveEventHandlerMail.java +++ b/src/main/java/forestry/mail/SaveEventHandlerMail.java @@ -13,7 +13,6 @@ package forestry.mail; import net.minecraft.world.World; import forestry.core.interfaces.ISaveEventHandler; -import forestry.plugins.PluginMail; public class SaveEventHandlerMail implements ISaveEventHandler { @@ -22,7 +21,6 @@ public class SaveEventHandlerMail implements ISaveEventHandler { PostRegistry.cachedPostOffice = null; PostRegistry.cachedPOBoxes.clear(); PostRegistry.cachedTradeStations.clear(); - PluginMail.proxy.clearMailboxInfo(); } @Override diff --git a/src/main/java/forestry/mail/TickHandlerMailClient.java b/src/main/java/forestry/mail/TickHandlerMailClient.java index cca408238..0eb5f5779 100755 --- a/src/main/java/forestry/mail/TickHandlerMailClient.java +++ b/src/main/java/forestry/mail/TickHandlerMailClient.java @@ -15,8 +15,10 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent.Phase; import cpw.mods.fml.common.gameevent.TickEvent.RenderTickEvent; +import forestry.core.network.ForestryPacket; +import forestry.core.network.PacketIds; +import forestry.core.proxy.Proxies; import forestry.mail.gui.GuiMailboxInfo; -import forestry.plugins.PluginMail; public class TickHandlerMailClient { public TickHandlerMailClient() { @@ -29,10 +31,10 @@ public class TickHandlerMailClient { return; } - if (GuiMailboxInfo.instance != null) { + if (GuiMailboxInfo.instance.hasPOBoxInfo()) { GuiMailboxInfo.instance.render(0, 0); } else { - PluginMail.proxy.resetMailboxInfo(); + Proxies.net.sendToServer(new ForestryPacket(PacketIds.POBOX_INFO_REQUEST)); } } } diff --git a/src/main/java/forestry/mail/TradeStation.java b/src/main/java/forestry/mail/TradeStation.java index 8b4ff785b..1da6c9303 100755 --- a/src/main/java/forestry/mail/TradeStation.java +++ b/src/main/java/forestry/mail/TradeStation.java @@ -47,7 +47,6 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve super(size, name); } - @Override public int[] getAccessibleSlotsFromSide(int side) { @@ -295,7 +294,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve NBTTagCompound nbttagcompound = new NBTTagCompound(); mail.writeToNBT(nbttagcompound); - ItemStack mailstack = ForestryItem.letters.getItemStack(1, ItemLetter.encodeMeta(1, ItemLetter.getType(mail))); + ItemStack mailstack = ItemLetter.createStampedLetterStack(mail); mailstack.setTagCompound(nbttagcompound); IPostalState responseState = PostManager.postRegistry.getPostOffice(world).lodgeLetter(world, mailstack, doLodge); @@ -329,7 +328,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve confirm.addStamps(ForestryItem.stamps.getItemStack(1, EnumPostage.P_1.ordinal() - 1)); confirm.writeToNBT(nbttagcompound); - ItemStack confirmstack = ForestryItem.letters.getItemStack(1, ItemLetter.encodeMeta(1, ItemLetter.getType(confirm))); + ItemStack confirmstack = ItemLetter.createStampedLetterStack(confirm); confirmstack.setTagCompound(nbttagcompound); PostManager.postRegistry.getPostOffice(world).lodgeLetter(world, confirmstack, doLodge); diff --git a/src/main/java/forestry/mail/gadgets/MachineTrader.java b/src/main/java/forestry/mail/gadgets/MachineTrader.java index 934bf1dbd..7bfeb8848 100755 --- a/src/main/java/forestry/mail/gadgets/MachineTrader.java +++ b/src/main/java/forestry/mail/gadgets/MachineTrader.java @@ -12,7 +12,6 @@ package forestry.mail.gadgets; import java.util.Collection; import java.util.LinkedList; -import java.util.Set; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; @@ -26,7 +25,6 @@ import net.minecraftforge.common.util.ForgeDirection; import cpw.mods.fml.common.Optional; import forestry.api.core.ForestryAPI; -import forestry.api.core.IErrorState; import forestry.api.mail.IMailAddress; import forestry.api.mail.IStamps; import forestry.api.mail.PostManager; diff --git a/src/main/java/forestry/mail/gui/ContainerLetter.java b/src/main/java/forestry/mail/gui/ContainerLetter.java index f4809ce61..b09624935 100755 --- a/src/main/java/forestry/mail/gui/ContainerLetter.java +++ b/src/main/java/forestry/mail/gui/ContainerLetter.java @@ -35,7 +35,6 @@ import forestry.core.network.PacketPayload; import forestry.core.network.PacketUpdate; import forestry.core.proxy.Proxies; import forestry.mail.Letter; -import forestry.mail.items.ItemLetter; import forestry.mail.items.ItemLetter.LetterInventory; import forestry.mail.network.PacketLetterInfo; @@ -45,13 +44,7 @@ public class ContainerLetter extends ContainerItemInventory { private TradeStationInfo tradeInfo = null; public ContainerLetter(EntityPlayer player, LetterInventory inventory) { - super(inventory); - - // Rip open delivered mails - if (Proxies.common.isSimulating(player.worldObj) && inventory.getLetter().isProcessed() && inventory.parent != null - && ItemLetter.getState(inventory.parent.getItemDamage()) < 2) { - inventory.parent.setItemDamage(ItemLetter.encodeMeta(2, ItemLetter.getSize(inventory.parent.getItemDamage()))); - } + super(inventory, player.inventory, 17, 145); // Init slots @@ -67,16 +60,12 @@ public class ContainerLetter extends ContainerItemInventory { } } - // Player inventory - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 9; j++) { - addSecuredSlot(player.inventory, j + i * 9 + 9, 17 + j * 18, 145 + i * 18); + // Rip open delivered mails + if (Proxies.common.isSimulating(player.worldObj)) { + if (inventory.getLetter().isProcessed()) { + inventory.onLetterOpened(); } } - // Player hotbar - for (int i = 0; i < 9; i++) { - addSecuredSlot(player.inventory, i, 17 + i * 18, 203); - } // Set recipient type ILetter letter = inventory.getLetter(); @@ -99,6 +88,8 @@ public class ContainerLetter extends ContainerItemInventory { } } + inventory.onContainerClosed(); + super.onContainerClosed(entityplayer); } @@ -200,7 +191,8 @@ public class ContainerLetter extends ContainerItemInventory { } public void handleSetText(PacketUpdate packet) { - getLetter().setText(packet.payload.stringPayload[0]); + String text = packet.payload.stringPayload[0]; + getLetter().setText(text); } /* Managing Trade info */ diff --git a/src/main/java/forestry/mail/gui/ContainerMailbox.java b/src/main/java/forestry/mail/gui/ContainerMailbox.java index 68b60fbbb..397b971c6 100755 --- a/src/main/java/forestry/mail/gui/ContainerMailbox.java +++ b/src/main/java/forestry/mail/gui/ContainerMailbox.java @@ -13,33 +13,29 @@ package forestry.mail.gui; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import forestry.api.mail.IMailAddress; -import forestry.api.mail.PostManager; -import forestry.core.gui.ContainerForestry; +import forestry.core.gui.ContainerTile; import forestry.core.gui.slots.SlotOutput; +import forestry.core.network.PacketIds; import forestry.core.proxy.Proxies; +import forestry.core.utils.GuiUtil; import forestry.mail.POBox; +import forestry.mail.POBoxInfo; import forestry.mail.gadgets.MachineMailbox; -import forestry.plugins.PluginMail; +import forestry.mail.network.PacketPOBoxInfo; -public class ContainerMailbox extends ContainerForestry { +public class ContainerMailbox extends ContainerTile { public static final short SLOT_LETTERS = 0; public static final short SLOT_LETTERS_COUNT = 7 * 12; - private final MachineMailbox mailbox; private final POBox mailInventory; public ContainerMailbox(InventoryPlayer player, MachineMailbox tile) { - super(tile); + super(tile, player, 35, 145); IInventory inventory = tile.getOrCreateMailInventory(player.player.worldObj, player.player.getGameProfile()); - // Mailbox contents - this.mailbox = tile; - if (inventory instanceof POBox) { this.mailInventory = (POBox) inventory; } else { @@ -51,28 +47,16 @@ public class ContainerMailbox extends ContainerForestry { addSlotToContainer(new SlotOutput(inventory, j + i * 9, 8 + j * 18, 8 + i * 18)); } } - - // Player inventory - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 9; j++) { - addSlotToContainer(new Slot(player, j + i * 9 + 9, 35 + j * 18, 145 + i * 18)); - } - } - // Player hotbar - for (int i = 0; i < 9; i++) { - addSlotToContainer(new Slot(player, i, 35 + i * 18, 203)); - } - } @Override public ItemStack slotClick(int slotIndex, int button, int par3, EntityPlayer player) { ItemStack stack = super.slotClick(slotIndex, button, par3, player); - if (slotIndex >= SLOT_LETTERS && slotIndex < SLOT_LETTERS + SLOT_LETTERS_COUNT) { + if (GuiUtil.isIndexInRange(slotIndex, SLOT_LETTERS, SLOT_LETTERS_COUNT)) { if (Proxies.common.isSimulating(player.worldObj) && mailInventory != null) { - IMailAddress address = PostManager.postRegistry.getMailAddress(player.getGameProfile()); - PluginMail.proxy.setPOBoxInfo(mailbox.getWorldObj(), address, mailInventory.getPOBoxInfo()); + POBoxInfo info = mailInventory.getPOBoxInfo(); + Proxies.net.sendToPlayer(new PacketPOBoxInfo(PacketIds.POBOX_INFO, info), player); } } diff --git a/src/main/java/forestry/mail/gui/ContainerPhilatelist.java b/src/main/java/forestry/mail/gui/ContainerPhilatelist.java index 6c3764a2c..a53fc1ecf 100755 --- a/src/main/java/forestry/mail/gui/ContainerPhilatelist.java +++ b/src/main/java/forestry/mail/gui/ContainerPhilatelist.java @@ -11,17 +11,16 @@ package forestry.mail.gui; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; -import forestry.core.gui.ContainerForestry; +import forestry.core.gui.ContainerTile; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; import forestry.mail.gadgets.MachinePhilatelist; -public class ContainerPhilatelist extends ContainerForestry { +public class ContainerPhilatelist extends ContainerTile { public ContainerPhilatelist(InventoryPlayer player, MachinePhilatelist tile) { - super(tile); + super(tile, player, 8, 111); // Filter addSlotToContainer(new SlotFiltered(tile, MachinePhilatelist.SLOT_FILTER, 80, 19)); @@ -32,18 +31,5 @@ public class ContainerPhilatelist extends ContainerForestry { addSlotToContainer(new SlotOutput(tile, j + i * 9 + MachinePhilatelist.SLOT_BUFFER_1, 8 + j * 18, 46 + i * 18)); } } - - // Player inventory - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 9; j++) { - addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, 111 + i * 18)); - } - } - // Player hotbar - for (int i = 0; i < 9; i++) { - addSlotToContainer(new Slot(player, i, 8 + i * 18, 169)); - } - } - } diff --git a/src/main/java/forestry/mail/gui/ContainerTrader.java b/src/main/java/forestry/mail/gui/ContainerTrader.java index 85758f637..6521794d4 100755 --- a/src/main/java/forestry/mail/gui/ContainerTrader.java +++ b/src/main/java/forestry/mail/gui/ContainerTrader.java @@ -11,46 +11,41 @@ package forestry.mail.gui; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; import forestry.api.mail.IMailAddress; -import forestry.core.gui.ContainerForestry; +import forestry.core.gui.ContainerTile; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotForestry; import forestry.core.gui.slots.SlotOutput; import forestry.mail.TradeStation; import forestry.mail.gadgets.MachineTrader; -public class ContainerTrader extends ContainerForestry { - - private final MachineTrader machine; +public class ContainerTrader extends ContainerTile { public ContainerTrader(InventoryPlayer player, MachineTrader tile) { - super(tile); - - machine = tile; + super(tile, player, 33, 138); // Trade good - this.addSlotToContainer(new SlotForestry(machine, TradeStation.SLOT_TRADEGOOD, 78, 109).blockShift()); + this.addSlotToContainer(new SlotForestry(this.tile, TradeStation.SLOT_TRADEGOOD, 78, 109).blockShift()); // Exchange for (int row = 0; row < 2; row++) { for (int col = 0; col < 2; col++) { - addSlotToContainer(new SlotForestry(machine, TradeStation.SLOT_EXCHANGE_1 + col + row * 2, 69 + col * 18, 55 + row * 18).blockShift()); + addSlotToContainer(new SlotForestry(this.tile, TradeStation.SLOT_EXCHANGE_1 + col + row * 2, 69 + col * 18, 55 + row * 18).blockShift()); } } // Stamps for (int row = 0; row < 2; row++) { for (int col = 0; col < 2; col++) { - addSlotToContainer(new SlotFiltered(machine, TradeStation.SLOT_STAMPS_1 + col + row * 2, 15 + col * 18, 37 + row * 18)); + addSlotToContainer(new SlotFiltered(this.tile, TradeStation.SLOT_STAMPS_1 + col + row * 2, 15 + col * 18, 37 + row * 18)); } } // Letters for (int row = 0; row < 3; row++) { for (int col = 0; col < 2; col++) { - addSlotToContainer(new SlotFiltered(machine, TradeStation.SLOT_LETTERS_1 + col + row * 2, 15 + col * 18, 73 + row * 18)); + addSlotToContainer(new SlotFiltered(this.tile, TradeStation.SLOT_LETTERS_1 + col + row * 2, 15 + col * 18, 73 + row * 18)); } } @@ -58,30 +53,19 @@ public class ContainerTrader extends ContainerForestry { final int bufCols = 5; for (int row = 0; row < 3; row++) { for (int col = 0; col < bufCols; col++) { - addSlotToContainer(new SlotOutput(machine, TradeStation.SLOT_RECEIVE_BUFFER + col + row * bufCols, 123 + col * 18, 19 + row * 18)); + addSlotToContainer(new SlotOutput(this.tile, TradeStation.SLOT_RECEIVE_BUFFER + col + row * bufCols, 123 + col * 18, 19 + row * 18)); } } for (int row = 0; row < 2; row++) { for (int col = 0; col < bufCols; col++) { - addSlotToContainer(new SlotFiltered(machine, TradeStation.SLOT_SEND_BUFFER + col + row * bufCols, 123 + col * 18, (19 + (18 * 4)) + row * 18)); + addSlotToContainer(new SlotFiltered(this.tile, TradeStation.SLOT_SEND_BUFFER + col + row * bufCols, 123 + col * 18, (19 + (18 * 4)) + row * 18)); } } - - // Player inventory - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 9; j++) { - addSlotToContainer(new Slot(player, j + i * 9 + 9, 33 + j * 18, 138 + i * 18)); - } - } - // Player hotbar - for (int i = 0; i < 9; i++) { - addSlotToContainer(new Slot(player, i, 33 + i * 18, 196)); - } } public IMailAddress getAddress() { - return machine.getAddress(); + return tile.getAddress(); } } diff --git a/src/main/java/forestry/mail/gui/GuiMailboxInfo.java b/src/main/java/forestry/mail/gui/GuiMailboxInfo.java index 3ae5ebf4e..9d4877543 100755 --- a/src/main/java/forestry/mail/gui/GuiMailboxInfo.java +++ b/src/main/java/forestry/mail/gui/GuiMailboxInfo.java @@ -24,13 +24,13 @@ import forestry.mail.POBoxInfo; public class GuiMailboxInfo extends Gui { - public static GuiMailboxInfo instance; + public final static GuiMailboxInfo instance = new GuiMailboxInfo(); private final FontRenderer fontRendererObj; private POBoxInfo poInfo; private final ResourceLocation textureAlert = new ForestryResource(Defaults.TEXTURE_PATH_GUI + "/mailalert.png"); - public GuiMailboxInfo() { + private GuiMailboxInfo() { fontRendererObj = Proxies.common.getClientInstance().fontRenderer; } @@ -56,8 +56,7 @@ public class GuiMailboxInfo extends Gui { this.drawTexturedModalRect(x, y, 0, 0, 98, 17); - fontRendererObj - .drawString(Integer.toString(poInfo.playerLetters), x + 27 + getCenteredOffset(Integer.toString(poInfo.playerLetters), 22), y + 5, 0xffffff); + fontRendererObj.drawString(Integer.toString(poInfo.playerLetters), x + 27 + getCenteredOffset(Integer.toString(poInfo.playerLetters), 22), y + 5, 0xffffff); fontRendererObj.drawString(Integer.toString(poInfo.tradeLetters), x + 75 + getCenteredOffset(Integer.toString(poInfo.tradeLetters), 22), y + 5, 0xffffff); GL11.glDisable(32826); @@ -69,6 +68,10 @@ public class GuiMailboxInfo extends Gui { return (xWidth - fontRendererObj.getStringWidth(string)) / 2; } + public boolean hasPOBoxInfo() { + return poInfo != null; + } + public void setPOBoxInfo(POBoxInfo info) { boolean playJingle = false; diff --git a/src/main/java/forestry/mail/items/ItemLetter.java b/src/main/java/forestry/mail/items/ItemLetter.java index 6ebaa748f..8c7ffe179 100755 --- a/src/main/java/forestry/mail/items/ItemLetter.java +++ b/src/main/java/forestry/mail/items/ItemLetter.java @@ -45,46 +45,67 @@ import forestry.mail.Letter; public class ItemLetter extends ItemInventoried { + private enum LetterState { + FRESH, STAMPED, OPENED, EMPTIED + } + + private enum LetterSize { + EMPTY, SMALL, BIG + } + public static class LetterInventory extends ItemInventory implements IErrorSource, IHintSource { + private ILetter letter; - ILetter letter; - - public LetterInventory(ItemStack itemstack) { - super(ItemLetter.class, 0, itemstack); - - // Set an uid to identify the itemstack on SMP - setUID(true); - - readFromNBT(itemstack.getTagCompound()); + public LetterInventory(EntityPlayer player, ItemStack itemstack) { + super(player, 0, itemstack); } public ILetter getLetter() { - return this.letter; + return letter; } - @Override - public void onGuiSaved(EntityPlayer player) { - super.onGuiSaved(player); - + public void onContainerClosed() { + ItemStack parent = getParent(); if (parent == null) { return; } - // Already delivered mails can't be made usable anymore. - int state = getState(parent.getItemDamage()); - if (state >= 2) { - if (state == 2 && letter.countAttachments() <= 0) { - parent.setItemDamage(encodeMeta(3, getSize(parent.getItemDamage()))); - } - return; + LetterState state = getState(parent.getItemDamage()); + LetterSize size = getSize(parent.getItemDamage()); + + switch (state) { + case OPENED: + if (letter.countAttachments() <= 0) { + int meta = encodeMeta(LetterState.EMPTIED, size); + parent.setItemDamage(meta); + } + break; + case FRESH: + case STAMPED: + if (letter.isMailable() && letter.isPostPaid()) { + int meta = encodeMeta(LetterState.STAMPED, size); + parent.setItemDamage(meta); + } else { + int meta = encodeMeta(LetterState.FRESH, size); + parent.setItemDamage(meta); + } + break; + case EMPTIED: } - int type = getType(letter); + letter.writeToNBT(parent.getTagCompound()); + } - if (parent != null && letter.isMailable() && letter.isPostPaid()) { - parent.setItemDamage(encodeMeta(1, type)); - } else { - parent.setItemDamage(encodeMeta(0, type)); + public void onLetterOpened() { + ItemStack parent = getParent(); + if (parent != null) { + int oldMeta = parent.getItemDamage(); + LetterState state = getState(oldMeta); + if (state == LetterState.FRESH || state == LetterState.STAMPED) { + LetterSize size = ItemLetter.getSize(oldMeta); + int newMeta = ItemLetter.encodeMeta(LetterState.OPENED, size); + parent.setItemDamage(newMeta); + } } } @@ -98,19 +119,17 @@ public class ItemLetter extends ItemInventoried { letter = new Letter(nbttagcompound); } - @Override - public void writeToNBT(NBTTagCompound nbttagcompound) { - letter.writeToNBT(nbttagcompound); - } - @Override public ItemStack decrStackSize(int i, int j) { - return letter.decrStackSize(i, j); + ItemStack result = letter.decrStackSize(i, j); + letter.writeToNBT(getParent().getTagCompound()); + return result; } @Override public void setInventorySlotContents(int i, ItemStack itemstack) { letter.setInventorySlotContents(i, itemstack); + letter.writeToNBT(getParent().getTagCompound()); } @Override @@ -191,8 +210,10 @@ public class ItemLetter extends ItemInventoried { } - public ItemLetter() { - super(); + public static ItemStack createStampedLetterStack(ILetter letter) { + LetterSize size = getSize(letter); + int meta = encodeMeta(LetterState.STAMPED, size); + return ForestryItem.letters.getItemStack(1, meta); } @Override @@ -227,31 +248,44 @@ public class ItemLetter extends ItemInventoried { icons[i][2] = TextureManager.getInstance().registerTex(register, "mail/letter." + i + ".opened"); icons[i][3] = TextureManager.getInstance().registerTex(register, "mail/letter." + i + ".emptied"); } - } @SideOnly(Side.CLIENT) @Override public IIcon getIconFromDamage(int damage) { - int state = getState(damage); - int size = getSize(damage); + LetterState state = getState(damage); + LetterSize size = getSize(damage); - return icons[size][state]; + return icons[size.ordinal()][state.ordinal()]; } - public static int encodeMeta(int state, int size) { - int meta = size << 4; - meta |= state; + public static int encodeMeta(LetterState state, LetterSize size) { + int meta = size.ordinal() << 4; + meta |= state.ordinal(); return meta; } - public static int getState(int meta) { - return meta & 0x0f; + public static LetterState getState(int meta) { + int ordinal = meta & 0x0f; + return LetterState.values()[ordinal]; } - public static int getSize(int meta) { - return meta >> 4; + public static LetterSize getSize(int meta) { + int ordinal = meta >> 4; + return LetterSize.values()[ordinal]; + } + + public static LetterSize getSize(ILetter letter) { + int count = letter.countAttachments(); + + if (count > 5) { + return LetterSize.BIG; + } else if (count > 1) { + return LetterSize.SMALL; + } else { + return LetterSize.EMPTY; + } } @SuppressWarnings({"unchecked", "rawtypes"}) @@ -259,24 +293,11 @@ public class ItemLetter extends ItemInventoried { public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean flag) { NBTTagCompound nbttagcompound = itemstack.getTagCompound(); if (nbttagcompound == null) { - list.add("<" + StringUtil.localize("gui.blank") + ">"); + list.add('<' + StringUtil.localize("gui.blank") + '>'); return; } ILetter letter = new Letter(nbttagcompound); letter.addTooltip(list); } - - public static int getType(ILetter letter) { - int count = letter.countAttachments(); - - if (count > 5) { - return 2; - } else if (count > 1) { - return 1; - } else { - return 0; - } - } - } diff --git a/src/main/java/forestry/mail/proxy/ClientProxyMail.java b/src/main/java/forestry/mail/proxy/ClientProxyMail.java deleted file mode 100755 index e94b3fa8d..000000000 --- a/src/main/java/forestry/mail/proxy/ClientProxyMail.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.mail.proxy; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.World; - -import com.mojang.authlib.GameProfile; - -import forestry.api.mail.IMailAddress; -import forestry.api.mail.PostManager; -import forestry.core.network.ForestryPacket; -import forestry.core.network.PacketIds; -import forestry.core.proxy.Proxies; -import forestry.core.utils.PlayerUtil; -import forestry.mail.POBox; -import forestry.mail.POBoxInfo; -import forestry.mail.PostRegistry; -import forestry.mail.gui.GuiMailboxInfo; - -public class ClientProxyMail extends ProxyMail { - - @Override - public void clearMailboxInfo() { - GuiMailboxInfo.instance = null; - } - - @Override - public void resetMailboxInfo() { - if (Proxies.common.getClientInstance().thePlayer == null || Proxies.common.getClientInstance().theWorld == null) { - return; - } - - GuiMailboxInfo.instance = new GuiMailboxInfo(); - - if (!Proxies.common.isSimulating(Proxies.common.getRenderWorld())) { - Proxies.net.sendToServer(new ForestryPacket(PacketIds.POBOX_INFO_REQUEST)); - } else { - GameProfile profile = Proxies.common.getClientInstance().thePlayer.getGameProfile(); - IMailAddress address = PostManager.postRegistry.getMailAddress(profile); - POBox pobox = PostRegistry.getPOBox(Proxies.common.getRenderWorld(), address); - if (pobox != null) { - setPOBoxInfo(Proxies.common.getRenderWorld(), address, pobox.getPOBoxInfo()); - } - } - } - - @Override - public void setPOBoxInfo(World world, IMailAddress address, POBoxInfo info) { - EntityPlayer clientPlayer = Proxies.common.getPlayer(); - if (PlayerUtil.isSameGameProfile(clientPlayer.getGameProfile(), address.getPlayerProfile())) { - GuiMailboxInfo.instance.setPOBoxInfo(info); - } - } -} diff --git a/src/main/java/forestry/mail/proxy/ProxyMail.java b/src/main/java/forestry/mail/proxy/ProxyMail.java deleted file mode 100755 index 76f938c8f..000000000 --- a/src/main/java/forestry/mail/proxy/ProxyMail.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.mail.proxy; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.World; - -import forestry.api.mail.IMailAddress; -import forestry.core.network.PacketIds; -import forestry.core.proxy.Proxies; -import forestry.mail.POBoxInfo; -import forestry.mail.network.PacketPOBoxInfo; - -public class ProxyMail { - - public void clearMailboxInfo() { - } - - public void resetMailboxInfo() { - } - - public void setPOBoxInfo(World world, IMailAddress address, POBoxInfo info) { - EntityPlayer player = Proxies.common.getPlayer(world, address.getPlayerProfile()); - if (player != null) { - Proxies.net.sendToPlayer(new PacketPOBoxInfo(PacketIds.POBOX_INFO, info), player); - } - } -} diff --git a/src/main/java/forestry/plugins/PluginMail.java b/src/main/java/forestry/plugins/PluginMail.java index b61db5747..fbb10069d 100755 --- a/src/main/java/forestry/plugins/PluginMail.java +++ b/src/main/java/forestry/plugins/PluginMail.java @@ -16,7 +16,6 @@ import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.network.IGuiHandler; import forestry.api.mail.EnumAddressee; @@ -30,7 +29,6 @@ import forestry.core.config.ForestryItem; import forestry.core.fluids.Fluids; import forestry.core.gadgets.BlockBase; import forestry.core.gadgets.MachineDefinition; -import forestry.core.interfaces.IOreDictionaryHandler; import forestry.core.interfaces.IPacketHandler; import forestry.core.interfaces.ISaveEventHandler; import forestry.core.items.ItemForestryBlock; @@ -50,14 +48,11 @@ import forestry.mail.items.ItemCatalogue; import forestry.mail.items.ItemLetter; import forestry.mail.items.ItemStamps; import forestry.mail.items.ItemStamps.StampInfo; -import forestry.mail.proxy.ProxyMail; import forestry.mail.triggers.MailTriggers; @Plugin(pluginID = "Mail", name = "Mail", author = "SirSengir", url = Defaults.URL, unlocalizedDescription = "for.plugin.mail.description") public class PluginMail extends ForestryPlugin { - @SidedProxy(clientSide = "forestry.mail.proxy.ClientProxyMail", serverSide = "forestry.mail.proxy.ProxyMail") - public static ProxyMail proxy; public static MachineDefinition definitionMailbox; public static MachineDefinition definitionTradestation; public static MachineDefinition definitionPhilatelist; diff --git a/src/main/java/forestry/storage/GuiHandlerStorage.java b/src/main/java/forestry/storage/GuiHandlerStorage.java index 9d5cc6d83..262458139 100755 --- a/src/main/java/forestry/storage/GuiHandlerStorage.java +++ b/src/main/java/forestry/storage/GuiHandlerStorage.java @@ -11,7 +11,6 @@ package forestry.storage; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; @@ -34,20 +33,15 @@ public class GuiHandlerStorage extends GuiHandlerBase { public static class PagedBackpackInventory extends ItemInventoryBackpack implements IPagedInventory { - //private final int x, y, z; private final int guiId; - public PagedBackpackInventory(Class itemClass, int size, ItemStack itemstack, int x, int y, int z, int guiId) { - super(itemClass, size, itemstack); - /*this.x = x; - this.y = y; - this.z = z;*/ + public PagedBackpackInventory(EntityPlayer player, int size, ItemStack itemstack, int guiId) { + super(player, size, itemstack); this.guiId = guiId; } @Override public void flipPage(EntityPlayer player, int page) { - onGuiSaved(player); player.openGui(ForestryAPI.instance, encodeGuiData(guiId, page), player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ); } } @@ -70,22 +64,22 @@ public class GuiHandlerStorage extends GuiHandlerBase { return null; } ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot("rootBees"); - PagedBackpackInventory inventory = new PagedBackpackInventory(ItemBackpack.class, Defaults.SLOTS_BACKPACK_APIARIST, equipped, x, y, z, cleanId); - return new GuiNaturalistInventory(speciesRoot, player, new ContainerNaturalistBackpack(player.inventory, inventory, guiData, 25), inventory, guiData, 5); + PagedBackpackInventory inventory = new PagedBackpackInventory(player, Defaults.SLOTS_BACKPACK_APIARIST, equipped, cleanId); + return new GuiNaturalistInventory(speciesRoot, player, new ContainerNaturalistBackpack(player, inventory, guiData, 25), inventory, guiData, 5); case BackpackGUI: equipped = getBackpackItem(player); if (equipped == null) { return null; } - return new GuiBackpack(new ContainerBackpack(player, new ItemInventoryBackpack(ItemBackpack.class, Defaults.SLOTS_BACKPACK_DEFAULT, equipped))); + return new GuiBackpack(new ContainerBackpack(player, ContainerBackpack.Size.DEFAULT, equipped)); case BackpackT2GUI: equipped = getBackpackItem(player); if (equipped == null) { return null; } - return new GuiBackpackT2(new ContainerBackpack(player, new ItemInventoryBackpack(ItemBackpack.class, Defaults.SLOTS_BACKPACK_T2, equipped))); + return new GuiBackpackT2(new ContainerBackpack(player, ContainerBackpack.Size.T2, equipped)); case LepidopteristBackpackGUI: equipped = getBackpackItem(player); @@ -93,8 +87,8 @@ public class GuiHandlerStorage extends GuiHandlerBase { return null; } speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot("rootButterflies"); - inventory = new PagedBackpackInventory(ItemBackpack.class, Defaults.SLOTS_BACKPACK_APIARIST, equipped, x, y, z, id); - return new GuiNaturalistInventory(speciesRoot, player, new ContainerNaturalistBackpack(player.inventory, inventory, guiData, 25), inventory, guiData, 5); + inventory = new PagedBackpackInventory(player, Defaults.SLOTS_BACKPACK_APIARIST, equipped, id); + return new GuiNaturalistInventory(speciesRoot, player, new ContainerNaturalistBackpack(player, inventory, guiData, 25), inventory, guiData, 5); default: return null; @@ -102,7 +96,7 @@ public class GuiHandlerStorage extends GuiHandlerBase { } } - private ItemStack getBackpackItem(EntityPlayer player) { + private static ItemStack getBackpackItem(EntityPlayer player) { ItemStack equipped = player.getCurrentEquippedItem(); if (equipped == null) { return null; @@ -131,7 +125,7 @@ public class GuiHandlerStorage extends GuiHandlerBase { return null; } - return new ContainerNaturalistBackpack(player.inventory, new PagedBackpackInventory(ItemBackpack.class, Defaults.SLOTS_BACKPACK_APIARIST, equipped, x, y, z, cleanId), guiData, 25); + return new ContainerNaturalistBackpack(player, new PagedBackpackInventory(player, Defaults.SLOTS_BACKPACK_APIARIST, equipped, cleanId), guiData, 25); case BackpackGUI: equipped = getBackpackItem(player); @@ -139,7 +133,7 @@ public class GuiHandlerStorage extends GuiHandlerBase { return null; } - return new ContainerBackpack(player, new ItemInventoryBackpack(ItemBackpack.class, Defaults.SLOTS_BACKPACK_DEFAULT, equipped)); + return new ContainerBackpack(player, ContainerBackpack.Size.DEFAULT, equipped); case BackpackT2GUI: equipped = getBackpackItem(player); @@ -147,7 +141,7 @@ public class GuiHandlerStorage extends GuiHandlerBase { return null; } - return new ContainerBackpack(player, new ItemInventoryBackpack(ItemBackpack.class, Defaults.SLOTS_BACKPACK_T2, equipped)); + return new ContainerBackpack(player, ContainerBackpack.Size.T2, equipped); case LepidopteristBackpackGUI: equipped = getBackpackItem(player); @@ -155,7 +149,7 @@ public class GuiHandlerStorage extends GuiHandlerBase { return null; } - return new ContainerNaturalistBackpack(player.inventory, new PagedBackpackInventory(ItemBackpack.class, Defaults.SLOTS_BACKPACK_APIARIST, equipped, x, y, z, cleanId), guiData, 25); + return new ContainerNaturalistBackpack(player, new PagedBackpackInventory(player, Defaults.SLOTS_BACKPACK_APIARIST, equipped, cleanId), guiData, 25); default: return null; diff --git a/src/main/java/forestry/storage/ResupplyHandler.java b/src/main/java/forestry/storage/ResupplyHandler.java index de98d77fc..bdb3174c6 100755 --- a/src/main/java/forestry/storage/ResupplyHandler.java +++ b/src/main/java/forestry/storage/ResupplyHandler.java @@ -10,7 +10,11 @@ ******************************************************************************/ package forestry.storage; +import java.util.ArrayList; +import java.util.List; + import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ContainerPlayer; import net.minecraft.item.ItemStack; @@ -18,9 +22,7 @@ import net.minecraftforge.common.MinecraftForge; import cpw.mods.fml.common.eventhandler.Event; -import forestry.api.storage.BackpackManager; import forestry.api.storage.BackpackResupplyEvent; -import forestry.api.storage.IBackpackDefinition; import forestry.core.interfaces.IResupplyHandler; import forestry.core.inventory.ItemInventory; import forestry.core.inventory.ItemInventoryBackpack; @@ -28,6 +30,16 @@ import forestry.storage.items.ItemBackpack; public class ResupplyHandler implements IResupplyHandler { + private static List backpacks(InventoryPlayer playerInventory) { + List backpacks = new ArrayList(); + for (ItemStack itemStack : playerInventory.mainInventory) { + if (itemStack != null && itemStack.stackSize > 0 && (itemStack.getItem() instanceof ItemBackpack)) { + backpacks.add(itemStack); + } + } + return backpacks; + } + @Override public void resupply(EntityPlayer player) { @@ -36,24 +48,7 @@ public class ResupplyHandler implements IResupplyHandler { return; } - for (IBackpackDefinition backpack : BackpackManager.definitions.values()) { - resupply(backpack, player); - } - - } - - public void resupply(IBackpackDefinition backpackItem, EntityPlayer player) { - - // Get all backpacks of this type in the player's inventory - for (ItemStack backpack : player.inventory.mainInventory) { - - if (backpack == null || backpack.stackSize <= 0) { - continue; - } - - if (!(backpack.getItem() instanceof ItemBackpack)) { - continue; - } + for (ItemStack backpack : backpacks(player.inventory)) { // Only handle those in resupply mode if (ItemBackpack.getMode(backpack) != BackpackMode.RESUPPLY) { @@ -67,49 +62,37 @@ public class ResupplyHandler implements IResupplyHandler { } // Load their inventory - ItemBackpack packItem = ((ItemBackpack) backpack.getItem()); - ItemInventory backpackinventory = new ItemInventoryBackpack(ItemBackpack.class, packItem.getBackpackSize(), backpack); - Event event = new BackpackResupplyEvent(player, packItem.getDefinition(), backpackinventory); + ItemBackpack backpackItem = ((ItemBackpack) backpack.getItem()); + ItemInventory backpackInventory = new ItemInventoryBackpack(player, backpackItem.getBackpackSize(), backpack); + + Event event = new BackpackResupplyEvent(player, backpackItem.getDefinition(), backpackInventory); MinecraftForge.EVENT_BUS.post(event); if (event.isCanceled()) { continue; } - boolean inventoryChanged = false; // Cycle through their contents - for (int i = 0; i < backpackinventory.getSizeInventory(); i++) { + for (int i = 0; i < backpackInventory.getSizeInventory(); i++) { - ItemStack packstack = backpackinventory.getStackInSlot(i); - if (packstack == null) { - continue; - } - if (packstack.stackSize <= 0) { + ItemStack itemStack = backpackInventory.getStackInSlot(i); + if (itemStack == null || itemStack.stackSize <= 0) { continue; } // Try to add it to the player's inventory and note any change - boolean change = topOffPlayerInventory(player, packstack); - if (!inventoryChanged) { - inventoryChanged = change; - } + boolean change = topOffPlayerInventory(player, itemStack); - // Clear consumed stacks - if (packstack.stackSize <= 0) { - backpackinventory.setInventorySlotContents(i, null); + if (change) { + backpackInventory.setInventorySlotContents(i, itemStack); } } - // Save the backpack inventory if it changed - if (inventoryChanged) { - backpackinventory.onGuiSaved(player); - } - } } /** * This tops off existing stacks in the player's inventory. */ - private boolean topOffPlayerInventory(EntityPlayer player, ItemStack itemstack) { + private static boolean topOffPlayerInventory(EntityPlayer player, ItemStack itemstack) { // Add to player inventory first, if there is an incomplete stack in // there. diff --git a/src/main/java/forestry/storage/gui/ContainerBackpack.java b/src/main/java/forestry/storage/gui/ContainerBackpack.java index 1edfda00b..0f7bc93d6 100755 --- a/src/main/java/forestry/storage/gui/ContainerBackpack.java +++ b/src/main/java/forestry/storage/gui/ContainerBackpack.java @@ -11,51 +11,44 @@ package forestry.storage.gui; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; -import forestry.core.config.Defaults; import forestry.core.gui.ContainerItemInventory; import forestry.core.gui.slots.SlotFiltered; import forestry.core.inventory.ItemInventoryBackpack; public class ContainerBackpack extends ContainerItemInventory { - public ContainerBackpack(EntityPlayer player, ItemInventoryBackpack inventory) { - super(inventory); + public enum Size { + DEFAULT(3, 5, 44, 19), + T2(5, 9, 8, 8); - int lines = 0; - int columns = 0; - int startX = 0; - int startY = 0; - if (inventory.getSizeInventory() == Defaults.SLOTS_BACKPACK_DEFAULT) { - lines = 3; - columns = 5; - startX = 44; - startY = 19; - } else if (inventory.getSizeInventory() == Defaults.SLOTS_BACKPACK_T2) { - lines = 5; - columns = 9; - startX = 8; - startY = 8; + final int rows; + final int columns; + final int startX; + final int startY; + + Size(int rows, int columns, int startX, int startY) { + this.rows = rows; + this.columns = columns; + this.startX = startX; + this.startY = startY; } - // Inventory - for (int j = 0; j < lines; j++) { - for (int k = 0; k < columns; k++) { - int slot = k + j * columns; - addSlotToContainer(new SlotFiltered(inventory, slot, startX + k * 18, startY + j * 18)); - } - } - - // Player inventory - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 9; j++) { - addSecuredSlot(player.inventory, j + i * 9 + 9, 8 + j * 18, 11 + startY + lines * 18 + i * 18); - } - } - // Player hotbar - for (int i = 0; i < 9; i++) { - addSecuredSlot(player.inventory, i, 8 + i * 18, 11 + startY + lines * 18 + 58); + public int getSize() { + return rows * columns; } } + public ContainerBackpack(EntityPlayer player, Size size, ItemStack parent) { + super(new ItemInventoryBackpack(player, size.getSize(), parent), player.inventory, 8, 11 + size.startY + size.rows * 18); + + // Inventory + for (int j = 0; j < size.rows; j++) { + for (int k = 0; k < size.columns; k++) { + int slot = k + j * size.columns; + addSlotToContainer(new SlotFiltered(inventory, slot, size.startX + k * 18, size.startY + j * 18)); + } + } + } } diff --git a/src/main/java/forestry/storage/gui/ContainerNaturalistBackpack.java b/src/main/java/forestry/storage/gui/ContainerNaturalistBackpack.java index 4380d20d7..d0ade8435 100755 --- a/src/main/java/forestry/storage/gui/ContainerNaturalistBackpack.java +++ b/src/main/java/forestry/storage/gui/ContainerNaturalistBackpack.java @@ -11,7 +11,6 @@ package forestry.storage.gui; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; import forestry.core.gui.ContainerItemInventory; import forestry.core.gui.IGuiSelectable; @@ -21,8 +20,8 @@ import forestry.storage.GuiHandlerStorage.PagedBackpackInventory; public class ContainerNaturalistBackpack extends ContainerItemInventory implements IGuiSelectable { - public ContainerNaturalistBackpack(InventoryPlayer player, PagedBackpackInventory inventory, int page, int pageSize) { - super(inventory); + public ContainerNaturalistBackpack(EntityPlayer player, PagedBackpackInventory inventory, int page, int pageSize) { + super(inventory, player.inventory, 18, 120); // Inventory for (int x = 0; x < 5; x++) { @@ -30,17 +29,6 @@ public class ContainerNaturalistBackpack extends ContainerItemInventory