#402 Item conduits not working correctly with double chests.

This commit is contained in:
CrazyPants committed 2014-01-18 10:55:47 +08:00
1 parent af45a9922c
commit ae577a0e6a
3 files changed
+48 -3

No files matched your search

@@ -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<IItemConduit> {
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<IItemConduit> {
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<IItemConduit> {
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;
+6 -2
View File
@@ -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();
+24 -1
View File
@@ -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;
}
}