From b46fd3be72adb87d5aee4ca9514b600ab23277e1 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 17 Oct 2020 17:33:31 +0200 Subject: [PATCH] removed chest special handling (since it was fixed in Forge) and added getNeighborCap to PipeTileEntity --- .../ellpeck/prettypipes/network/PipeNetwork.java | 2 +- .../ellpeck/prettypipes/pipe/PipeTileEntity.java | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java b/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java index 169a3cd..ddccaec 100644 --- a/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java +++ b/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java @@ -299,7 +299,7 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL if (handler == null) continue; // check if this handler already exists (double-connected pipes, double chests etc.) - if (info.stream().anyMatch(l -> l.getItemHandler(this.world) == handler)) + if (info.stream().anyMatch(l -> handler.equals(l.getItemHandler(this.world)))) continue; NetworkLocation location = new NetworkLocation(dest, dir); if (!location.isEmpty(this.world)) diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java b/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java index afd4913..5069abe 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java @@ -302,19 +302,16 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide } public IItemHandler getItemHandler(Direction dir) { + return this.getNeighborCap(dir, CapabilityItemHandler.ITEM_HANDLER_CAPABILITY); + } + + public T getNeighborCap(Direction dir, Capability cap) { if (!this.isConnected(dir)) return null; BlockPos pos = this.pos.offset(dir); TileEntity tile = this.world.getTileEntity(pos); - if (tile != null) { - // if we don't do this, then chests get really weird - if (tile instanceof ChestTileEntity) { - BlockState state = this.world.getBlockState(tile.getPos()); - if (state.getBlock() instanceof ChestBlock) - return new InvWrapper(ChestBlock.getChestInventory((ChestBlock) state.getBlock(), state, this.world, tile.getPos(), true)); - } - return tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, dir.getOpposite()).orElse(null); - } + if (tile != null) + return tile.getCapability(cap, dir.getOpposite()).orElse(null); return null; }