From 034cdf2860f68d91e16f5c468767902dcbff58de Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Sun, 30 Nov 2014 17:19:16 -0800 Subject: [PATCH] Intial stages of an cleanup of the inventory code, this commit is very broken. --- .../apiculture/gadgets/TileAlveary.java | 14 +- .../gadgets/TileAlvearyHygroregulator.java | 89 +++++------ .../apiculture/gadgets/TileAlvearyPlain.java | 149 +++++++----------- .../apiculture/gadgets/TileAlvearySieve.java | 7 +- .../gadgets/TileAlvearySwarmer.java | 137 ++++++++-------- .../apiculture/gadgets/TileBeehouse.java | 2 +- .../apiculture/gadgets/TileSwarm.java | 2 +- .../apiculture/gui/ContainerAlvearySieve.java | 4 - .../apiculture/gui/ContainerApiary.java | 32 ++-- .../apiculture/items/ItemBeealyzer.java | 2 +- .../apiculture/items/ItemBiomefinder.java | 2 +- .../arboriculture/items/ItemTreealyzer.java | 2 +- .../core/circuits/ItemSolderingIron.java | 2 +- .../java/forestry/core/gadgets/BlockBase.java | 3 +- .../forestry/core/gadgets/BlockForestry.java | 1 - .../forestry/core/gadgets/BlockStructure.java | 3 +- .../forestry/core/gadgets/TileAnalyzer.java | 109 ++++--------- .../java/forestry/core/gadgets/TileBase.java | 10 -- .../forestry/core/gadgets/TileEscritoire.java | 4 +- .../forestry/core/gadgets/TileForestry.java | 82 +++------- .../forestry/core/gadgets/TileMachine.java | 88 +---------- .../forestry/core/gui/ContainerAlyzer.java | 2 +- .../forestry/core/gui/ContainerForestry.java | 2 +- .../core/gui/ContainerItemInventory.java | 2 +- .../{utils => inventory}/AlyzerInventory.java | 2 +- .../InventoryAdapter.java | 25 ++- .../{utils => inventory}/ItemInventory.java | 3 +- .../TileInventoryAdapter.java | 27 +++- .../java/forestry/core/utils/StackUtils.java | 1 + src/main/java/forestry/core/utils/Utils.java | 10 +- .../forestry/energy/gadgets/EngineBronze.java | 93 ++--------- .../forestry/energy/gadgets/EngineCopper.java | 4 +- .../forestry/energy/gadgets/EngineTin.java | 2 +- .../energy/gadgets/MachineGenerator.java | 2 +- .../energy/gui/ContainerEngineBronze.java | 25 ++- .../energy/gui/ContainerEngineCopper.java | 25 ++- .../energy/gui/ContainerGenerator.java | 20 ++- .../factory/gadgets/MachineBottler.java | 117 ++++++++------ .../factory/gadgets/MachineCarpenter.java | 4 +- .../factory/gadgets/MachineCentrifuge.java | 2 +- .../factory/gadgets/MachineFabricator.java | 2 +- .../factory/gadgets/MachineFermenter.java | 2 +- .../factory/gadgets/MachineMoistener.java | 2 +- .../factory/gadgets/MachineRaintank.java | 2 +- .../factory/gadgets/MachineSqueezer.java | 2 +- .../factory/gadgets/MachineStill.java | 2 +- .../factory/gadgets/TileWorktable.java | 4 +- .../factory/gui/ContainerBottler.java | 19 ++- .../factory/gui/ContainerFermenter.java | 24 ++- .../factory/gui/ContainerMoistener.java | 24 +-- .../factory/gui/ContainerRaintank.java | 15 +- .../forestry/factory/gui/ContainerStill.java | 16 +- .../forestry/farming/gadgets/TileFarm.java | 2 +- .../farming/gadgets/TileFarmPlain.java | 4 +- .../forestry/farming/gadgets/TileHatch.java | 2 +- .../forestry/farming/gui/ContainerFarm.java | 2 +- .../items/ItemFlutterlyzer.java | 2 +- src/main/java/forestry/mail/Letter.java | 2 +- src/main/java/forestry/mail/MailAddress.java | 26 ++- src/main/java/forestry/mail/POBox.java | 2 +- src/main/java/forestry/mail/PostRegistry.java | 5 + src/main/java/forestry/mail/TradeStation.java | 2 +- .../forestry/mail/gadgets/MachineMailbox.java | 2 +- .../mail/gadgets/MachinePhilatelist.java | 2 +- .../forestry/mail/gadgets/MachineTrader.java | 2 +- .../forestry/mail/gui/ContainerTradeName.java | 8 +- .../forestry/mail/gui/ContainerTrader.java | 47 ++++-- .../java/forestry/mail/items/ItemLetter.java | 2 +- .../pipes/gui/ContainerPropolisPipe.java | 19 +-- .../forestry/storage/GuiHandlerStorage.java | 2 +- .../forestry/storage/ResupplyHandler.java | 2 +- .../storage/gui/ContainerBackpack.java | 2 +- .../forestry/storage/items/ItemBackpack.java | 2 +- 73 files changed, 606 insertions(+), 759 deletions(-) rename src/main/java/forestry/core/{utils => inventory}/AlyzerInventory.java (97%) rename src/main/java/forestry/core/{utils => inventory}/InventoryAdapter.java (95%) rename src/main/java/forestry/core/{utils => inventory}/ItemInventory.java (98%) rename src/main/java/forestry/core/{utils => inventory}/TileInventoryAdapter.java (59%) diff --git a/src/main/java/forestry/apiculture/gadgets/TileAlveary.java b/src/main/java/forestry/apiculture/gadgets/TileAlveary.java index a4a28c98e..6f9b246e0 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileAlveary.java +++ b/src/main/java/forestry/apiculture/gadgets/TileAlveary.java @@ -23,9 +23,6 @@ import forestry.core.config.ForestryBlock; import forestry.core.gadgets.TileForestry; import forestry.core.network.PacketPayload; import forestry.core.proxy.Proxies; -import forestry.core.utils.TileInventoryAdapter; -import forestry.core.utils.Utils; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -40,8 +37,6 @@ public abstract class TileAlveary extends TileForestry implements IAlvearyCompon private boolean isMaster; protected int masterX, masterZ; protected int masterY = -99; - - protected TileInventoryAdapter inventory; protected final int componentBlockMeta; public TileAlveary(int componentBlockMeta) { @@ -147,7 +142,7 @@ public abstract class TileAlveary extends TileForestry implements IAlvearyCompon setCentralTE(null); isMaster = true; - if (inventory == null) + if (getInternalInventory() == null) createInventory(); } @@ -215,7 +210,7 @@ public abstract class TileAlveary extends TileForestry implements IAlvearyCompon @Override public IInventory getInventory() { - return inventory; + return getInternalInventory(); } /* IALVEARY COMPONENT */ @@ -258,9 +253,4 @@ public abstract class TileAlveary extends TileForestry implements IAlvearyCompon return res; } - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return Utils.isUseableByPlayer(player, this, worldObj, xCoord, yCoord, zCoord); - } - } diff --git a/src/main/java/forestry/apiculture/gadgets/TileAlvearyHygroregulator.java b/src/main/java/forestry/apiculture/gadgets/TileAlvearyHygroregulator.java index 64f6aa013..cb85c3437 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileAlvearyHygroregulator.java +++ b/src/main/java/forestry/apiculture/gadgets/TileAlvearyHygroregulator.java @@ -32,9 +32,10 @@ import forestry.core.fluids.tanks.FilteredTank; import forestry.core.interfaces.ILiquidTankContainer; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; -import forestry.core.utils.InventoryAdapter; import forestry.core.utils.LiquidHelper; import forestry.core.utils.StackUtils; +import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.utils.Utils; public class TileAlvearyHygroregulator extends TileAlveary implements IInventory, ILiquidTankContainer { @@ -43,6 +44,7 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory /* RECIPE MANAGMENT */ private static class HygroregulatorRecipe { + public final FluidStack liquid; public final int transferTime; public final float humidChange; @@ -59,7 +61,6 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory private final HygroregulatorRecipe[] recipes; /* MEMBERS */ - private final InventoryAdapter canInventory = new InventoryAdapter(1, "CanInv"); private final TankManager tankManager; private final FilteredTank liquidTank; @@ -69,6 +70,8 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory public TileAlvearyHygroregulator() { super(BLOCK_META); + setInternalInventory(new TileInventoryAdapter(this, 1, "CanInv")); + Fluid water = LiquidHelper.getFluid(Defaults.LIQUID_WATER); Fluid lava = LiquidHelper.getFluid(Defaults.LIQUID_LAVA); Fluid liquidIce = LiquidHelper.getFluid(Defaults.LIQUID_ICE); @@ -76,9 +79,9 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory liquidTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, water, lava, liquidIce); tankManager = new TankManager(liquidTank); - recipes = new HygroregulatorRecipe[] { new HygroregulatorRecipe(new FluidStack(water, 1), 1, 0.01f, -0.005f), - new HygroregulatorRecipe(new FluidStack(lava, 1), 10, -0.01f, +0.005f), - new HygroregulatorRecipe(new FluidStack(liquidIce, 1), 10, 0.02f, -0.01f) }; + recipes = new HygroregulatorRecipe[]{new HygroregulatorRecipe(new FluidStack(water, 1), 1, 0.01f, -0.005f), + new HygroregulatorRecipe(new FluidStack(lava, 1), 10, -0.01f, +0.005f), + new HygroregulatorRecipe(new FluidStack(liquidIce, 1), 10, 0.02f, -0.01f)}; } @Override @@ -94,11 +97,12 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory /* UPDATING */ private HygroregulatorRecipe getRecipe(FluidStack liquid) { HygroregulatorRecipe recipe = null; - for (HygroregulatorRecipe rec : recipes) + for (HygroregulatorRecipe rec : recipes) { if (rec.liquid.isFluidEqual(liquid)) { recipe = rec; break; } + } return recipe; } @@ -131,11 +135,13 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory if (worldObj.getTotalWorldTime() % 20 * 10 != 0) return; + TileInventoryAdapter canInventory = getInternalInventory(); + // Check if we have suitable items waiting in the item slot if (canInventory.getStackInSlot(0) != null) { FluidContainerData container = LiquidHelper.getLiquidContainer(canInventory.getStackInSlot(0)); - if (container != null && - (container.fluid.getFluid() == FluidRegistry.WATER || container.fluid.getFluid() == FluidRegistry.LAVA)) { + if (container != null + && (container.fluid.getFluid() == FluidRegistry.WATER || container.fluid.getFluid() == FluidRegistry.LAVA)) { canInventory.setInventorySlotContents(0, StackUtils.replenishByContainer(this, canInventory.getStackInSlot(0), container, liquidTank)); if (canInventory.getStackInSlot(0).stackSize <= 0) @@ -154,9 +160,6 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory @Override public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); - - canInventory.readFromNBT(nbttagcompound); - tankManager.readTanksFromNBT(nbttagcompound); transferTime = nbttagcompound.getInteger("TransferTime"); @@ -170,9 +173,6 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory @Override public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); - - canInventory.writeToNBT(nbttagcompound); - tankManager.writeTanksToNBT(nbttagcompound); nbttagcompound.setInteger("TransferTime", transferTime); @@ -192,38 +192,38 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory @Override public IInventory getInventory() { - return canInventory; + return getInternalInventory(); } /* IINVENTORY */ @Override public int getSizeInventory() { - if (canInventory != null) - return canInventory.getSizeInventory(); + if (getInternalInventory() != null) + return getInternalInventory().getSizeInventory(); else return 0; } @Override public ItemStack getStackInSlot(int slotIndex) { - if (canInventory != null) - return canInventory.getStackInSlot(slotIndex); + if (getInternalInventory() != null) + return getInternalInventory().getStackInSlot(slotIndex); else return null; } @Override public ItemStack decrStackSize(int slotIndex, int amount) { - if (canInventory != null) - return canInventory.decrStackSize(slotIndex, amount); + if (getInternalInventory() != null) + return getInternalInventory().decrStackSize(slotIndex, amount); else return null; } @Override public ItemStack getStackInSlotOnClosing(int slotIndex) { - if (canInventory != null) - return canInventory.getStackInSlotOnClosing(slotIndex); + if (getInternalInventory() != null) + return getInternalInventory().getStackInSlotOnClosing(slotIndex); else return null; } @@ -231,21 +231,26 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory @Override public void setInventorySlotContents(int slotIndex, ItemStack itemstack) { // Client side handling for container synch - if (canInventory == null && !Proxies.common.isSimulating(worldObj)) + if (getInternalInventory() == null && !Proxies.common.isSimulating(worldObj)) createInventory(); - if (canInventory != null) - canInventory.setInventorySlotContents(slotIndex, itemstack); + if (getInternalInventory() != null) + getInternalInventory().setInventorySlotContents(slotIndex, itemstack); } @Override public int getInventoryStackLimit() { - if (canInventory != null) - return canInventory.getInventoryStackLimit(); + if (getInternalInventory() != null) + return getInternalInventory().getInventoryStackLimit(); else return 0; } + @Override + public boolean isUseableByPlayer(EntityPlayer player) { + return Utils.isUseableByPlayer(player, this); + } + @Override public void openInventory() { } @@ -254,27 +259,16 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory public void closeInventory() { } - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - /** - * TODO: just a specialsource workaround - */ @Override public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); + return false; } - /** - * TODO: just a specialsource workaround - */ @Override public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { + if (!getInternalInventory().isItemValidForSlot(slotIndex, itemstack)) + return false; + if (slotIndex == 0) { FluidStack fluid = LiquidHelper.getFluidStackInContainer(itemstack); if (fluid == null || fluid.amount <= 0) @@ -282,7 +276,7 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory return liquidTank.accepts(fluid.getFluid()); } - return super.isItemValidForSlot(slotIndex, itemstack); + return false; } /* ILIQUIDTANKCONTAINER */ @@ -296,6 +290,7 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory return tankManager.fill(from, resource, doFill); } + @Override public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { return tankManager.drain(from, resource, doDrain); } @@ -321,8 +316,10 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory } @Override - public void getGUINetworkData(int messageId, int data) {} + public void getGUINetworkData(int messageId, int data) { + } @Override - public void sendGUINetworkData(Container container, ICrafting iCrafting) {} + public void sendGUINetworkData(Container container, ICrafting iCrafting) { + } } diff --git a/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java b/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java index 97b73f9ea..7286dc25d 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java +++ b/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java @@ -27,6 +27,7 @@ import forestry.api.core.ITileStructure; import forestry.api.genetics.IIndividual; import forestry.apiculture.gui.ContainerAlveary; import forestry.core.config.Config; +import forestry.core.config.Defaults; import forestry.core.config.ForestryItem; import forestry.core.interfaces.IClimatised; import forestry.core.interfaces.IErrorSource; @@ -35,8 +36,8 @@ import forestry.core.network.GuiId; import forestry.core.network.PacketIds; import forestry.core.network.PacketInventoryStack; import forestry.core.proxy.Proxies; -import forestry.core.utils.InventoryAdapter; -import forestry.core.utils.TileInventoryAdapter; +import forestry.core.inventory.InventoryAdapter; +import forestry.core.inventory.TileInventoryAdapter; import forestry.core.utils.Utils; import forestry.plugins.PluginApiculture; import net.minecraft.entity.player.EntityPlayer; @@ -47,11 +48,11 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; -import net.minecraftforge.common.BiomeDictionary; import net.minecraftforge.common.util.ForgeDirection; import java.util.LinkedHashSet; import java.util.Set; +import scala.collection.SortedMap; public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, ISpecialInventory, IBeeHousing, IClimatised, IHintSource { @@ -90,8 +91,6 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS this.tempChange = nbttagcompound.getFloat("TempChange"); this.humidChange = nbttagcompound.getFloat("HumidChange"); - if (inventory != null) - inventory.readFromNBT(nbttagcompound); if (beekeepingLogic != null) beekeepingLogic.readFromNBT(nbttagcompound); @@ -104,8 +103,6 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS nbttagcompound.setFloat("TempChange", tempChange); nbttagcompound.setFloat("HumidChange", humidChange); - if (inventory != null) - inventory.writeToNBT(nbttagcompound); if (beekeepingLogic != null) beekeepingLogic.writeToNBT(nbttagcompound); @@ -139,7 +136,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS // Add swarm effects if (worldObj.getTotalWorldTime() % 200 * 10 == 0) - onQueenChange(inventory.getStackInSlot(SLOT_QUEEN)); + onQueenChange(getInternalInventory().getStackInSlot(SLOT_QUEEN)); if (getErrorState() == EnumErrorCode.OK) queen.doFX(beekeepingLogic.getEffectData(), this); @@ -164,16 +161,15 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS if (!isMaster()) return; - if (inventory == null) + if (getInternalInventory() == null) return; // / Multiplayer FX - if (PluginApiculture.beeInterface.isMated(inventory.getStackInSlot(SLOT_QUEEN))) { + if (PluginApiculture.beeInterface.isMated(getInternalInventory().getStackInSlot(SLOT_QUEEN))) if (getErrorState() == EnumErrorCode.OK && worldObj.getTotalWorldTime() % 2 == 0) { - IBee displayQueen = PluginApiculture.beeInterface.getMember(inventory.getStackInSlot(SLOT_QUEEN)); + IBee displayQueen = PluginApiculture.beeInterface.getMember(getInternalInventory().getStackInSlot(SLOT_QUEEN)); displayQueen.doFX(beekeepingLogic.getEffectData(), this); } - } } private void equalizeTemperature() { @@ -196,6 +192,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS /* STATE INFORMATION */ private int getHealthDisplay() { + IInventory inventory = getInternalInventory(); if (inventory == null || inventory.getStackInSlot(SLOT_QUEEN) == null) return 0; @@ -208,6 +205,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS } private int getMaxHealthDisplay() { + IInventory inventory = getInternalInventory(); if (inventory == null || inventory.getStackInSlot(SLOT_QUEEN) == null) return 0; @@ -237,7 +235,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS /* STRUCTURE MANAGMENT */ @Override protected void createInventory() { - this.inventory = new TileInventoryAdapter(this, 9, "Items"); + setInternalInventory(new TileInventoryAdapter(this, 9, "Items")); } @Override @@ -425,6 +423,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS @Override public boolean addProduct(ItemStack product, boolean all) { + TileInventoryAdapter inventory = getInternalInventory(); if (inventory == null) return false; @@ -523,13 +522,8 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS } /* IINVENTORY */ - @Override - public InventoryAdapter getInternalInventory() { - return (InventoryAdapter) getStructureInventory(); - } - private IInventory getStructureInventory() { - + TileInventoryAdapter inventory = getInternalInventory(); if (inventory != null) { if (isMaster() || !Proxies.common.isSimulating(worldObj)) return inventory; @@ -580,6 +574,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS @Override public void setInventorySlotContents(int slotIndex, ItemStack itemstack) { + TileInventoryAdapter inventory = getInternalInventory(); // Client side handling for container synch if (inventory == null && !Proxies.common.isSimulating(worldObj)) createInventory(); @@ -603,33 +598,6 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS return 0; } - @Override - protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) { - - if (!super.canTakeStackFromSide(slotIndex, itemstack, side)) - return false; - - if (slotIndex != SLOT_QUEEN && slotIndex != SLOT_DRONE) - return true; - - return false; - } - - @Override - protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) { - - if (!super.canPutStackFromSide(slotIndex, itemstack, side)) - return false; - - if (slotIndex == SLOT_QUEEN && PluginApiculture.beeInterface.isMember(itemstack) - && !PluginApiculture.beeInterface.isDrone(itemstack)) - return true; - if (slotIndex == SLOT_DRONE && PluginApiculture.beeInterface.isDrone(itemstack)) - return true; - - return false; - } - @Override public void openInventory() { } @@ -638,52 +606,53 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS public void closeInventory() { } - /** - * TODO: just a specialsource workaround - */ @Override public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); + return Utils.isUseableByPlayer(player, this); } - /** - * TODO: just a specialsource workaround - */ @Override public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); + return false; } - /** - * TODO: just a specialsource workaround - */ @Override public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); + TileInventoryAdapter inventory = getInternalInventory(); + if (inventory == null) + return false; + + if (!inventory.isItemValidForSlot(slotIndex, itemstack)) + return false; + + if (slotIndex == SLOT_QUEEN && PluginApiculture.beeInterface.isMember(itemstack) + && !PluginApiculture.beeInterface.isDrone(itemstack)) + return true; + return slotIndex == SLOT_DRONE && PluginApiculture.beeInterface.isDrone(itemstack); } - /** - * TODO: just a specialsource workaround - */ @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - return super.canInsertItem(i, itemstack, j); + public boolean canInsertItem(int slotIndex, ItemStack itemstack, int side) { + return isItemValidForSlot(slotIndex, itemstack); } - /** - * TODO: just a specialsource workaround - */ @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - return super.canExtractItem(i, itemstack, j); + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + TileInventoryAdapter inventory = getInternalInventory(); + if (inventory == null) + return false; + if (!inventory.canExtractItem(slotIndex, itemstack, side)) + return false; + + return slotIndex != SLOT_QUEEN && slotIndex != SLOT_DRONE; } - /** - * TODO: just a specialsource workaround - */ @Override public int[] getAccessibleSlotsFromSide(int side) { - return super.getAccessibleSlotsFromSide(side); + TileInventoryAdapter inventory = getInternalInventory(); + if (inventory == null) + return Defaults.FACINGS_NONE; + return inventory.getAccessibleSlotsFromSide(side); } /* ISPECIALINVENTORY */ @@ -755,28 +724,28 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS break; } - return new ItemStack[] { product }; + return new ItemStack[]{product}; } /* SMP GUI */ public void getGUINetworkData(int i, int j) { switch (i) { - case 0: - displayHealth = j; - break; - case 1: - displayHealthMax = j; - break; - case 4: - this.tempChange = (float) j / 100; - break; - case 5: - this.humidChange = (float) j / 100; - break; - case 6: { - this.biome = BiomeGenBase.getBiome(j); - break; - } + case 0: + displayHealth = j; + break; + case 1: + displayHealthMax = j; + break; + case 4: + this.tempChange = (float) j / 100; + break; + case 5: + this.humidChange = (float) j / 100; + break; + case 6: { + this.biome = BiomeGenBase.getBiome(j); + break; + } } } @@ -836,7 +805,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS public boolean isOwnable() { return true; } - + /* IHousing */ @Override public GameProfile getOwnerName() { diff --git a/src/main/java/forestry/apiculture/gadgets/TileAlvearySieve.java b/src/main/java/forestry/apiculture/gadgets/TileAlvearySieve.java index d5d21d206..dd8536ea9 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileAlvearySieve.java +++ b/src/main/java/forestry/apiculture/gadgets/TileAlvearySieve.java @@ -23,7 +23,7 @@ import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IIndividual; import forestry.core.interfaces.ICrafter; import forestry.core.network.GuiId; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListener { @@ -125,11 +125,6 @@ public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListe } } } - - /* INVENTORY */ - public InventoryAdapter getInternalInventory() { - return inventory; - } /* ICRAFTER */ @Override diff --git a/src/main/java/forestry/apiculture/gadgets/TileAlvearySwarmer.java b/src/main/java/forestry/apiculture/gadgets/TileAlvearySwarmer.java index a7339d22f..93572e7f8 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileAlvearySwarmer.java +++ b/src/main/java/forestry/apiculture/gadgets/TileAlvearySwarmer.java @@ -19,7 +19,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraftforge.common.util.ForgeDirection; import forestry.api.apiculture.BeeManager; import forestry.api.apiculture.EnumBeeType; @@ -27,20 +26,25 @@ import forestry.api.apiculture.IAlvearyComponent; import forestry.api.apiculture.IBee; import forestry.api.apiculture.IBeeHousing; import forestry.api.core.ForestryAPI; -import forestry.api.core.ISpecialInventory; import forestry.apiculture.worldgen.WorldGenHive; import forestry.apiculture.worldgen.WorldGenHiveSwamer; +import forestry.core.config.Defaults; +import forestry.core.config.ForestryItem; +import forestry.core.inventory.wrappers.IInvSlot; +import forestry.core.inventory.wrappers.InventoryIterator; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; -import forestry.core.utils.TileInventoryAdapter; +import forestry.core.utils.StackUtils; +import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.utils.Utils; import forestry.plugins.PluginApiculture; +import net.minecraft.inventory.ISidedInventory; -public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory { +public class TileAlvearySwarmer extends TileAlveary implements ISidedInventory { /* CONSTANTS */ public static final int BLOCK_META = 2; - TileInventoryAdapter swarmerInventory; private final Stack pendingSpawns = new Stack(); public TileAlvearySwarmer() { @@ -50,7 +54,7 @@ public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory @Override public void initialize() { super.initialize(); - if (swarmerInventory == null) + if (getInternalInventory() == null) createInventory(); } @@ -89,10 +93,10 @@ public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory int slot = getInducerSlot(); if (slot < 0) return; - int chance = getChanceFor(swarmerInventory.getStackInSlot(slot)); + int chance = getChanceFor(getInternalInventory().getStackInSlot(slot)); // Remove resource - swarmerInventory.decrStackSize(slot, 1); + getInternalInventory().decrStackSize(slot, 1); // Try to spawn princess if (worldObj.rand.nextInt(1000) >= chance) @@ -115,12 +119,13 @@ public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory } private int getInducerSlot() { - for (int i = 0; i < swarmerInventory.getSizeInventory(); i++) { - if (swarmerInventory.getStackInSlot(i) == null) + for (IInvSlot slot : InventoryIterator.getIterable(getInternalInventory())) { + ItemStack stack = slot.getStackInSlot(); + if (stack == null) continue; for (Entry entry : BeeManager.inducers.entrySet()) { - if (entry.getKey().isItemEqual(swarmerInventory.getStackInSlot(i))) - return i; + if (entry.getKey().isItemEqual(stack)) + return slot.getIndex(); } } @@ -130,7 +135,7 @@ public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory private void trySpawnSwarm() { ItemStack toSpawn = pendingSpawns.peek(); - WorldGenHive generator = new WorldGenHiveSwamer(new ItemStack[] { toSpawn }); + WorldGenHive generator = new WorldGenHiveSwamer(new ItemStack[]{toSpawn}); int i = 0; while (i < 10) { @@ -154,7 +159,7 @@ public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory /* TEXTURES */ @Override public int getIcon(int side, int metadata) { - if(side == 0 || side == 1) + if (side == 0 || side == 1) return BlockAlveary.BOTTOM; if (pendingSpawns.size() > 0) @@ -166,10 +171,9 @@ public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory /* SAVING & LOADING */ @Override public void readFromNBT(NBTTagCompound nbttagcompound) { - super.readFromNBT(nbttagcompound); - if (swarmerInventory == null) + if (getInternalInventory() == null) createInventory(); - swarmerInventory.readFromNBT(nbttagcompound); + super.readFromNBT(nbttagcompound); NBTTagList nbttaglist = nbttagcompound.getTagList("PendingSpawns", 10); for (int i = 0; i < nbttaglist.tagCount(); i++) { @@ -182,75 +186,60 @@ public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory @Override public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); - if (swarmerInventory != null) - swarmerInventory.writeToNBT(nbttagcompound); NBTTagList nbttaglist = new NBTTagList(); ItemStack[] offspring = pendingSpawns.toArray(new ItemStack[pendingSpawns.size()]); - for (int i = 0; i < offspring.length; i++) + for (int i = 0; i < offspring.length; i++) { if (offspring[i] != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte) i); offspring[i].writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } + } nbttagcompound.setTag("PendingSpawns", nbttaglist); } @Override protected void createInventory() { - swarmerInventory = new TileInventoryAdapter(this, 4, "SwarmInv"); + setInternalInventory(new TileInventoryAdapter(this, 4, "SwarmInv")); } @Override public IInventory getInventory() { - return swarmerInventory; - } - - /* ISPECIALINVENTORY */ - @Override - public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) { - if (swarmerInventory != null) - return swarmerInventory.addStack(stack, false, doAdd); - else - return 0; - } - - @Override - public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) { - return null; + return getInternalInventory(); } /* IINVENTORY */ @Override public int getSizeInventory() { - if (swarmerInventory != null) - return swarmerInventory.getSizeInventory(); + if (getInternalInventory() != null) + return getInternalInventory().getSizeInventory(); else return 0; } @Override public ItemStack getStackInSlot(int slotIndex) { - if (swarmerInventory != null) - return swarmerInventory.getStackInSlot(slotIndex); + if (getInternalInventory() != null) + return getInternalInventory().getStackInSlot(slotIndex); else return null; } @Override public ItemStack decrStackSize(int slotIndex, int amount) { - if (swarmerInventory != null) - return swarmerInventory.decrStackSize(slotIndex, amount); + if (getInternalInventory() != null) + return getInternalInventory().decrStackSize(slotIndex, amount); else return null; } @Override public ItemStack getStackInSlotOnClosing(int slotIndex) { - if (swarmerInventory != null) - return swarmerInventory.getStackInSlotOnClosing(slotIndex); + if (getInternalInventory() != null) + return getInternalInventory().getStackInSlotOnClosing(slotIndex); else return null; } @@ -258,11 +247,11 @@ public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory @Override public void setInventorySlotContents(int slotIndex, ItemStack itemstack) { // Client side handling for container synch - if (swarmerInventory == null && !Proxies.common.isSimulating(worldObj)) + if (getInternalInventory() == null && !Proxies.common.isSimulating(worldObj)) createInventory(); - if (swarmerInventory != null) - swarmerInventory.setInventorySlotContents(slotIndex, itemstack); + if (getInternalInventory() != null) + getInternalInventory().setInventorySlotContents(slotIndex, itemstack); } @Override @@ -272,36 +261,56 @@ public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory @Override public int getInventoryStackLimit() { - if (swarmerInventory != null) - return swarmerInventory.getInventoryStackLimit(); + if (getInternalInventory() != null) + return getInternalInventory().getInventoryStackLimit(); else return 0; } - @Override public void openInventory() {} - @Override public void closeInventory() {} + @Override + public void openInventory() { + } + + @Override + public void closeInventory() { + } - /** - * TODO: just a specialsource workaround - */ @Override public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); + return Utils.isUseableByPlayer(player, this); } - /** - * TODO: just a specialsource workaround - */ @Override public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); + return false; } - /** - * TODO: just a specialsource workaround - */ @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); + public boolean isItemValidForSlot(int slotIndex, ItemStack stack) { + if (getInternalInventory() != null) { + if (!getInternalInventory().isItemValidForSlot(slotIndex, stack)) + return false; + return StackUtils.isIdenticalItem(stack, ForestryItem.royalJelly.getItemStack()); + } + return false; + } + + @Override + public int[] getAccessibleSlotsFromSide(int side) { + if (getInternalInventory() != null) + return getInternalInventory().getAccessibleSlotsFromSide(side); + return Defaults.FACINGS_NONE; + } + + @Override + public boolean canInsertItem(int slot, ItemStack stack, int side) { + if (getInternalInventory() != null) + return getInternalInventory().isItemValidForSlot(slot, stack); + return false; + } + + @Override + public boolean canExtractItem(int slot, ItemStack stack, int side) { + return false; } } diff --git a/src/main/java/forestry/apiculture/gadgets/TileBeehouse.java b/src/main/java/forestry/apiculture/gadgets/TileBeehouse.java index d343f4a03..44898033d 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileBeehouse.java +++ b/src/main/java/forestry/apiculture/gadgets/TileBeehouse.java @@ -29,7 +29,7 @@ import forestry.core.network.PacketIds; import forestry.core.network.PacketInventoryStack; import forestry.core.network.PacketTileUpdate; import forestry.core.proxy.Proxies; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.Utils; import forestry.plugins.PluginApiculture; import net.minecraft.entity.player.EntityPlayer; diff --git a/src/main/java/forestry/apiculture/gadgets/TileSwarm.java b/src/main/java/forestry/apiculture/gadgets/TileSwarm.java index 509566fe9..e9595c0cf 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileSwarm.java +++ b/src/main/java/forestry/apiculture/gadgets/TileSwarm.java @@ -14,7 +14,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; public class TileSwarm extends TileEntity { diff --git a/src/main/java/forestry/apiculture/gui/ContainerAlvearySieve.java b/src/main/java/forestry/apiculture/gui/ContainerAlvearySieve.java index 20eeedf67..0db2433b3 100755 --- a/src/main/java/forestry/apiculture/gui/ContainerAlvearySieve.java +++ b/src/main/java/forestry/apiculture/gui/ContainerAlvearySieve.java @@ -50,8 +50,4 @@ public class ContainerAlvearySieve extends ContainerForestry { } - @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return tile.isUseableByPlayer(entityplayer); - } } diff --git a/src/main/java/forestry/apiculture/gui/ContainerApiary.java b/src/main/java/forestry/apiculture/gui/ContainerApiary.java index 7a3af8172..414118aca 100755 --- a/src/main/java/forestry/apiculture/gui/ContainerApiary.java +++ b/src/main/java/forestry/apiculture/gui/ContainerApiary.java @@ -10,7 +10,6 @@ ******************************************************************************/ package forestry.apiculture.gui; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.IInventory; @@ -22,7 +21,6 @@ import forestry.core.config.ForestryItem; import forestry.core.gui.ContainerForestry; import forestry.core.gui.slots.SlotClosed; import forestry.core.gui.slots.SlotCustom; -import forestry.core.utils.Utils; public class ContainerApiary extends ContainerForestry { @@ -33,29 +31,29 @@ public class ContainerApiary extends ContainerForestry { this.tile = tile; tile.sendNetworkUpdate(); - IInventory inventory = tile.getInternalInventory(); + IInventory inv = tile.getInternalInventory(); // Queen/Princess - this.addSlot(new SlotCustom(inventory, TileBeehouse.SLOT_QUEEN, 29, 39, ForestryItem.beePrincessGE, ForestryItem.beeQueenGE)); + this.addSlot(new SlotCustom(inv, TileBeehouse.SLOT_QUEEN, 29, 39, ForestryItem.beePrincessGE, ForestryItem.beeQueenGE)); // Drone - this.addSlot(new SlotCustom(inventory, TileBeehouse.SLOT_DRONE, 29, 65, ForestryItem.beeDroneGE)); + this.addSlot(new SlotCustom(inv, TileBeehouse.SLOT_DRONE, 29, 65, ForestryItem.beeDroneGE)); // Frames if (hasFrames) { - this.addSlot(new SlotCustom(inventory, TileBeehouse.SLOT_FRAMES_1, 66, 23, IHiveFrame.class)); - this.addSlot(new SlotCustom(inventory, TileBeehouse.SLOT_FRAMES_1 + 1, 66, 52, IHiveFrame.class)); - this.addSlot(new SlotCustom(inventory, TileBeehouse.SLOT_FRAMES_1 + 2, 66, 81, IHiveFrame.class)); + this.addSlot(new SlotCustom(inv, TileBeehouse.SLOT_FRAMES_1, 66, 23, IHiveFrame.class)); + this.addSlot(new SlotCustom(inv, TileBeehouse.SLOT_FRAMES_1 + 1, 66, 52, IHiveFrame.class)); + this.addSlot(new SlotCustom(inv, TileBeehouse.SLOT_FRAMES_1 + 2, 66, 81, IHiveFrame.class)); } // Product Inventory - this.addSlot(new SlotClosed(inventory, 2, 116, 52)); - this.addSlot(new SlotClosed(inventory, 3, 137, 39)); - this.addSlot(new SlotClosed(inventory, 4, 137, 65)); - this.addSlot(new SlotClosed(inventory, 5, 116, 78)); - this.addSlot(new SlotClosed(inventory, 6, 95, 65)); - this.addSlot(new SlotClosed(inventory, 7, 95, 39)); - this.addSlot(new SlotClosed(inventory, 8, 116, 26)); + this.addSlot(new SlotClosed(inv, 2, 116, 52)); + this.addSlot(new SlotClosed(inv, 3, 137, 39)); + this.addSlot(new SlotClosed(inv, 4, 137, 65)); + this.addSlot(new SlotClosed(inv, 5, 116, 78)); + this.addSlot(new SlotClosed(inv, 6, 95, 65)); + this.addSlot(new SlotClosed(inv, 7, 95, 39)); + this.addSlot(new SlotClosed(inv, 8, 116, 26)); // Player inventory for (int i1 = 0; i1 < 3; i1++) { @@ -82,8 +80,4 @@ public class ContainerApiary extends ContainerForestry { } } - @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return Utils.isUseableByPlayer(entityplayer, tile, tile.getWorld(), tile.xCoord, tile.yCoord, tile.zCoord); - } } diff --git a/src/main/java/forestry/apiculture/items/ItemBeealyzer.java b/src/main/java/forestry/apiculture/items/ItemBeealyzer.java index d5a8210d5..64aa13eb8 100755 --- a/src/main/java/forestry/apiculture/items/ItemBeealyzer.java +++ b/src/main/java/forestry/apiculture/items/ItemBeealyzer.java @@ -10,7 +10,7 @@ ******************************************************************************/ package forestry.apiculture.items; -import forestry.core.utils.AlyzerInventory; +import forestry.core.inventory.AlyzerInventory; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; diff --git a/src/main/java/forestry/apiculture/items/ItemBiomefinder.java b/src/main/java/forestry/apiculture/items/ItemBiomefinder.java index a77af1765..24b86c762 100755 --- a/src/main/java/forestry/apiculture/items/ItemBiomefinder.java +++ b/src/main/java/forestry/apiculture/items/ItemBiomefinder.java @@ -38,7 +38,7 @@ import forestry.core.interfaces.IHintSource; import forestry.core.items.ItemInventoried; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; -import forestry.core.utils.ItemInventory; +import forestry.core.inventory.ItemInventory; import forestry.core.utils.Vect; import forestry.plugins.PluginApiculture; diff --git a/src/main/java/forestry/arboriculture/items/ItemTreealyzer.java b/src/main/java/forestry/arboriculture/items/ItemTreealyzer.java index d9156069e..dd051c3b1 100755 --- a/src/main/java/forestry/arboriculture/items/ItemTreealyzer.java +++ b/src/main/java/forestry/arboriculture/items/ItemTreealyzer.java @@ -15,7 +15,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import forestry.core.utils.AlyzerInventory; +import forestry.core.inventory.AlyzerInventory; import forestry.api.arboriculture.ITree; import forestry.api.core.ForestryAPI; import forestry.api.core.Tabs; diff --git a/src/main/java/forestry/core/circuits/ItemSolderingIron.java b/src/main/java/forestry/core/circuits/ItemSolderingIron.java index 0a6e3413e..91a5bda2b 100755 --- a/src/main/java/forestry/core/circuits/ItemSolderingIron.java +++ b/src/main/java/forestry/core/circuits/ItemSolderingIron.java @@ -30,7 +30,7 @@ import forestry.core.interfaces.IErrorSource; import forestry.core.items.ItemForestry; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; -import forestry.core.utils.ItemInventory; +import forestry.core.inventory.ItemInventory; public class ItemSolderingIron extends ItemForestry implements ISolderingIron { diff --git a/src/main/java/forestry/core/gadgets/BlockBase.java b/src/main/java/forestry/core/gadgets/BlockBase.java index 404db46d6..5cf9aee0e 100755 --- a/src/main/java/forestry/core/gadgets/BlockBase.java +++ b/src/main/java/forestry/core/gadgets/BlockBase.java @@ -37,6 +37,7 @@ import forestry.core.items.ItemNBTTile; import forestry.core.proxy.Proxies; import forestry.core.utils.LiquidHelper; import forestry.core.utils.StringUtil; +import forestry.core.utils.Utils; public class BlockBase extends BlockForestry { @@ -161,7 +162,7 @@ public class BlockBase extends BlockForestry { return false; TileBase tile = (TileBase) world.getTileEntity(x, y, z); - if (!tile.isUseableByPlayer(player)) + if (!Utils.isUseableByPlayer(player, tile)) return false; ItemStack current = player.getCurrentEquippedItem(); diff --git a/src/main/java/forestry/core/gadgets/BlockForestry.java b/src/main/java/forestry/core/gadgets/BlockForestry.java index ba26d000a..ae1832255 100755 --- a/src/main/java/forestry/core/gadgets/BlockForestry.java +++ b/src/main/java/forestry/core/gadgets/BlockForestry.java @@ -10,7 +10,6 @@ ******************************************************************************/ package forestry.core.gadgets; -import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; diff --git a/src/main/java/forestry/core/gadgets/BlockStructure.java b/src/main/java/forestry/core/gadgets/BlockStructure.java index 4f1a8ed17..a26f5b69f 100755 --- a/src/main/java/forestry/core/gadgets/BlockStructure.java +++ b/src/main/java/forestry/core/gadgets/BlockStructure.java @@ -20,6 +20,7 @@ import net.minecraft.world.World; import forestry.api.core.ITileStructure; import forestry.core.proxy.Proxies; import forestry.core.utils.StringUtil; +import forestry.core.utils.Utils; public abstract class BlockStructure extends BlockForestry { @@ -60,7 +61,7 @@ public abstract class BlockStructure extends BlockForestry { return false; TileForestry tile = (TileForestry) world.getTileEntity(x, y, z); - if (!tile.isUseableByPlayer(player)) + if (!Utils.isUseableByPlayer(player, tile)) return false; if (!Proxies.common.isSimulating(world)) diff --git a/src/main/java/forestry/core/gadgets/TileAnalyzer.java b/src/main/java/forestry/core/gadgets/TileAnalyzer.java index 22a1c007b..582f54356 100755 --- a/src/main/java/forestry/core/gadgets/TileAnalyzer.java +++ b/src/main/java/forestry/core/gadgets/TileAnalyzer.java @@ -42,7 +42,7 @@ import forestry.core.inventory.InvTools; import forestry.core.inventory.wrappers.IInvSlot; import forestry.core.inventory.wrappers.InventoryIterator; import forestry.core.inventory.wrappers.InventoryMapper; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.TileInventoryAdapter; import net.minecraft.inventory.IInventory; public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiquidTankContainer { @@ -57,8 +57,6 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui public static final short SLOT_OUTPUT_1 = 8; /* MEMBER */ - private final InventoryAdapter inventory = new InventoryAdapter(12, "Items"); - private int analyzeTime; @EntityNetData @@ -68,13 +66,15 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui private final Stack pendingProducts = new Stack(); - private final IInventory invInput = new InventoryMapper(inventory, SLOT_INPUT_1, 6); + private final IInventory invInput; /* CONSTRUCTOR */ public TileAnalyzer() { super(800, 40, Defaults.MACHINE_MAX_ENERGY); + setInternalInventory(new TileInventoryAdapter(this, 12, "Items")); resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, Fluids.HONEY.get()); tankManager = new TankManager(resourceTank); + invInput = new InventoryMapper(getInternalInventory(), SLOT_INPUT_1, 6); } @Override @@ -100,17 +100,15 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui // / Pending Products NBTTagList nbttaglist = new NBTTagList(); ItemStack[] pending = pendingProducts.toArray(new ItemStack[pendingProducts.size()]); - for (int i = 0; i < pending.length; i++) + for (int i = 0; i < pending.length; i++) { if (pending[i] != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte) i); pending[i].writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } + } nbttagcompound.setTag("PendingProducts", nbttaglist); - - // / Inventory - inventory.writeToNBT(nbttagcompound); } @Override @@ -127,9 +125,6 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); pendingProducts.add(ItemStack.loadItemStackFromNBT(nbttagcompound1)); } - - // / Inventory - inventory.readFromNBT(nbttagcompound); } @Override @@ -249,7 +244,7 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui return false; ItemStack next = pendingProducts.peek(); - if (inventory.tryAddStack(next, SLOT_OUTPUT_1, inventory.getSizeInventory() - SLOT_OUTPUT_1, true)) { + if (getInternalInventory().tryAddStack(next, SLOT_OUTPUT_1, getInternalInventory().getSizeInventory() - SLOT_OUTPUT_1, true)) { pendingProducts.pop(); return true; } @@ -270,7 +265,7 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui if (analyzeTime > 0) return true; - return getErrorState() == EnumErrorCode.OK ||getErrorState() == EnumErrorCode.NOPOWER; + return getErrorState() == EnumErrorCode.OK || getErrorState() == EnumErrorCode.NOPOWER; } public int getProgressScaled(int i) { @@ -304,62 +299,34 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui } /* ISIDEDINVENTORY */ - @Override - public InventoryAdapter getInternalInventory() { - return inventory; - } - - @Override - protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) { - if (!super.canTakeStackFromSide(slotIndex, itemstack, side)) - return false; - - return slotIndex >= SLOT_OUTPUT_1 && slotIndex < SLOT_OUTPUT_1 + 4; - } - - @Override - protected boolean canPutStackFromSide(int slotIndex, ItemStack stack, int side) { - - if (!super.canPutStackFromSide(slotIndex, stack, side)) - return false; - - if (slotIndex >= SLOT_INPUT_1 && slotIndex < SLOT_INPUT_1 + 6) - return AlleleManager.alleleRegistry.isIndividual(stack); - - if (slotIndex == SLOT_CAN) - return Fluids.HONEY.isContained(stack); - - return false; - } - @Override public int getSizeInventory() { - return inventory.getSizeInventory(); + return getInternalInventory().getSizeInventory(); } @Override public ItemStack getStackInSlot(int i) { - return inventory.getStackInSlot(i); + return getInternalInventory().getStackInSlot(i); } @Override public ItemStack decrStackSize(int i, int j) { - return inventory.decrStackSize(i, j); + return getInternalInventory().decrStackSize(i, j); } @Override public void setInventorySlotContents(int i, ItemStack itemstack) { - inventory.setInventorySlotContents(i, itemstack); + getInternalInventory().setInventorySlotContents(i, itemstack); } @Override public int getInventoryStackLimit() { - return inventory.getInventoryStackLimit(); + return getInternalInventory().getInventoryStackLimit(); } @Override public ItemStack getStackInSlotOnClosing(int slot) { - return inventory.getStackInSlotOnClosing(slot); + return getInternalInventory().getStackInSlotOnClosing(slot); } @Override @@ -370,52 +337,46 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui public void closeInventory() { } - /** - * TODO: just a specialsource workaround - */ @Override public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); + return getInternalInventory().isUseableByPlayer(player); } - /** - * TODO: just a specialsource workaround - */ @Override public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); + return false; } - /** - * TODO: just a specialsource workaround - */ @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); + public boolean isItemValidForSlot(int slot, ItemStack stack) { + if (!getInternalInventory().isItemValidForSlot(slot, stack)) + return false; + + if (slot >= SLOT_INPUT_1 && slot < SLOT_INPUT_1 + 6) + return AlleleManager.alleleRegistry.isIndividual(stack); + + if (slot == SLOT_CAN) + return Fluids.HONEY.isContained(stack); + + return false; } - /** - * TODO: just a specialsource workaround - */ @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - return super.canInsertItem(i, itemstack, j); + public boolean canInsertItem(int slot, ItemStack stack, int side) { + return isItemValidForSlot(side, stack); } - /** - * TODO: just a specialsource workaround - */ @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - return super.canExtractItem(i, itemstack, j); + public boolean canExtractItem(int slotIndex, ItemStack stack, int side) { + if (!getInternalInventory().canExtractItem(slotIndex, stack, side)) + return false; + + return slotIndex >= SLOT_OUTPUT_1 && slotIndex < SLOT_OUTPUT_1 + 4; } - /** - * TODO: just a specialsource workaround - */ @Override public int[] getAccessibleSlotsFromSide(int side) { - return super.getAccessibleSlotsFromSide(side); + return getInternalInventory().getAccessibleSlotsFromSide(side); } /* ILIQUIDCONTAINER */ diff --git a/src/main/java/forestry/core/gadgets/TileBase.java b/src/main/java/forestry/core/gadgets/TileBase.java index a88799bae..1761487f7 100755 --- a/src/main/java/forestry/core/gadgets/TileBase.java +++ b/src/main/java/forestry/core/gadgets/TileBase.java @@ -89,16 +89,6 @@ public abstract class TileBase extends TileForestry implements IHintSource { public void openGui(EntityPlayer player, TileBase tile) { } - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - if (!Utils.isUseableByPlayer(player, this, worldObj, xCoord, yCoord, zCoord)) - return false; - if (getAccess() == EnumAccess.PRIVATE) - return PlayerUtil.isSameGameProfile(owner, player.getGameProfile()); - - return true; - } - public boolean canDrainWithBucket() { return false; } diff --git a/src/main/java/forestry/core/gadgets/TileEscritoire.java b/src/main/java/forestry/core/gadgets/TileEscritoire.java index 6fdde0480..0bbed58cc 100755 --- a/src/main/java/forestry/core/gadgets/TileEscritoire.java +++ b/src/main/java/forestry/core/gadgets/TileEscritoire.java @@ -29,9 +29,9 @@ import forestry.core.network.PacketTileNBT; import forestry.core.network.PacketTileUpdate; import forestry.core.proxy.Proxies; import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.StringUtil; -import forestry.core.utils.TileInventoryAdapter; +import forestry.core.inventory.TileInventoryAdapter; import forestry.core.utils.Utils; public class TileEscritoire extends TileBase implements ISidedInventory, IRenderableMachine, ICrafter { diff --git a/src/main/java/forestry/core/gadgets/TileForestry.java b/src/main/java/forestry/core/gadgets/TileForestry.java index a6e1aedcd..940b9c831 100755 --- a/src/main/java/forestry/core/gadgets/TileForestry.java +++ b/src/main/java/forestry/core/gadgets/TileForestry.java @@ -18,7 +18,6 @@ import com.mojang.authlib.GameProfile; import cpw.mods.fml.common.Optional; import forestry.api.core.EnumErrorCode; import forestry.core.config.Config; -import forestry.core.config.Defaults; import forestry.core.interfaces.IErrorSource; import forestry.core.interfaces.IOwnable; import forestry.core.network.ForestryPacket; @@ -27,7 +26,7 @@ import forestry.core.network.PacketPayload; import forestry.core.network.PacketTileUpdate; import forestry.core.proxy.Proxies; import forestry.core.utils.EnumAccess; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.TileInventoryAdapter; import forestry.core.utils.Vect; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -46,6 +45,7 @@ import java.util.Collection; public abstract class TileForestry extends TileEntity implements INetworkedEntity, IOwnable, IErrorSource, ITriggerProvider { protected boolean isInited = false; + private TileInventoryAdapter inventory; public Vect Coords() { return new Vect(xCoord, yCoord, zCoord); @@ -79,44 +79,43 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit initialize(); isInited = true; } - - if (!Proxies.common.isSimulating(worldObj)) - return; } public abstract void initialize(); // / SAVING & LOADING @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - super.readFromNBT(nbttagcompound); + public void readFromNBT(NBTTagCompound data) { + super.readFromNBT(data); + + if(inventory != null) inventory.readFromNBT(data); - if (nbttagcompound.hasKey("Access")) - access = EnumAccess.values()[nbttagcompound.getInteger("Access")]; + if (data.hasKey("Access")) + access = EnumAccess.values()[data.getInteger("Access")]; else access = EnumAccess.SHARED; - if (nbttagcompound.hasKey("owner")) { - owner = NBTUtil.func_152459_a(nbttagcompound.getCompoundTag("owner")); - } + if (data.hasKey("owner")) + owner = NBTUtil.func_152459_a(data.getCompoundTag("owner")); - if (nbttagcompound.hasKey("Orientation")) - orientation = ForgeDirection.values()[nbttagcompound.getInteger("Orientation")]; + if (data.hasKey("Orientation")) + orientation = ForgeDirection.values()[data.getInteger("Orientation")]; else orientation = ForgeDirection.WEST; } @Override - public void writeToNBT(NBTTagCompound nbttagcompound) { - super.writeToNBT(nbttagcompound); - nbttagcompound.setInteger("Access", access.ordinal()); + public void writeToNBT(NBTTagCompound data) { + super.writeToNBT(data); + if(inventory != null) inventory.writeToNBT(data); + data.setInteger("Access", access.ordinal()); if (this.owner != null) { NBTTagCompound nbt = new NBTTagCompound(); NBTUtil.func_152460_a(nbt, owner); - nbttagcompound.setTag("owner", nbt); + data.setTag("owner", nbt); } if (orientation != null) - nbttagcompound.setInteger("Orientation", orientation.ordinal()); + data.setInteger("Orientation", orientation.ordinal()); } // / SMP @@ -205,7 +204,7 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit return errorState; } // / OWNERSHIP - public GameProfile owner = null; + private GameProfile owner = null; private EnumAccess access = EnumAccess.SHARED; @Override @@ -285,52 +284,21 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit } /* NAME */ - /** * Gets the tile's unlocalized name, based on the block at the location of this entity (client-only). + * @return */ public String getUnlocalizedName() { - String blockUnlocalizedName = getBlockType().getUnlocalizedName().replace("tile.for.",""); + String blockUnlocalizedName = getBlockType().getUnlocalizedName().replace("tile.for.", ""); return blockUnlocalizedName + "." + getBlockMetadata() + ".name"; } - public boolean hasCustomInventoryName() { - return true; - } - - /* ACCESS */ - public abstract boolean isUseableByPlayer(EntityPlayer player); - /* INVENTORY BASICS */ - public InventoryAdapter getInternalInventory() { - return null; + public final TileInventoryAdapter getInternalInventory() { + return inventory; } - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return true; - } - - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - return canPutStackFromSide(i, itemstack, j); - } - - protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) { - return getAccess() == EnumAccess.SHARED; - } - - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - return canTakeStackFromSide(i, itemstack, j); - } - - protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) { - return getAccess() == EnumAccess.SHARED; - } - - public int[] getAccessibleSlotsFromSide(int side) { - if (getInternalInventory() == null) - return Defaults.FACINGS_NONE; - else - return getInternalInventory().getSizeInventorySide(side); - + public final void setInternalInventory(TileInventoryAdapter inv) { + this.inventory = inv; } } diff --git a/src/main/java/forestry/core/gadgets/TileMachine.java b/src/main/java/forestry/core/gadgets/TileMachine.java index 54d250006..532cfc120 100755 --- a/src/main/java/forestry/core/gadgets/TileMachine.java +++ b/src/main/java/forestry/core/gadgets/TileMachine.java @@ -12,32 +12,26 @@ package forestry.core.gadgets; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; -import forestry.api.core.ISpecialInventory; import forestry.core.config.Defaults; import forestry.core.config.ForestryBlock; import forestry.core.interfaces.IClimatised; import forestry.core.interfaces.IHintSource; import forestry.core.network.PacketPayload; import forestry.core.proxy.Proxies; -import forestry.core.utils.EnumAccess; import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.Utils; import forestry.plugins.PluginApiculture; import forestry.plugins.PluginEnergy; import forestry.plugins.PluginFactory; import forestry.plugins.PluginIC2; import forestry.plugins.PluginMail; import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.IBlockAccess; -import net.minecraftforge.common.util.ForgeDirection; import java.util.HashMap; -public abstract class TileMachine extends TileForestry implements ISpecialInventory, IClimatised, IHintSource { +public abstract class TileMachine extends TileForestry implements IClimatised, IHintSource { public TileMachine() { } @@ -275,86 +269,6 @@ public abstract class TileMachine extends TileForestry implements ISpecialInvent return false; } - // IINVENTORY IMPLEMENTATION - @Override - public int getSizeInventory() { - return 0; - } - - @Override - public ItemStack getStackInSlot(int i) { - return null; - } - - @Override - public ItemStack decrStackSize(int i, int j) { - return null; - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - } - - @Override - public String getInventoryName() { - return getUnlocalizedName(); - } - - @Override - public int getInventoryStackLimit() { - return 64; - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - return null; - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return Utils.isUseableByPlayer(player, this, worldObj, xCoord, yCoord, zCoord); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); - } - - // IPARTICULARINVENTORY IMPLEMENTATION - @Override - public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) { - if (getAccess() == EnumAccess.PRIVATE) - return 0; - - return 0; - } - - @Override - public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) { - if (getAccess() == EnumAccess.PRIVATE) - return new ItemStack[0]; - - return new ItemStack[0]; - } // INETWORKEDTILE IMPLEMENTATION @Override diff --git a/src/main/java/forestry/core/gui/ContainerAlyzer.java b/src/main/java/forestry/core/gui/ContainerAlyzer.java index 91f95b2a0..eddc05d5f 100644 --- a/src/main/java/forestry/core/gui/ContainerAlyzer.java +++ b/src/main/java/forestry/core/gui/ContainerAlyzer.java @@ -2,7 +2,7 @@ package forestry.core.gui; import forestry.core.gui.slots.SlotCustom; import forestry.core.proxy.Proxies; -import forestry.core.utils.AlyzerInventory; +import forestry.core.inventory.AlyzerInventory; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; diff --git a/src/main/java/forestry/core/gui/ContainerForestry.java b/src/main/java/forestry/core/gui/ContainerForestry.java index 15a947fcb..b4d915402 100755 --- a/src/main/java/forestry/core/gui/ContainerForestry.java +++ b/src/main/java/forestry/core/gui/ContainerForestry.java @@ -213,7 +213,7 @@ public class ContainerForestry extends Container { } @Override - public boolean canInteractWith(EntityPlayer entityplayer) { + public final boolean canInteractWith(EntityPlayer entityplayer) { return inventory.isUseableByPlayer(entityplayer); } } diff --git a/src/main/java/forestry/core/gui/ContainerItemInventory.java b/src/main/java/forestry/core/gui/ContainerItemInventory.java index eb7a26704..755b88708 100755 --- a/src/main/java/forestry/core/gui/ContainerItemInventory.java +++ b/src/main/java/forestry/core/gui/ContainerItemInventory.java @@ -17,7 +17,7 @@ import net.minecraft.item.ItemStack; import forestry.core.gui.slots.SlotItemInventory; import forestry.core.gui.slots.SlotLocked; import forestry.core.proxy.Proxies; -import forestry.core.utils.ItemInventory; +import forestry.core.inventory.ItemInventory; public abstract class ContainerItemInventory extends ContainerForestry { diff --git a/src/main/java/forestry/core/utils/AlyzerInventory.java b/src/main/java/forestry/core/inventory/AlyzerInventory.java similarity index 97% rename from src/main/java/forestry/core/utils/AlyzerInventory.java rename to src/main/java/forestry/core/inventory/AlyzerInventory.java index 398ab4764..3423427c1 100644 --- a/src/main/java/forestry/core/utils/AlyzerInventory.java +++ b/src/main/java/forestry/core/inventory/AlyzerInventory.java @@ -1,4 +1,4 @@ -package forestry.core.utils; +package forestry.core.inventory; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; diff --git a/src/main/java/forestry/core/utils/InventoryAdapter.java b/src/main/java/forestry/core/inventory/InventoryAdapter.java similarity index 95% rename from src/main/java/forestry/core/utils/InventoryAdapter.java rename to src/main/java/forestry/core/inventory/InventoryAdapter.java index ea2b606cd..dc35a1fbb 100755 --- a/src/main/java/forestry/core/utils/InventoryAdapter.java +++ b/src/main/java/forestry/core/inventory/InventoryAdapter.java @@ -8,7 +8,7 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.core.utils; +package forestry.core.inventory; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; @@ -18,13 +18,16 @@ import net.minecraft.nbt.NBTTagList; import forestry.api.core.INBTTagable; import forestry.core.config.Defaults; +import forestry.core.utils.PlainInventory; +import forestry.core.utils.StackUtils; +import net.minecraft.inventory.ISidedInventory; /** * With permission from Krapht. */ -public class InventoryAdapter implements IInventory, INBTTagable { +public class InventoryAdapter implements IInventory, ISidedInventory, INBTTagable { - private IInventory inventory = null; + private final IInventory inventory; //private boolean debug = false; public InventoryAdapter(int size, String name) { @@ -44,7 +47,6 @@ public class InventoryAdapter implements IInventory, INBTTagable { // this.debug = true; // return this; // } - /** * @return Copy of this inventory. Stacks are copies. */ @@ -333,7 +335,7 @@ public class InventoryAdapter implements IInventory, INBTTagable { @Override public boolean isUseableByPlayer(EntityPlayer entityplayer) { - return false; + return true; } @Override @@ -357,7 +359,8 @@ public class InventoryAdapter implements IInventory, INBTTagable { /* ISIDEDINVENTORY */ private int[][] slotMap; - public int[] getSizeInventorySide(int side) { + @Override + public int[] getAccessibleSlotsFromSide(int side) { return slotMap[side]; } @@ -407,6 +410,16 @@ public class InventoryAdapter implements IInventory, INBTTagable { return this; } + @Override + public boolean canInsertItem(int slot, ItemStack stack, int side) { + return isItemValidForSlot(slot, stack); + } + + @Override + public boolean canExtractItem(int slot, ItemStack stack, int side) { + return true; + } + /* SAVING & LOADING */ @Override public void readFromNBT(NBTTagCompound nbttagcompound) { diff --git a/src/main/java/forestry/core/utils/ItemInventory.java b/src/main/java/forestry/core/inventory/ItemInventory.java similarity index 98% rename from src/main/java/forestry/core/utils/ItemInventory.java rename to src/main/java/forestry/core/inventory/ItemInventory.java index e7fcb75ff..b8d489157 100755 --- a/src/main/java/forestry/core/utils/ItemInventory.java +++ b/src/main/java/forestry/core/inventory/ItemInventory.java @@ -8,7 +8,7 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.core.utils; +package forestry.core.inventory; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; @@ -18,6 +18,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import forestry.api.core.INBTTagable; +import forestry.core.utils.Utils; public class ItemInventory implements IInventory, INBTTagable { diff --git a/src/main/java/forestry/core/utils/TileInventoryAdapter.java b/src/main/java/forestry/core/inventory/TileInventoryAdapter.java similarity index 59% rename from src/main/java/forestry/core/utils/TileInventoryAdapter.java rename to src/main/java/forestry/core/inventory/TileInventoryAdapter.java index d88b17f40..20bcfc26e 100755 --- a/src/main/java/forestry/core/utils/TileInventoryAdapter.java +++ b/src/main/java/forestry/core/inventory/TileInventoryAdapter.java @@ -8,19 +8,22 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.core.utils; +package forestry.core.inventory; import net.minecraft.entity.player.EntityPlayer; import forestry.core.gadgets.TileForestry; +import forestry.core.utils.EnumAccess; +import forestry.core.utils.PlayerUtil; +import forestry.core.utils.Utils; +import net.minecraft.item.ItemStack; public class TileInventoryAdapter extends InventoryAdapter { private final TileForestry tile; public TileInventoryAdapter(TileForestry tile, int size, String name) { - super(size, name); - this.tile = tile; + this(tile, size, name, 64); } public TileInventoryAdapter(TileForestry tile, int size, String name, int stackLimit) { @@ -29,8 +32,12 @@ public class TileInventoryAdapter extends InventoryAdapter { } @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) { - return tile.isUseableByPlayer(entityplayer); + public boolean isUseableByPlayer(EntityPlayer player) { + if (!Utils.isUseableByPlayer(player, tile)) + return false; + if (tile.getAccess() == EnumAccess.PRIVATE) + return PlayerUtil.isSameGameProfile(tile.getOwnerProfile(), player.getGameProfile()); + return true; } @Override @@ -38,4 +45,14 @@ public class TileInventoryAdapter extends InventoryAdapter { super.markDirty(); tile.markDirty(); } + + @Override + public boolean isItemValidForSlot(int i, ItemStack itemstack) { + return tile.getAccess() == EnumAccess.SHARED; + } + + @Override + public boolean canExtractItem(int slot, ItemStack stack, int side) { + return tile.getAccess() == EnumAccess.SHARED; + } } diff --git a/src/main/java/forestry/core/utils/StackUtils.java b/src/main/java/forestry/core/utils/StackUtils.java index 14ea1fbaf..ed4b946c5 100755 --- a/src/main/java/forestry/core/utils/StackUtils.java +++ b/src/main/java/forestry/core/utils/StackUtils.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.core.utils; +import forestry.core.inventory.InventoryAdapter; import java.util.ArrayList; import java.util.Random; diff --git a/src/main/java/forestry/core/utils/Utils.java b/src/main/java/forestry/core/utils/Utils.java index 06bc7b70f..06b216d55 100755 --- a/src/main/java/forestry/core/utils/Utils.java +++ b/src/main/java/forestry/core/utils/Utils.java @@ -229,7 +229,15 @@ public class Utils { return block == Blocks.water || block == Blocks.flowing_water || block == Blocks.lava || block == Blocks.flowing_lava; } - public static boolean isUseableByPlayer(EntityPlayer player, TileEntity tile, World world, int x, int y, int z) { + public static boolean isUseableByPlayer(EntityPlayer player, TileEntity tile) { + int x = tile.xCoord; + int y = tile.yCoord; + int z = tile.zCoord; + World world = tile.getWorldObj(); + + if(tile.isInvalid()) + return false; + if (world.getTileEntity(x, y, z) != tile) return false; diff --git a/src/main/java/forestry/energy/gadgets/EngineBronze.java b/src/main/java/forestry/energy/gadgets/EngineBronze.java index a07753998..530b758c2 100755 --- a/src/main/java/forestry/energy/gadgets/EngineBronze.java +++ b/src/main/java/forestry/energy/gadgets/EngineBronze.java @@ -25,8 +25,7 @@ import forestry.core.interfaces.ILiquidTankContainer; import forestry.core.network.GuiId; import forestry.core.network.PacketPayload; import forestry.core.utils.LiquidHelper; -import forestry.core.utils.TileInventoryAdapter; -import static forestry.factory.gadgets.MachineBottler.SLOT_PRODUCT; +import forestry.core.inventory.TileInventoryAdapter; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; @@ -70,7 +69,6 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank public FilteredTank fuelTank; public FilteredTank heatingTank; private final TankManager tankManager; - private final TileInventoryAdapter inventory; public int burnTime; public int totalTime; public int currentFluidId = -1; @@ -83,7 +81,7 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank super(Defaults.ENGINE_BRONZE_HEAT_MAX, 300000, 5000); setHints(Config.hints.get("engine.bronze")); - inventory = new TileInventoryAdapter(this, 1, "Items"); + setInternalInventory(new TileInventoryAdapter(this, 1, "Items")); fuelTank = new FilteredTank(Defaults.ENGINE_TANK_CAPACITY, FuelManager.bronzeEngineFuel.keySet()); fuelTank.tankMode = StandardTank.TankMode.INPUT; @@ -107,6 +105,8 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank super.updateServerSide(); + TileInventoryAdapter inventory = getInternalInventory(); + // Check if we have suitable items waiting in the item slot if (inventory.getStackInSlot(SLOT_CAN) != null) { @@ -304,7 +304,6 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank */ @Override public void readFromNBT(NBTTagCompound nbt) { - super.readFromNBT(nbt); burnTime = nbt.getInteger("EngineBurnTime"); @@ -317,7 +316,6 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank } tankManager.readTanksFromNBT(nbt); - inventory.readFromNBT(nbt); } @@ -327,7 +325,6 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank */ @Override public void writeToNBT(NBTTagCompound nbt) { - super.writeToNBT(nbt); nbt.setInteger("EngineBurnTime", burnTime); @@ -338,7 +335,6 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank nbt.setString("currentFluid", fluid.getName()); tankManager.writeTanksToNBT(nbt); - inventory.writeToNBT(nbt); } /* GUI */ @@ -382,32 +378,32 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank /* IINVENTORY */ @Override public int getSizeInventory() { - return inventory.getSizeInventory(); + return getInternalInventory().getSizeInventory(); } @Override public ItemStack getStackInSlot(int i) { - return inventory.getStackInSlot(i); + return getInternalInventory().getStackInSlot(i); } @Override public void setInventorySlotContents(int i, ItemStack itemstack) { - inventory.setInventorySlotContents(i, itemstack); + getInternalInventory().setInventorySlotContents(i, itemstack); } @Override public ItemStack decrStackSize(int i, int j) { - return inventory.decrStackSize(i, j); + return getInternalInventory().decrStackSize(i, j); } @Override public ItemStack getStackInSlotOnClosing(int slot) { - return inventory.getStackInSlotOnClosing(slot); + return getInternalInventory().getStackInSlotOnClosing(slot); } @Override public int getInventoryStackLimit() { - return inventory.getInventoryStackLimit(); + return getInternalInventory().getInventoryStackLimit(); } @Override @@ -418,14 +414,9 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank public void closeInventory() { } - /** - * TODO: just a specialsource workaround - * @param player - * @return - */ @Override public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); + return getInternalInventory().isUseableByPlayer(player); } @Override @@ -433,21 +424,11 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank return getUnlocalizedName(); } - /** - * TODO: just a specialsource workaround - * @return - */ @Override public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); + return false; } - /** - * TODO: just a specialsource workaround - * @param slotIndex - * @param itemstack - * @return - */ @Override public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { if (slotIndex == SLOT_CAN) { @@ -457,65 +438,25 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank return fuelTank.accepts(fluid.getFluid()) || heatingTank.accepts(fluid.getFluid()); } - return super.isItemValidForSlot(slotIndex, itemstack); + return getInternalInventory().isItemValidForSlot(slotIndex, itemstack); } /* ISIDEDINVENTORY */ @Override - protected boolean canTakeStackFromSide(int slotIndex, ItemStack stack, int side) { + public boolean canExtractItem(int i, ItemStack itemstack, int j) { return false; } @Override - protected boolean canPutStackFromSide(int slotIndex, ItemStack stack, int side) { - if (!super.canTakeStackFromSide(slotIndex, stack, side)) - return false; - - FluidContainerData container = LiquidHelper.getLiquidContainer(stack); - return container != null; + public boolean canInsertItem(int slotIndex, ItemStack stack, int side) { + return isItemValidForSlot(slotIndex, stack); } - /** - * TODO: just a specialsource workaround - * @return - */ - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - return super.canExtractItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - * @return - */ - @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - return super.canInsertItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - * @return - */ @Override public int[] getAccessibleSlotsFromSide(int side) { - return super.getAccessibleSlotsFromSide(side); //To change body of generated methods, choose Tools | Templates. + return getInternalInventory().getAccessibleSlotsFromSide(side); } - /* ISPECIALINVENTORY */ -// @Override -// public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) { -// FluidContainerData container = LiquidHelper.getLiquidContainer(stack); -// if (container == null) -// return 0; -// -// return inventory.addStack(stack, false, doAdd); -// } -// -// @Override -// public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) { -// return null; -// } // IFluidHandler @Override public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { diff --git a/src/main/java/forestry/energy/gadgets/EngineCopper.java b/src/main/java/forestry/energy/gadgets/EngineCopper.java index 9e98ee7f9..7be670b65 100755 --- a/src/main/java/forestry/energy/gadgets/EngineCopper.java +++ b/src/main/java/forestry/energy/gadgets/EngineCopper.java @@ -24,8 +24,8 @@ import forestry.core.gadgets.Engine; import forestry.core.gadgets.TileBase; import forestry.core.network.GuiId; import forestry.core.utils.BlockUtil; -import forestry.core.utils.InventoryAdapter; -import forestry.core.utils.TileInventoryAdapter; +import forestry.core.inventory.InventoryAdapter; +import forestry.core.inventory.TileInventoryAdapter; import forestry.factory.triggers.FactoryTriggers; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; diff --git a/src/main/java/forestry/energy/gadgets/EngineTin.java b/src/main/java/forestry/energy/gadgets/EngineTin.java index e584daadc..a210889d2 100755 --- a/src/main/java/forestry/energy/gadgets/EngineTin.java +++ b/src/main/java/forestry/energy/gadgets/EngineTin.java @@ -32,7 +32,7 @@ import forestry.core.interfaces.ISocketable; import forestry.core.network.GuiId; import forestry.core.utils.DelayTimer; import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.plugins.PluginIC2; public class EngineTin extends Engine implements ISocketable, IInventory { diff --git a/src/main/java/forestry/energy/gadgets/MachineGenerator.java b/src/main/java/forestry/energy/gadgets/MachineGenerator.java index bcec54700..3a94775fa 100755 --- a/src/main/java/forestry/energy/gadgets/MachineGenerator.java +++ b/src/main/java/forestry/energy/gadgets/MachineGenerator.java @@ -38,7 +38,7 @@ import forestry.core.interfaces.IRenderableMachine; import forestry.core.network.EntityNetData; import forestry.core.network.GuiId; import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.LiquidHelper; import forestry.core.utils.StackUtils; import forestry.core.utils.Utils; diff --git a/src/main/java/forestry/energy/gui/ContainerEngineBronze.java b/src/main/java/forestry/energy/gui/ContainerEngineBronze.java index c0f4c498e..adb70f8d0 100755 --- a/src/main/java/forestry/energy/gui/ContainerEngineBronze.java +++ b/src/main/java/forestry/energy/gui/ContainerEngineBronze.java @@ -10,6 +10,12 @@ ******************************************************************************/ package forestry.energy.gui; +<<<<<<< Updated upstream +======= +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Slot; + +>>>>>>> Stashed changes import forestry.core.gui.ContainerLiquidTanks; import forestry.core.gui.slots.SlotLiquidContainer; import forestry.energy.gadgets.EngineBronze; @@ -18,7 +24,12 @@ import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; public class ContainerEngineBronze extends ContainerLiquidTanks { +<<<<<<< Updated upstream protected final EngineBronze engine; +======= + + protected EngineBronze engine; +>>>>>>> Stashed changes public ContainerEngineBronze(InventoryPlayer player, EngineBronze engine) { super(engine, engine); @@ -27,18 +38,16 @@ public class ContainerEngineBronze extends ContainerLiquidTanks { this.addSlot(new SlotLiquidContainer(engine, EngineBronze.SLOT_CAN, 143, 40)); int i; - for (i = 0; i < 3; ++i) - for (int var4 = 0; var4 < 9; ++var4) + for (i = 0; i < 3; ++i) { + for (int var4 = 0; var4 < 9; ++var4) { this.addSlot(new Slot(player, var4 + i * 9 + 9, 8 + var4 * 18, 84 + i * 18)); + } + } - for (i = 0; i < 9; ++i) + for (i = 0; i < 9; ++i) { this.addSlot(new Slot(player, i, 8 + i * 18, 142)); + } } - @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return engine.isUseableByPlayer(entityplayer); - } - } diff --git a/src/main/java/forestry/energy/gui/ContainerEngineCopper.java b/src/main/java/forestry/energy/gui/ContainerEngineCopper.java index bd678ff3d..bdd46cbe9 100755 --- a/src/main/java/forestry/energy/gui/ContainerEngineCopper.java +++ b/src/main/java/forestry/energy/gui/ContainerEngineCopper.java @@ -10,7 +10,6 @@ ******************************************************************************/ package forestry.energy.gui; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; @@ -20,7 +19,12 @@ import forestry.core.gui.slots.SlotClosed; import forestry.energy.gadgets.EngineCopper; public class ContainerEngineCopper extends ContainerForestry { +<<<<<<< Updated upstream protected final EngineCopper engine; +======= + + protected EngineCopper engine; +>>>>>>> Stashed changes public ContainerEngineCopper(InventoryPlayer player, EngineCopper tile) { super(tile); @@ -33,12 +37,15 @@ public class ContainerEngineCopper extends ContainerForestry { this.addSlot(new SlotClosed(tile, 3, 116, 35)); this.addSlot(new SlotClosed(tile, 4, 116, 53)); - for (int i = 0; i < 3; ++i) - for (int j = 0; j < 9; ++j) + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 9; ++j) { this.addSlot(new Slot(player, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); + } + } - for (int i = 0; i < 9; ++i) + for (int i = 0; i < 9; ++i) { this.addSlot(new Slot(player, i, 8 + i * 18, 142)); + } } @@ -52,12 +59,14 @@ public class ContainerEngineCopper extends ContainerForestry { public void detectAndSendChanges() { super.detectAndSendChanges(); +<<<<<<< Updated upstream for (Object crafter : crafters) engine.sendGUINetworkData(this, (ICrafting) crafter); +======= + for (Object crafter : crafters) { + engine.sendGUINetworkData(this, (ICrafting) crafter); + } +>>>>>>> Stashed changes } - @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return engine.isUseableByPlayer(entityplayer); - } } diff --git a/src/main/java/forestry/energy/gui/ContainerGenerator.java b/src/main/java/forestry/energy/gui/ContainerGenerator.java index 570a909d2..53f6efdaa 100755 --- a/src/main/java/forestry/energy/gui/ContainerGenerator.java +++ b/src/main/java/forestry/energy/gui/ContainerGenerator.java @@ -10,6 +10,12 @@ ******************************************************************************/ package forestry.energy.gui; +<<<<<<< Updated upstream +======= +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Slot; + +>>>>>>> Stashed changes import forestry.core.gui.ContainerLiquidTanks; import forestry.core.gui.slots.SlotLiquidContainer; import forestry.energy.gadgets.MachineGenerator; @@ -27,17 +33,15 @@ public class ContainerGenerator extends ContainerLiquidTanks { this.tile = tile; this.addSlot(new SlotLiquidContainer(tile, MachineGenerator.SLOT_CAN, 22, 38)); - for (int i = 0; i < 3; ++i) - for (int var4 = 0; var4 < 9; ++var4) + for (int i = 0; i < 3; ++i) { + for (int var4 = 0; var4 < 9; ++var4) { this.addSlot(new Slot(player, var4 + i * 9 + 9, 8 + var4 * 18, 84 + i * 18)); + } + } - for (int i = 0; i < 9; ++i) + for (int i = 0; i < 9; ++i) { this.addSlot(new Slot(player, i, 8 + i * 18, 142)); - } - - @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return tile.isUseableByPlayer(entityplayer); + } } } diff --git a/src/main/java/forestry/factory/gadgets/MachineBottler.java b/src/main/java/forestry/factory/gadgets/MachineBottler.java index 0e9d01fcd..8b7348bae 100755 --- a/src/main/java/forestry/factory/gadgets/MachineBottler.java +++ b/src/main/java/forestry/factory/gadgets/MachineBottler.java @@ -25,7 +25,7 @@ import forestry.core.interfaces.ILiquidTankContainer; import forestry.core.network.EntityNetData; import forestry.core.network.GuiId; import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.LiquidHelper; import forestry.core.utils.StackUtils; import forestry.core.utils.Utils; @@ -64,6 +64,7 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq /* RECIPE MANAGMENT */ public static class Recipe { + public final int cyclesPerUnit; public final FluidStack input; public final ItemStack can; @@ -86,7 +87,12 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq } public static class RecipeManager implements ICraftingProvider { +<<<<<<< Updated upstream public static final ArrayList recipes = new ArrayList(); +======= + + public static ArrayList recipes = new ArrayList(); +>>>>>>> Stashed changes /** * @@ -105,9 +111,9 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq } // No recipe matched. See if the liquid dictionary has anything. - if(FluidContainerRegistry.isEmptyContainer(empty)) { + if (FluidContainerRegistry.isEmptyContainer(empty)) { ItemStack filled = FluidContainerRegistry.fillFluidContainer(res, empty); - if(filled != null) { + if (filled != null) { FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(filled); Recipe recipe = new Recipe(CYCLES_FILLING_DEFAULT, fluidStack, empty, filled); recipes.add(recipe); @@ -133,8 +139,9 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq public Map getRecipes() { HashMap recipeList = new HashMap(); - for (Recipe recipe : recipes) - recipeList.put(new Object[] { recipe.input, recipe.can }, new Object[] { recipe.bottled }); + for (Recipe recipe : recipes) { + recipeList.put(new Object[]{recipe.input, recipe.can}, new Object[]{recipe.bottled}); + } return recipeList; } @@ -184,13 +191,14 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq NBTTagList nbttaglist = new NBTTagList(); ItemStack[] offspring = pendingProducts.toArray(new ItemStack[pendingProducts.size()]); - for (int i = 0; i < offspring.length; i++) + for (int i = 0; i < offspring.length; i++) { if (offspring[i] != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte) i); offspring[i].writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } + } nbttagcompound.setTag("PendingProducts", nbttaglist); } @@ -379,14 +387,43 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq } /* IINVENTORY */ - @Override public int getSizeInventory() { return inventory.getSizeInventory(); } - @Override public ItemStack getStackInSlot(int i) { return inventory.getStackInSlot(i); } - @Override public ItemStack decrStackSize(int i, int j) { return inventory.decrStackSize(i, j); } - @Override public void setInventorySlotContents(int i, ItemStack itemstack) { inventory.setInventorySlotContents(i, itemstack); } - @Override public ItemStack getStackInSlotOnClosing(int slot) { return inventory.getStackInSlotOnClosing(slot); } - @Override public int getInventoryStackLimit() { return inventory.getInventoryStackLimit(); } - @Override public void openInventory() {} - @Override public void closeInventory() {} + @Override + public int getSizeInventory() { + return inventory.getSizeInventory(); + } + + @Override + public ItemStack getStackInSlot(int i) { + return inventory.getStackInSlot(i); + } + + @Override + public ItemStack decrStackSize(int i, int j) { + return inventory.decrStackSize(i, j); + } + + @Override + public void setInventorySlotContents(int i, ItemStack itemstack) { + inventory.setInventorySlotContents(i, itemstack); + } + + @Override + public ItemStack getStackInSlotOnClosing(int slot) { + return inventory.getStackInSlotOnClosing(slot); + } + + @Override + public int getInventoryStackLimit() { + return inventory.getInventoryStackLimit(); + } + + @Override + public void openInventory() { + } + + @Override + public void closeInventory() { + } /** * TODO: just a specialsource workaround @@ -404,36 +441,38 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq return super.hasCustomInventoryName(); } - /** - * TODO: just a specialsource workaround - */ @Override public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); + if (!getInternalInventory().isItemValidForSlot(slotIndex, itemstack)) + return false; + + if (slotIndex == SLOT_RESOURCE) + return FluidContainerRegistry.isEmptyContainer(itemstack); + + if (slotIndex == SLOT_CAN) { + FluidContainerData container = LiquidHelper.getLiquidContainer(itemstack); + return container != null && RecipeManager.isInput(container.fluid); + } + + return false; } - /** - * TODO: just a specialsource workaround - */ + @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - return super.canInsertItem(i, itemstack, j); + public boolean canInsertItem(int slotIndex, ItemStack itemstack, int side) { + return isItemValidForSlot(slotIndex, itemstack); } - /** - * TODO: just a specialsource workaround - */ + @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - return super.canExtractItem(i, itemstack, j); + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + return getInternalInventory().canExtractItem(side, itemstack, side) && slotIndex == SLOT_PRODUCT; } - /** - * TODO: just a specialsource workaround - */ + @Override public int[] getAccessibleSlotsFromSide(int side) { - return super.getAccessibleSlotsFromSide(side); + return getInternalInventory().getAccessibleSlotsFromSide(side); } /* ISIDEDINVENTORY */ @@ -445,7 +484,7 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq @Override protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) { - if(!super.canTakeStackFromSide(slotIndex, itemstack, side)) + if (!super.canTakeStackFromSide(slotIndex, itemstack, side)) return false; return slotIndex == SLOT_PRODUCT; @@ -454,18 +493,6 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq @Override protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) { - if(!super.canPutStackFromSide(slotIndex, itemstack, side)) - return false; - - if(slotIndex == SLOT_RESOURCE) - return FluidContainerRegistry.isEmptyContainer(itemstack); - - if(slotIndex == SLOT_CAN) { - FluidContainerData container = LiquidHelper.getLiquidContainer(itemstack); - return container != null && RecipeManager.isInput(container.fluid); - } - - return false; } /* ILIQUIDCONTAINER */ diff --git a/src/main/java/forestry/factory/gadgets/MachineCarpenter.java b/src/main/java/forestry/factory/gadgets/MachineCarpenter.java index 3ce691173..2bc174197 100755 --- a/src/main/java/forestry/factory/gadgets/MachineCarpenter.java +++ b/src/main/java/forestry/factory/gadgets/MachineCarpenter.java @@ -25,11 +25,11 @@ import forestry.core.network.EntityNetData; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.LiquidHelper; import forestry.core.utils.ShapedRecipeCustom; import forestry.core.utils.StackUtils; -import forestry.core.utils.TileInventoryAdapter; +import forestry.core.inventory.TileInventoryAdapter; import forestry.core.utils.Utils; import forestry.factory.gui.ContainerCarpenter; import net.minecraft.entity.player.EntityPlayer; diff --git a/src/main/java/forestry/factory/gadgets/MachineCentrifuge.java b/src/main/java/forestry/factory/gadgets/MachineCentrifuge.java index cf1b0a6e7..e54ea176d 100755 --- a/src/main/java/forestry/factory/gadgets/MachineCentrifuge.java +++ b/src/main/java/forestry/factory/gadgets/MachineCentrifuge.java @@ -21,7 +21,7 @@ import forestry.core.config.Defaults; import forestry.core.gadgets.TileBase; import forestry.core.gadgets.TilePowered; import forestry.core.network.GuiId; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.StackUtils; import forestry.factory.triggers.FactoryTriggers; import net.minecraft.entity.player.EntityPlayer; diff --git a/src/main/java/forestry/factory/gadgets/MachineFabricator.java b/src/main/java/forestry/factory/gadgets/MachineFabricator.java index f591b17db..927374790 100755 --- a/src/main/java/forestry/factory/gadgets/MachineFabricator.java +++ b/src/main/java/forestry/factory/gadgets/MachineFabricator.java @@ -42,7 +42,7 @@ import forestry.core.proxy.Proxies; import forestry.core.fluids.tanks.StandardTank; import forestry.core.fluids.TankManager; import forestry.core.fluids.tanks.FilteredTank; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.ShapedRecipeCustom; import forestry.core.utils.StackUtils; import net.minecraftforge.fluids.FluidTankInfo; diff --git a/src/main/java/forestry/factory/gadgets/MachineFermenter.java b/src/main/java/forestry/factory/gadgets/MachineFermenter.java index 3b1925a95..af22edc69 100755 --- a/src/main/java/forestry/factory/gadgets/MachineFermenter.java +++ b/src/main/java/forestry/factory/gadgets/MachineFermenter.java @@ -28,7 +28,7 @@ import forestry.core.interfaces.ILiquidTankContainer; import forestry.core.network.EntityNetData; import forestry.core.network.GuiId; import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.LiquidHelper; import forestry.core.utils.StackUtils; import forestry.core.utils.Utils; diff --git a/src/main/java/forestry/factory/gadgets/MachineMoistener.java b/src/main/java/forestry/factory/gadgets/MachineMoistener.java index c3970bdec..d34065cf0 100755 --- a/src/main/java/forestry/factory/gadgets/MachineMoistener.java +++ b/src/main/java/forestry/factory/gadgets/MachineMoistener.java @@ -26,7 +26,7 @@ import forestry.core.interfaces.IRenderableMachine; import forestry.core.network.EntityNetData; import forestry.core.network.GuiId; import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.LiquidHelper; import forestry.core.utils.StackUtils; import forestry.core.utils.Utils; diff --git a/src/main/java/forestry/factory/gadgets/MachineRaintank.java b/src/main/java/forestry/factory/gadgets/MachineRaintank.java index 64d5ae494..45d208b1e 100755 --- a/src/main/java/forestry/factory/gadgets/MachineRaintank.java +++ b/src/main/java/forestry/factory/gadgets/MachineRaintank.java @@ -21,7 +21,7 @@ import forestry.core.gadgets.TileBase; import forestry.core.interfaces.ILiquidTankContainer; import forestry.core.network.GuiId; import forestry.core.utils.Fluids; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.LiquidHelper; import forestry.core.utils.StackUtils; import forestry.core.utils.Utils; diff --git a/src/main/java/forestry/factory/gadgets/MachineSqueezer.java b/src/main/java/forestry/factory/gadgets/MachineSqueezer.java index b51346295..7f523433e 100755 --- a/src/main/java/forestry/factory/gadgets/MachineSqueezer.java +++ b/src/main/java/forestry/factory/gadgets/MachineSqueezer.java @@ -26,7 +26,7 @@ import forestry.core.network.EntityNetData; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.LiquidHelper; import forestry.core.utils.StackUtils; import forestry.core.utils.Utils; diff --git a/src/main/java/forestry/factory/gadgets/MachineStill.java b/src/main/java/forestry/factory/gadgets/MachineStill.java index bf5ded4ea..231ea79a6 100755 --- a/src/main/java/forestry/factory/gadgets/MachineStill.java +++ b/src/main/java/forestry/factory/gadgets/MachineStill.java @@ -25,7 +25,7 @@ import forestry.core.interfaces.ILiquidTankContainer; import forestry.core.network.EntityNetData; import forestry.core.network.GuiId; import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.LiquidHelper; import forestry.core.utils.StackUtils; import forestry.core.utils.Utils; diff --git a/src/main/java/forestry/factory/gadgets/TileWorktable.java b/src/main/java/forestry/factory/gadgets/TileWorktable.java index 8249834e3..c670c3a2a 100755 --- a/src/main/java/forestry/factory/gadgets/TileWorktable.java +++ b/src/main/java/forestry/factory/gadgets/TileWorktable.java @@ -34,10 +34,10 @@ import forestry.core.network.PacketIds; import forestry.core.network.PacketTileNBT; import forestry.core.network.PacketTileUpdate; import forestry.core.proxy.Proxies; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.PlainInventory; import forestry.core.utils.StackUtils; -import forestry.core.utils.TileInventoryAdapter; +import forestry.core.inventory.TileInventoryAdapter; public class TileWorktable extends TileBase implements ICrafter { diff --git a/src/main/java/forestry/factory/gui/ContainerBottler.java b/src/main/java/forestry/factory/gui/ContainerBottler.java index 7d4d2e27f..565b3801b 100755 --- a/src/main/java/forestry/factory/gui/ContainerBottler.java +++ b/src/main/java/forestry/factory/gui/ContainerBottler.java @@ -10,6 +10,12 @@ ******************************************************************************/ package forestry.factory.gui; +<<<<<<< Updated upstream +======= +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Slot; + +>>>>>>> Stashed changes import forestry.core.gui.ContainerLiquidTanks; import forestry.core.gui.slots.SlotClosed; import forestry.core.gui.slots.SlotLiquidContainer; @@ -31,17 +37,16 @@ public class ContainerBottler extends ContainerLiquidTanks { this.addSlot(new SlotLiquidContainer(tile, MachineBottler.SLOT_CAN, 26, 38)); int var3; - for (var3 = 0; var3 < 3; ++var3) - for (int var4 = 0; var4 < 9; ++var4) + for (var3 = 0; var3 < 3; ++var3) { + for (int var4 = 0; var4 < 9; ++var4) { this.addSlot(new Slot(player, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18)); + } + } - for (var3 = 0; var3 < 9; ++var3) + for (var3 = 0; var3 < 9; ++var3) { this.addSlot(new Slot(player, var3, 8 + var3 * 18, 142)); + } } - @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return tile.isUseableByPlayer(entityplayer); - } } diff --git a/src/main/java/forestry/factory/gui/ContainerFermenter.java b/src/main/java/forestry/factory/gui/ContainerFermenter.java index 5d43389d3..90c58931e 100755 --- a/src/main/java/forestry/factory/gui/ContainerFermenter.java +++ b/src/main/java/forestry/factory/gui/ContainerFermenter.java @@ -10,6 +10,12 @@ ******************************************************************************/ package forestry.factory.gui; +<<<<<<< Updated upstream +======= +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Slot; + +>>>>>>> Stashed changes import forestry.core.gui.ContainerLiquidTanks; import forestry.core.gui.slots.SlotCustom; import forestry.core.gui.slots.SlotLiquidContainer; @@ -20,7 +26,12 @@ import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; public class ContainerFermenter extends ContainerLiquidTanks { +<<<<<<< Updated upstream protected final MachineFermenter fermenter; +======= + + protected MachineFermenter fermenter; +>>>>>>> Stashed changes public ContainerFermenter(InventoryPlayer player, MachineFermenter fermenter) { super(fermenter, fermenter); @@ -32,17 +43,16 @@ public class ContainerFermenter extends ContainerLiquidTanks { this.addSlot(new SlotLiquidContainer(fermenter, MachineFermenter.SLOT_CAN_INPUT, 150, 22, true)); this.addSlot(new SlotLiquidContainer(fermenter, MachineFermenter.SLOT_INPUT, 10, 40)); - for (int i = 0; i < 3; ++i) - for (int var4 = 0; var4 < 9; ++var4) + for (int i = 0; i < 3; ++i) { + for (int var4 = 0; var4 < 9; ++var4) { this.addSlot(new Slot(player, var4 + i * 9 + 9, 8 + var4 * 18, 84 + i * 18)); + } + } - for (int i = 0; i < 9; ++i) + for (int i = 0; i < 9; ++i) { this.addSlot(new Slot(player, i, 8 + i * 18, 142)); + } } - @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return fermenter.isUseableByPlayer(entityplayer); - } } diff --git a/src/main/java/forestry/factory/gui/ContainerMoistener.java b/src/main/java/forestry/factory/gui/ContainerMoistener.java index 0a12d2390..b94d3152d 100755 --- a/src/main/java/forestry/factory/gui/ContainerMoistener.java +++ b/src/main/java/forestry/factory/gui/ContainerMoistener.java @@ -10,7 +10,6 @@ ******************************************************************************/ package forestry.factory.gui; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; @@ -30,12 +29,15 @@ public class ContainerMoistener extends ContainerLiquidTanks implements IContain this.tile = tile; // Stash - for (int l = 0; l < 2; l++) - for (int k1 = 0; k1 < 3; k1++) + for (int l = 0; l < 2; l++) { + for (int k1 = 0; k1 < 3; k1++) { addSlot(new Slot(tile, k1 + l * 3, 39 + k1 * 18, 16 + l * 18)); + } + } // Reservoir - for (int k1 = 0; k1 < 3; k1++) + for (int k1 = 0; k1 < 3; k1++) { addSlot(new Slot(tile, k1 + 6, 39 + k1 * 18, 22 + 36)); + } // Working slot this.addSlot(new SlotWorking(tile, 9, 105, 37)); @@ -47,12 +49,15 @@ public class ContainerMoistener extends ContainerLiquidTanks implements IContain // Player inventory int var3; - for (var3 = 0; var3 < 3; ++var3) - for (int var4 = 0; var4 < 9; ++var4) + for (var3 = 0; var3 < 3; ++var3) { + for (int var4 = 0; var4 < 9; ++var4) { this.addSlot(new Slot(player, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18)); + } + } - for (var3 = 0; var3 < 9; ++var3) + for (var3 = 0; var3 < 9; ++var3) { this.addSlot(new Slot(player, var3, 8 + var3 * 18, 142)); + } } @@ -62,9 +67,4 @@ public class ContainerMoistener extends ContainerLiquidTanks implements IContain tile.checkRecipe(); } - @Override - public boolean canInteractWith(EntityPlayer player) { - return this.tile.isUseableByPlayer(player); - } - } diff --git a/src/main/java/forestry/factory/gui/ContainerRaintank.java b/src/main/java/forestry/factory/gui/ContainerRaintank.java index ad0b0afa6..b3ade0028 100755 --- a/src/main/java/forestry/factory/gui/ContainerRaintank.java +++ b/src/main/java/forestry/factory/gui/ContainerRaintank.java @@ -10,9 +10,7 @@ ******************************************************************************/ package forestry.factory.gui; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; import forestry.core.gui.ContainerLiquidTanks; @@ -31,17 +29,16 @@ public class ContainerRaintank extends ContainerLiquidTanks { this.addSlot(new SlotLiquidContainer(tile, MachineRaintank.SLOT_RESOURCE, 116, 19, true)); this.addSlot(new SlotClosed(tile, MachineRaintank.SLOT_PRODUCT, 116, 55)); - for (int i = 0; i < 3; ++i) - for (int j = 0; j < 9; ++j) + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 9; ++j) { this.addSlot(new Slot(player, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); + } + } - for (int i = 0; i < 9; ++i) + for (int i = 0; i < 9; ++i) { this.addSlot(new Slot(player, i, 8 + i * 18, 142)); + } } - @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return tile.isUseableByPlayer(entityplayer); - } } diff --git a/src/main/java/forestry/factory/gui/ContainerStill.java b/src/main/java/forestry/factory/gui/ContainerStill.java index fa384ee0f..41dcb6217 100755 --- a/src/main/java/forestry/factory/gui/ContainerStill.java +++ b/src/main/java/forestry/factory/gui/ContainerStill.java @@ -10,9 +10,7 @@ ******************************************************************************/ package forestry.factory.gui; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; import forestry.core.gui.ContainerLiquidTanks; @@ -20,6 +18,7 @@ import forestry.core.gui.slots.SlotLiquidContainer; import forestry.factory.gadgets.MachineStill; public class ContainerStill extends ContainerLiquidTanks { + protected MachineStill processor; public ContainerStill(InventoryPlayer player, MachineStill tile) { @@ -30,17 +29,16 @@ public class ContainerStill extends ContainerLiquidTanks { this.addSlot(new SlotLiquidContainer(tile, MachineStill.SLOT_RESOURCE, 150, 18, true)); this.addSlot(new SlotLiquidContainer(tile, MachineStill.SLOT_CAN, 10, 36)); - for (int i = 0; i < 3; ++i) - for (int j = 0; j < 9; ++j) + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 9; ++j) { this.addSlot(new Slot(player, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); + } + } - for (int i = 0; i < 9; ++i) + for (int i = 0; i < 9; ++i) { this.addSlot(new Slot(player, i, 8 + i * 18, 142)); + } } - @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return processor.isUseableByPlayer(entityplayer); - } } diff --git a/src/main/java/forestry/farming/gadgets/TileFarm.java b/src/main/java/forestry/farming/gadgets/TileFarm.java index 15e94981e..e55409480 100755 --- a/src/main/java/forestry/farming/gadgets/TileFarm.java +++ b/src/main/java/forestry/farming/gadgets/TileFarm.java @@ -33,7 +33,7 @@ import forestry.core.network.GuiId; import forestry.core.network.PacketPayload; import forestry.core.proxy.Proxies; import forestry.core.render.TextureManager; -import forestry.core.utils.TileInventoryAdapter; +import forestry.core.inventory.TileInventoryAdapter; import forestry.core.utils.Utils; public abstract class TileFarm extends TileForestry implements IFarmComponent { diff --git a/src/main/java/forestry/farming/gadgets/TileFarmPlain.java b/src/main/java/forestry/farming/gadgets/TileFarmPlain.java index 0638c4766..5bf242b7e 100755 --- a/src/main/java/forestry/farming/gadgets/TileFarmPlain.java +++ b/src/main/java/forestry/farming/gadgets/TileFarmPlain.java @@ -60,10 +60,10 @@ import forestry.core.utils.DelayTimer; import forestry.core.fluids.tanks.StandardTank; import forestry.core.fluids.tanks.FilteredTank; import forestry.core.fluids.TankManager; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.LiquidHelper; import forestry.core.utils.StackUtils; -import forestry.core.utils.TileInventoryAdapter; +import forestry.core.inventory.TileInventoryAdapter; import forestry.core.utils.Vect; import forestry.farming.FarmTarget; import forestry.farming.logic.FarmLogicArboreal; diff --git a/src/main/java/forestry/farming/gadgets/TileHatch.java b/src/main/java/forestry/farming/gadgets/TileHatch.java index f80f814f0..117dc30fc 100755 --- a/src/main/java/forestry/farming/gadgets/TileHatch.java +++ b/src/main/java/forestry/farming/gadgets/TileHatch.java @@ -14,7 +14,7 @@ import buildcraft.api.statements.ITriggerExternal; import cpw.mods.fml.common.Optional; import forestry.api.core.ITileStructure; import forestry.core.utils.BlockUtil; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.StackUtils; import forestry.core.utils.Utils; import forestry.farming.triggers.FarmingTriggers; diff --git a/src/main/java/forestry/farming/gui/ContainerFarm.java b/src/main/java/forestry/farming/gui/ContainerFarm.java index b2e55fa4d..89ebd1148 100755 --- a/src/main/java/forestry/farming/gui/ContainerFarm.java +++ b/src/main/java/forestry/farming/gui/ContainerFarm.java @@ -24,7 +24,7 @@ import forestry.core.gui.slots.SlotCustom; import forestry.core.gui.slots.SlotForestry; import forestry.core.gui.slots.SlotLiquidContainer; import forestry.core.gui.slots.SlotOutput; -import forestry.core.utils.TileInventoryAdapter; +import forestry.core.inventory.TileInventoryAdapter; import forestry.farming.gadgets.TileFarmPlain; import forestry.plugins.PluginFarming; diff --git a/src/main/java/forestry/lepidopterology/items/ItemFlutterlyzer.java b/src/main/java/forestry/lepidopterology/items/ItemFlutterlyzer.java index a7f66e480..6375ab031 100755 --- a/src/main/java/forestry/lepidopterology/items/ItemFlutterlyzer.java +++ b/src/main/java/forestry/lepidopterology/items/ItemFlutterlyzer.java @@ -15,7 +15,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import forestry.core.utils.AlyzerInventory; +import forestry.core.inventory.AlyzerInventory; import forestry.api.core.ForestryAPI; import forestry.api.core.Tabs; import forestry.api.lepidopterology.IButterfly; diff --git a/src/main/java/forestry/mail/Letter.java b/src/main/java/forestry/mail/Letter.java index 237b93273..05f5610c9 100755 --- a/src/main/java/forestry/mail/Letter.java +++ b/src/main/java/forestry/mail/Letter.java @@ -20,7 +20,7 @@ import forestry.api.core.INBTTagable; import forestry.api.mail.ILetter; import forestry.api.mail.IStamps; import forestry.api.mail.IMailAddress; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.StringUtil; import org.apache.commons.lang3.StringUtils; diff --git a/src/main/java/forestry/mail/MailAddress.java b/src/main/java/forestry/mail/MailAddress.java index d5ea3a8fd..c76491e9e 100644 --- a/src/main/java/forestry/mail/MailAddress.java +++ b/src/main/java/forestry/mail/MailAddress.java @@ -23,6 +23,7 @@ import java.util.Locale; import java.util.UUID; public class MailAddress implements INBTTagable, IMailAddress { + private static final GameProfile invalidGameProfile = new GameProfile(new UUID(0, 0), ""); @EntityNetData private EnumAddressee type; @@ -47,17 +48,16 @@ public class MailAddress implements INBTTagable, IMailAddress { throw new IllegalArgumentException("name must not be null"); this.type = EnumAddressee.TRADER; - this.gameProfile = new GameProfile(new UUID(0, 0), name); + this.gameProfile = new GameProfile(null, name); } public MailAddress(IMailAddress address) { this.type = address.getType(); if (type == EnumAddressee.TRADER) { String name = address.getName(); - this.gameProfile = new GameProfile(new UUID(0, 0), name); - } else if (type == EnumAddressee.PLAYER) { + this.gameProfile = new GameProfile(null, name); + } else if (type == EnumAddressee.PLAYER) this.gameProfile = address.getPlayerProfile(); - } } public static MailAddress loadFromNBT(NBTTagCompound nbttagcompound) { @@ -100,7 +100,7 @@ public class MailAddress implements INBTTagable, IMailAddress { @Override public int hashCode() { - return gameProfile.hashCode(); + return gameProfile.getName().hashCode(); } @Override @@ -108,18 +108,28 @@ public class MailAddress implements INBTTagable, IMailAddress { if (!(o instanceof MailAddress)) return false; +<<<<<<< Updated upstream MailAddress address = (MailAddress) o; return PlayerUtil.isSameGameProfile(address.gameProfile, gameProfile); +======= + MailAddress other = (MailAddress) o; + return isSamePlayer(gameProfile, other.gameProfile); + } + + private static boolean isSamePlayer(GameProfile a, GameProfile b) { + if (a.getId() != null && b.getId() != null) + return a.getId().equals(b.getId()); + return a.getName() != null && a.getName().equals(b.getName()); +>>>>>>> Stashed changes } @Override public String toString() { String name = getName().toLowerCase(Locale.ENGLISH); - if (isPlayer()) { + if (isPlayer()) return type + "-" + name + "-" + gameProfile.getId(); - } else { + else return type + "-" + name; - } } @Override diff --git a/src/main/java/forestry/mail/POBox.java b/src/main/java/forestry/mail/POBox.java index 5fbc694f2..a229d5308 100755 --- a/src/main/java/forestry/mail/POBox.java +++ b/src/main/java/forestry/mail/POBox.java @@ -19,7 +19,7 @@ import net.minecraft.world.WorldSavedData; import forestry.api.mail.ILetter; import forestry.api.mail.PostManager; import forestry.api.mail.IMailAddress; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; public class POBox extends WorldSavedData implements IInventory { diff --git a/src/main/java/forestry/mail/PostRegistry.java b/src/main/java/forestry/mail/PostRegistry.java index 507f78daf..ac8761653 100755 --- a/src/main/java/forestry/mail/PostRegistry.java +++ b/src/main/java/forestry/mail/PostRegistry.java @@ -35,8 +35,13 @@ import forestry.plugins.PluginMail; public class PostRegistry implements IPostRegistry { public static PostOffice cachedPostOffice; +<<<<<<< Updated upstream public static final HashMap cachedPOBoxes = new HashMap(); public static final HashMap cachedTradeStations = new HashMap(); +======= + public static Map cachedPOBoxes = new HashMap(); + public static Map cachedTradeStations = new HashMap(); +>>>>>>> Stashed changes /** * @param world the Minecraft world the PO box will be in diff --git a/src/main/java/forestry/mail/TradeStation.java b/src/main/java/forestry/mail/TradeStation.java index 4325a891e..002014b2f 100755 --- a/src/main/java/forestry/mail/TradeStation.java +++ b/src/main/java/forestry/mail/TradeStation.java @@ -20,7 +20,7 @@ import forestry.api.mail.ITradeStation; import forestry.api.mail.PostManager; import forestry.api.mail.TradeStationInfo; import forestry.core.config.ForestryItem; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.PlayerUtil; import forestry.core.utils.StackUtils; import forestry.mail.items.ItemLetter; diff --git a/src/main/java/forestry/mail/gadgets/MachineMailbox.java b/src/main/java/forestry/mail/gadgets/MachineMailbox.java index 39fb314fb..b4e5facfe 100755 --- a/src/main/java/forestry/mail/gadgets/MachineMailbox.java +++ b/src/main/java/forestry/mail/gadgets/MachineMailbox.java @@ -23,7 +23,7 @@ import forestry.core.config.Config; import forestry.core.gadgets.TileBase; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.mail.EnumDeliveryState; import forestry.mail.IMailContainer; import forestry.mail.POBox; diff --git a/src/main/java/forestry/mail/gadgets/MachinePhilatelist.java b/src/main/java/forestry/mail/gadgets/MachinePhilatelist.java index 5352cf720..14f03818e 100755 --- a/src/main/java/forestry/mail/gadgets/MachinePhilatelist.java +++ b/src/main/java/forestry/mail/gadgets/MachinePhilatelist.java @@ -20,7 +20,7 @@ import forestry.api.mail.IStamps; import forestry.api.mail.PostManager; import forestry.core.gadgets.TileBase; import forestry.core.network.GuiId; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.StackUtils; public class MachinePhilatelist extends TileBase implements IInventory { diff --git a/src/main/java/forestry/mail/gadgets/MachineTrader.java b/src/main/java/forestry/mail/gadgets/MachineTrader.java index 224a2d780..7b813ef3a 100755 --- a/src/main/java/forestry/mail/gadgets/MachineTrader.java +++ b/src/main/java/forestry/mail/gadgets/MachineTrader.java @@ -22,7 +22,7 @@ import forestry.core.network.EntityNetData; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; import forestry.core.utils.EnumAccess; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.StackUtils; import forestry.mail.MailAddress; import forestry.mail.TradeStation; diff --git a/src/main/java/forestry/mail/gui/ContainerTradeName.java b/src/main/java/forestry/mail/gui/ContainerTradeName.java index b97913f2e..1ea386864 100755 --- a/src/main/java/forestry/mail/gui/ContainerTradeName.java +++ b/src/main/java/forestry/mail/gui/ContainerTradeName.java @@ -10,7 +10,6 @@ ******************************************************************************/ package forestry.mail.gui; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import forestry.core.gui.ContainerForestry; @@ -18,7 +17,7 @@ import forestry.core.network.PacketIds; import forestry.core.network.PacketPayload; import forestry.core.network.PacketUpdate; import forestry.core.proxy.Proxies; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.mail.gadgets.MachineTrader; import forestry.api.mail.PostManager; import forestry.api.mail.IMailAddress; @@ -61,9 +60,4 @@ public class ContainerTradeName extends ContainerForestry { machine.setAddress(address); } - @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return true; - } - } diff --git a/src/main/java/forestry/mail/gui/ContainerTrader.java b/src/main/java/forestry/mail/gui/ContainerTrader.java index 18d34328a..3e48c9d6d 100755 --- a/src/main/java/forestry/mail/gui/ContainerTrader.java +++ b/src/main/java/forestry/mail/gui/ContainerTrader.java @@ -10,7 +10,6 @@ ******************************************************************************/ package forestry.mail.gui; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Items; import net.minecraft.inventory.IInventory; @@ -37,11 +36,14 @@ public class ContainerTrader extends ContainerForestry { this.addSlot(new Slot(inventory, TradeStation.SLOT_TRADEGOOD, 78, 109)); // Exchange - for (int i = 0; i < 2; i++) - for (int j = 0; j < 2; j++) + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 2; j++) { addSlot(new Slot(inventory, TradeStation.SLOT_EXCHANGE_1 + j + i * 2, 69 + j * 18, 55 + i * 18)); + } + } // Stamps +<<<<<<< Updated upstream for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) addSlot(new SlotCustom(inventory, TradeStation.SLOT_STAMPS_1 + j + i * 2, 15 + j * 18, 37 + i * 18, ItemStamps.class)); @@ -50,24 +52,45 @@ public class ContainerTrader extends ContainerForestry { for (int i = 0; i < 3; i++) for (int j = 0; j < 2; j++) addSlot(new SlotCustom(inventory, TradeStation.SLOT_LETTERS_1 + j + i * 2, 15 + j * 18, 73 + i * 18, Items.paper)); +======= + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 2; j++) { + addSlot(new SlotCustom(inventory, TradeStation.SLOT_STAMPS_1 + j + i * 2, 15 + j * 18, 37 + i * 18, new Object[]{ItemStamps.class})); + } + } + + // Letters + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 2; j++) { + addSlot(new SlotCustom(inventory, TradeStation.SLOT_LETTERS_1 + j + i * 2, 15 + j * 18, 73 + i * 18, new Object[]{Items.paper})); + } + } +>>>>>>> Stashed changes // Buffers final int bufCols = 5; - for (int i = 0; i < 3; i++) - for (int j = 0; j < bufCols; j++) + for (int i = 0; i < 3; i++) { + for (int j = 0; j < bufCols; j++) { addSlot(new Slot(inventory, TradeStation.SLOT_RECEIVE_BUFFER + j + i * bufCols, 123 + j * 18, 19 + i * 18)); + } + } - for (int i = 0; i < 2; i++) - for (int j = 0; j < bufCols; j++) + for (int i = 0; i < 2; i++) { + for (int j = 0; j < bufCols; j++) { addSlot(new Slot(inventory, TradeStation.SLOT_SEND_BUFFER + j + i * bufCols, 123 + j * 18, (19 + (18 * 4)) + i * 18)); + } + } // Player inventory - for (int i = 0; i < 3; i++) - for (int j = 0; j < 9; j++) + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 9; j++) { addSlot(new Slot(player, j + i * 9 + 9, 33 + j * 18, 138 + i * 18)); + } + } // Player hotbar - for (int i = 0; i < 9; i++) + for (int i = 0; i < 9; i++) { addSlot(new Slot(player, i, 33 + i * 18, 196)); + } } @@ -79,8 +102,4 @@ public class ContainerTrader extends ContainerForestry { return machine.getAddress(); } - @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return true; - } } diff --git a/src/main/java/forestry/mail/items/ItemLetter.java b/src/main/java/forestry/mail/items/ItemLetter.java index d143399e1..f2002f732 100755 --- a/src/main/java/forestry/mail/items/ItemLetter.java +++ b/src/main/java/forestry/mail/items/ItemLetter.java @@ -33,7 +33,7 @@ import forestry.core.items.ItemInventoried; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; import forestry.core.render.TextureManager; -import forestry.core.utils.ItemInventory; +import forestry.core.inventory.ItemInventory; import forestry.core.utils.StringUtil; import forestry.mail.Letter; diff --git a/src/main/java/forestry/pipes/gui/ContainerPropolisPipe.java b/src/main/java/forestry/pipes/gui/ContainerPropolisPipe.java index 165d9c609..8af254003 100755 --- a/src/main/java/forestry/pipes/gui/ContainerPropolisPipe.java +++ b/src/main/java/forestry/pipes/gui/ContainerPropolisPipe.java @@ -6,15 +6,12 @@ * License 1.0, or MMPL. Please check the contents of the license located in * http://www.mod-buildcraft.com/MMPL-1.0.txt */ - package forestry.pipes.gui; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; -import buildcraft.transport.Pipe; import forestry.core.gui.ContainerForestry; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.pipes.PipeItemsPropolis; import forestry.pipes.PipeLogicPropolis; @@ -28,17 +25,15 @@ public class ContainerPropolisPipe extends ContainerForestry { this.playerIInventory = playerInventory; this.pipeLogic = pipe.pipeLogic; - for (int l = 0; l < 3; l++) - for (int k1 = 0; k1 < 9; k1++) + for (int l = 0; l < 3; l++) { + for (int k1 = 0; k1 < 9; k1++) { addSlot(new Slot(playerInventory, k1 + l * 9 + 9, 8 + k1 * 18, 140 + l * 18)); + } + } - for (int i1 = 0; i1 < 9; i1++) + for (int i1 = 0; i1 < 9; i1++) { addSlot(new Slot(playerInventory, i1, 8 + i1 * 18, 198)); - } - - @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return true; + } } } diff --git a/src/main/java/forestry/storage/GuiHandlerStorage.java b/src/main/java/forestry/storage/GuiHandlerStorage.java index 330452d45..835145b0c 100755 --- a/src/main/java/forestry/storage/GuiHandlerStorage.java +++ b/src/main/java/forestry/storage/GuiHandlerStorage.java @@ -23,7 +23,7 @@ import forestry.core.config.Defaults; import forestry.core.gui.GuiNaturalistInventory; import forestry.core.gui.IPagedInventory; import forestry.core.network.GuiId; -import forestry.core.utils.ItemInventory; +import forestry.core.inventory.ItemInventory; import forestry.storage.gui.ContainerBackpack; import forestry.storage.gui.ContainerNaturalistBackpack; import forestry.storage.gui.GuiBackpack; diff --git a/src/main/java/forestry/storage/ResupplyHandler.java b/src/main/java/forestry/storage/ResupplyHandler.java index 54be8eb05..aefbf8ba7 100755 --- a/src/main/java/forestry/storage/ResupplyHandler.java +++ b/src/main/java/forestry/storage/ResupplyHandler.java @@ -22,7 +22,7 @@ import forestry.api.storage.BackpackManager; import forestry.api.storage.BackpackResupplyEvent; import forestry.api.storage.IBackpackDefinition; import forestry.core.interfaces.IResupplyHandler; -import forestry.core.utils.ItemInventory; +import forestry.core.inventory.ItemInventory; import forestry.storage.items.ItemBackpack; public class ResupplyHandler implements IResupplyHandler { diff --git a/src/main/java/forestry/storage/gui/ContainerBackpack.java b/src/main/java/forestry/storage/gui/ContainerBackpack.java index 63d4ce780..0ce3de1f5 100755 --- a/src/main/java/forestry/storage/gui/ContainerBackpack.java +++ b/src/main/java/forestry/storage/gui/ContainerBackpack.java @@ -16,7 +16,7 @@ import net.minecraft.item.ItemStack; import forestry.core.config.Defaults; import forestry.core.gui.ContainerItemInventory; import forestry.core.gui.slots.SlotForestry; -import forestry.core.utils.ItemInventory; +import forestry.core.inventory.ItemInventory; import forestry.storage.items.ItemBackpack; public class ContainerBackpack extends ContainerItemInventory { diff --git a/src/main/java/forestry/storage/items/ItemBackpack.java b/src/main/java/forestry/storage/items/ItemBackpack.java index 871321ab8..b4dd85a75 100755 --- a/src/main/java/forestry/storage/items/ItemBackpack.java +++ b/src/main/java/forestry/storage/items/ItemBackpack.java @@ -40,7 +40,7 @@ import forestry.core.items.ItemInventoried; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; import forestry.core.render.TextureManager; -import forestry.core.utils.ItemInventory; +import forestry.core.inventory.ItemInventory; import forestry.core.utils.StringUtil; import forestry.storage.BackpackMode;