diff --git a/src/main/java/de/ellpeck/prettypipes/Utility.java b/src/main/java/de/ellpeck/prettypipes/Utility.java index 9dd5ab2..bc49d87 100644 --- a/src/main/java/de/ellpeck/prettypipes/Utility.java +++ b/src/main/java/de/ellpeck/prettypipes/Utility.java @@ -147,17 +147,6 @@ public final class Utility { e.connection.send(packet); } - public static IItemHandler getBlockItemHandler(Level world, BlockPos pos, Direction direction) { - var state = world.getBlockState(pos); - var block = state.getBlock(); - if (!(block instanceof WorldlyContainerHolder holder)) - return null; - var inventory = holder.getContainer(state, world, pos); - if (inventory == null) - return null; - return new SidedInvWrapper(inventory, direction); - } - public static BlockPos readBlockPos(Tag tag) { if (tag instanceof IntArrayTag i) { int[] arr = i.getAsIntArray(); diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java index 9e108b3..169fe32 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java @@ -199,26 +199,20 @@ public class PipeBlock extends BaseEntityBlock implements SimpleWaterloggedBlock return state; } - protected ConnectionType getConnectionType(Level world, BlockPos pos, Direction direction, BlockState state) { + protected ConnectionType getConnectionType(Level world, BlockPos pos, Direction direction, BlockState pipeState) { var offset = pos.relative(direction); if (!world.isLoaded(offset)) return ConnectionType.DISCONNECTED; var opposite = direction.getOpposite(); - var tile = world.getBlockEntity(offset); - if (tile != null) { - var connectable = world.getCapability(Registry.pipeConnectableCapability, offset, tile.getBlockState(), tile, opposite); - if (connectable != null) - return connectable.getConnectionType(pos, direction); - var handler = world.getCapability(Capabilities.ItemHandler.BLOCK, offset, tile.getBlockState(), tile, opposite); - if (handler != null) - return ConnectionType.CONNECTED; - } - var blockHandler = Utility.getBlockItemHandler(world, offset, opposite); - if (blockHandler != null) + var connectable = world.getCapability(Registry.pipeConnectableCapability, offset, null, null, opposite); + if (connectable != null) + return connectable.getConnectionType(pos, direction); + var handler = world.getCapability(Capabilities.ItemHandler.BLOCK, offset, null, null, opposite); + if (handler != null) return ConnectionType.CONNECTED; var offState = world.getBlockState(offset); if (PipeBlock.hasLegsTo(world, offState, offset, direction)) { - if (PipeBlock.DIRECTIONS.values().stream().noneMatch(d -> state.getValue(d) == ConnectionType.LEGS)) + if (PipeBlock.DIRECTIONS.values().stream().noneMatch(d -> pipeState.getValue(d) == ConnectionType.LEGS)) return ConnectionType.LEGS; } return ConnectionType.DISCONNECTED; diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlockEntity.java b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlockEntity.java index 09bb625..58631d0 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlockEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlockEntity.java @@ -307,27 +307,17 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC } public IItemHandler getItemHandler(Direction dir) { - var handler = this.getNeighborCap(dir, Capabilities.ItemHandler.BLOCK); - if (handler != null) - return handler; - return Utility.getBlockItemHandler(this.level, this.worldPosition.relative(dir), dir.getOpposite()); + return this.getNeighborCap(dir, Capabilities.ItemHandler.BLOCK); } - public T getNeighborCap(Direction dir, BlockCapability cap) { + public T getNeighborCap(Direction dir, BlockCapability cap) { if (!this.isConnected(dir)) return null; - var pos = this.worldPosition.relative(dir); - var tile = this.level.getBlockEntity(pos); - if (tile != null) - return this.level.getCapability(cap, tile.getBlockPos(), tile.getBlockState(), tile, dir.getOpposite()); - return null; + return this.level.getCapability(cap, this.worldPosition.relative(dir), null, null, dir.getOpposite()); } public IPipeConnectable getPipeConnectable(Direction dir) { - var tile = this.level.getBlockEntity(this.worldPosition.relative(dir)); - if (tile != null) - return this.level.getCapability(Registry.pipeConnectableCapability, tile.getBlockPos(), tile.getBlockState(), tile, dir.getOpposite()); - return null; + return this.level.getCapability(Registry.pipeConnectableCapability, this.worldPosition.relative(dir), null, null, dir.getOpposite()); } public boolean canHaveModules() {