From e4daa5a7968270a78017b7ed4666a13b7ed5e301 Mon Sep 17 00:00:00 2001 From: Worive <13164341+Worive@users.noreply.github.com> Date: Sun, 2 Nov 2025 10:50:55 +0100 Subject: [PATCH 1/2] Improve NetworkedInventory robustness Replaced the hardcoded inventory re-check logic with a universal TileEntity validity check. By caching the TileEntity and using isInvalid(), conduits can now automatically detect when a connected block is broken or replaced, allowing them to reconnect seamlessly. --- .../conduit/item/NetworkedInventory.java | 61 ++++++++++++------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/src/main/java/crazypants/enderio/conduit/item/NetworkedInventory.java b/src/main/java/crazypants/enderio/conduit/item/NetworkedInventory.java index 76cf2d68..a171e373 100644 --- a/src/main/java/crazypants/enderio/conduit/item/NetworkedInventory.java +++ b/src/main/java/crazypants/enderio/conduit/item/NetworkedInventory.java @@ -10,7 +10,6 @@ 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.util.StatCollector; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; @@ -41,8 +40,8 @@ public class NetworkedInventory { int tickDeficit; - // work around for a vanilla chest changing into a double chest without doing unneeded checks all the time - boolean recheckInv = false; + private TileEntity te; + // Hack for TiC crafting station not working correctly when setting output slot to null boolean ticHack = false; @@ -61,19 +60,13 @@ public class NetworkedInventory { this.location = location; world = con.getBundle().getWorld(); - TileEntity te = world.getTileEntity(location.x, location.y, location.z); - if (te.getClass().getName().equals("tconstruct.tools.logic.CraftingStationLogic")) { - ticHack = true; - } else if (te.getClass().getName().contains("cpw.mods.ironchest")) { - recheckInv = true; - } else if (te instanceof TileEntityChest) { - recheckInv = true; - } else if (te instanceof TileInventoryPanel) { - inventoryPanel = true; - } updateInventory(); } + public boolean isInvalid() { + return te == null || te.isInvalid(); + } + public boolean hasTarget(IItemConduit conduit, ForgeDirection dir) { for (Target t : sendPriority) { if (t.inv.con == conduit && t.inv.conDir == dir) { @@ -110,6 +103,13 @@ public class NetworkedInventory { } public void onTick() { + if (isInvalid()) { + updateInventory(); + if (isInvalid()) { + return; + } + } + if (tickDeficit > 0 || !canExtract() || !con.isExtractionRedstoneConditionMet(conDir)) { // do nothing } else { @@ -144,11 +144,6 @@ public class NetworkedInventory { } private boolean transferItems() { - - if (recheckInv) { - updateInventory(); - } - int[] slotIndices = getInventory().getAccessibleSlotsFromSide(inventorySide); if (slotIndices == null) { return false; @@ -257,9 +252,6 @@ public class NetworkedInventory { matchedStickyInput = of != null && of.isValid() && of.doesItemPassFilter(this, toExtract); } if (target.stickyInput || !matchedStickyInput) { - if (target.inv.recheckInv) { - target.inv.updateInventory(); - } int inserted = target.inv.insertItem(toExtract); if (inserted > 0) { toExtract.stackSize -= inserted; @@ -281,15 +273,38 @@ public class NetworkedInventory { } public final void updateInventory() { - TileEntity te = world.getTileEntity(location.x, location.y, location.z); + TileEntity newTe = world.getTileEntity(location.x, location.y, location.z); + if (newTe != te) { + te = newTe; + ticHack = false; + inventoryPanel = false; + if (te != null) { + if (te.getClass().getName().equals("tconstruct.tools.logic.CraftingStationLogic")) { + ticHack = true; + } else if (te instanceof TileInventoryPanel) { + inventoryPanel = true; + } + } + network.routesChanged(); + } + if (te instanceof ISidedInventory) { inv = (ISidedInventory) te; } else if (te instanceof IInventory) { inv = new InventoryWrapper((IInventory) te); + } else { + inv = null; } } private int insertItem(ItemStack item) { + if (isInvalid()) { + updateInventory(); + if (isInvalid()) { + return 0; + } + } + if (!canInsert() || item == null) { return 0; } @@ -410,7 +425,7 @@ public class NetworkedInventory { } public ISidedInventory getInventoryRecheck() { - if (recheckInv) { + if (isInvalid()) { updateInventory(); } return inv; From 7f8c7ca5bc305ef671ea589dceaa3d7efbbd2896 Mon Sep 17 00:00:00 2001 From: Worive <13164341+Worive@users.noreply.github.com> Date: Tue, 4 Nov 2025 18:26:07 +0100 Subject: [PATCH 2/2] Rename attribute for more clarity --- .../conduit/item/NetworkedInventory.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/crazypants/enderio/conduit/item/NetworkedInventory.java b/src/main/java/crazypants/enderio/conduit/item/NetworkedInventory.java index a171e373..96068858 100644 --- a/src/main/java/crazypants/enderio/conduit/item/NetworkedInventory.java +++ b/src/main/java/crazypants/enderio/conduit/item/NetworkedInventory.java @@ -40,7 +40,7 @@ public class NetworkedInventory { int tickDeficit; - private TileEntity te; + private TileEntity connectedTileEntity; // Hack for TiC crafting station not working correctly when setting output slot to null boolean ticHack = false; @@ -64,7 +64,7 @@ public class NetworkedInventory { } public boolean isInvalid() { - return te == null || te.isInvalid(); + return connectedTileEntity == null || connectedTileEntity.isInvalid(); } public boolean hasTarget(IItemConduit conduit, ForgeDirection dir) { @@ -274,24 +274,24 @@ public class NetworkedInventory { public final void updateInventory() { TileEntity newTe = world.getTileEntity(location.x, location.y, location.z); - if (newTe != te) { - te = newTe; + if (newTe != connectedTileEntity) { + connectedTileEntity = newTe; ticHack = false; inventoryPanel = false; - if (te != null) { - if (te.getClass().getName().equals("tconstruct.tools.logic.CraftingStationLogic")) { + if (connectedTileEntity != null) { + if (connectedTileEntity.getClass().getName().equals("tconstruct.tools.logic.CraftingStationLogic")) { ticHack = true; - } else if (te instanceof TileInventoryPanel) { + } else if (connectedTileEntity instanceof TileInventoryPanel) { inventoryPanel = true; } } network.routesChanged(); } - if (te instanceof ISidedInventory) { - inv = (ISidedInventory) te; - } else if (te instanceof IInventory) { - inv = new InventoryWrapper((IInventory) te); + if (connectedTileEntity instanceof ISidedInventory) { + inv = (ISidedInventory) connectedTileEntity; + } else if (connectedTileEntity instanceof IInventory) { + inv = new InventoryWrapper((IInventory) connectedTileEntity); } else { inv = null; }