diff --git a/common/crazypants/enderio/conduit/item/ItemConduitNetwork.java b/common/crazypants/enderio/conduit/item/ItemConduitNetwork.java index 3c1e7f13..0a610430 100644 --- a/common/crazypants/enderio/conduit/item/ItemConduitNetwork.java +++ b/common/crazypants/enderio/conduit/item/ItemConduitNetwork.java @@ -10,6 +10,7 @@ import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityChest; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import crazypants.enderio.conduit.AbstractConduitNetwork; @@ -138,6 +139,11 @@ public class ItemConduitNetwork extends AbstractConduitNetwork { int tickDeficit; + //work around for a vanilla chest changing into a double chest without doing unnedded checks all the time + boolean recheckInv = false; + private int delay = 0; + IInventory origInv; + NetworkedInventory(IInventory inv, IItemConduit con, ForgeDirection conDir, BlockCoord location) { inventorySide = conDir.getOpposite().ordinal(); @@ -149,6 +155,9 @@ public class ItemConduitNetwork extends AbstractConduitNetwork { if(inv instanceof ISidedInventory) { this.inv = (ISidedInventory) inv; } else { + if(inv instanceof TileEntityChest) { + recheckInv = true; + } this.inv = new InventoryWrapper(inv); } @@ -205,6 +214,15 @@ public class ItemConduitNetwork extends AbstractConduitNetwork { private boolean transferItems() { + if(recheckInv) { + //Re-check vanilla chests twice a second to make sure they haven't become double chests + delay++; + if(delay % 10 == 0) { + inv = new InventoryWrapper(((InventoryWrapper) inv).getWrappedInv()); + delay = 0; + } + } + int[] slotIndices = inv.getAccessibleSlotsFromSide(inventorySide); if(slotIndices == null) { return false; diff --git a/common/crazypants/util/InventoryWrapper.java b/common/crazypants/util/InventoryWrapper.java index f801d246..4a94b04c 100644 --- a/common/crazypants/util/InventoryWrapper.java +++ b/common/crazypants/util/InventoryWrapper.java @@ -21,13 +21,17 @@ public class InventoryWrapper implements ISidedInventory { private int[] slots; public InventoryWrapper(IInventory inventory) { - this.inv = inventory; - slots = new int[inventory.getSizeInventory()]; + this.inv = ItemUtil.getInventory(inventory); + slots = new int[inv.getSizeInventory()]; for (int i = 0; i < slots.length; i++) { slots[i] = i; } } + public IInventory getWrappedInv() { + return inv; + } + @Override public int getSizeInventory() { return inv.getSizeInventory(); diff --git a/common/crazypants/util/ItemUtil.java b/common/crazypants/util/ItemUtil.java index a04214ab..ba9af532 100644 --- a/common/crazypants/util/ItemUtil.java +++ b/common/crazypants/util/ItemUtil.java @@ -2,7 +2,9 @@ package crazypants.util; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; +import net.minecraft.inventory.InventoryLargeChest; import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntityChest; import net.minecraftforge.common.ForgeDirection; import buildcraft.api.transport.IPipeTile; import cofh.api.transport.IItemConduit; @@ -16,7 +18,7 @@ public class ItemUtil { if(into instanceof ISidedInventory) { return ItemUtil.doInsertItem((ISidedInventory) into, item, side); } else if(into instanceof IInventory) { - return ItemUtil.doInsertItem((IInventory) into, item); + return ItemUtil.doInsertItem(getInventory((IInventory) into), item); } else if(into instanceof IItemConduit) { return ItemUtil.doInsertItem((IItemConduit) into, item, side); } else if(into instanceof IPipeTile) { @@ -122,4 +124,25 @@ public class ItemUtil { return contents.stackSize >= contents.getMaxStackSize(); } + public static IInventory getInventory(IInventory inv) { + if(inv instanceof TileEntityChest) { + TileEntityChest chest = (TileEntityChest) inv; + TileEntityChest neigbour = null; + if(chest.adjacentChestXNeg != null) { + neigbour = chest.adjacentChestXNeg; + } else if(chest.adjacentChestXPos != null) { + neigbour = chest.adjacentChestXPos; + } else if(chest.adjacentChestZNeg != null) { + neigbour = chest.adjacentChestZNeg; + } else if(chest.adjacentChestZPosition != null) { + neigbour = chest.adjacentChestZPosition; + } + if(neigbour != null) { + return new InventoryLargeChest("", inv, neigbour); + } + return inv; + } + return inv; + } + }