mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2025-01-10 07:07:42 +01:00
use general capabilities when querying storage blocks, rather than tile-specific ones
This commit is contained in:
parent
8894d1d8c4
commit
4d0e484c08
3 changed files with 11 additions and 38 deletions
|
@ -147,17 +147,6 @@ public final class Utility {
|
||||||
e.connection.send(packet);
|
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) {
|
public static BlockPos readBlockPos(Tag tag) {
|
||||||
if (tag instanceof IntArrayTag i) {
|
if (tag instanceof IntArrayTag i) {
|
||||||
int[] arr = i.getAsIntArray();
|
int[] arr = i.getAsIntArray();
|
||||||
|
|
|
@ -199,26 +199,20 @@ public class PipeBlock extends BaseEntityBlock implements SimpleWaterloggedBlock
|
||||||
return state;
|
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);
|
var offset = pos.relative(direction);
|
||||||
if (!world.isLoaded(offset))
|
if (!world.isLoaded(offset))
|
||||||
return ConnectionType.DISCONNECTED;
|
return ConnectionType.DISCONNECTED;
|
||||||
var opposite = direction.getOpposite();
|
var opposite = direction.getOpposite();
|
||||||
var tile = world.getBlockEntity(offset);
|
var connectable = world.getCapability(Registry.pipeConnectableCapability, offset, null, null, opposite);
|
||||||
if (tile != null) {
|
|
||||||
var connectable = world.getCapability(Registry.pipeConnectableCapability, offset, tile.getBlockState(), tile, opposite);
|
|
||||||
if (connectable != null)
|
if (connectable != null)
|
||||||
return connectable.getConnectionType(pos, direction);
|
return connectable.getConnectionType(pos, direction);
|
||||||
var handler = world.getCapability(Capabilities.ItemHandler.BLOCK, offset, tile.getBlockState(), tile, opposite);
|
var handler = world.getCapability(Capabilities.ItemHandler.BLOCK, offset, null, null, opposite);
|
||||||
if (handler != null)
|
if (handler != null)
|
||||||
return ConnectionType.CONNECTED;
|
return ConnectionType.CONNECTED;
|
||||||
}
|
|
||||||
var blockHandler = Utility.getBlockItemHandler(world, offset, opposite);
|
|
||||||
if (blockHandler != null)
|
|
||||||
return ConnectionType.CONNECTED;
|
|
||||||
var offState = world.getBlockState(offset);
|
var offState = world.getBlockState(offset);
|
||||||
if (PipeBlock.hasLegsTo(world, offState, offset, direction)) {
|
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.LEGS;
|
||||||
}
|
}
|
||||||
return ConnectionType.DISCONNECTED;
|
return ConnectionType.DISCONNECTED;
|
||||||
|
|
|
@ -307,27 +307,17 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
|
||||||
}
|
}
|
||||||
|
|
||||||
public IItemHandler getItemHandler(Direction dir) {
|
public IItemHandler getItemHandler(Direction dir) {
|
||||||
var handler = this.getNeighborCap(dir, Capabilities.ItemHandler.BLOCK);
|
return this.getNeighborCap(dir, Capabilities.ItemHandler.BLOCK);
|
||||||
if (handler != null)
|
|
||||||
return handler;
|
|
||||||
return Utility.getBlockItemHandler(this.level, this.worldPosition.relative(dir), dir.getOpposite());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T, C> T getNeighborCap(Direction dir, BlockCapability<T, Direction> cap) {
|
public <T> T getNeighborCap(Direction dir, BlockCapability<T, Direction> cap) {
|
||||||
if (!this.isConnected(dir))
|
if (!this.isConnected(dir))
|
||||||
return null;
|
return null;
|
||||||
var pos = this.worldPosition.relative(dir);
|
return this.level.getCapability(cap, this.worldPosition.relative(dir), null, null, dir.getOpposite());
|
||||||
var tile = this.level.getBlockEntity(pos);
|
|
||||||
if (tile != null)
|
|
||||||
return this.level.getCapability(cap, tile.getBlockPos(), tile.getBlockState(), tile, dir.getOpposite());
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IPipeConnectable getPipeConnectable(Direction dir) {
|
public IPipeConnectable getPipeConnectable(Direction dir) {
|
||||||
var tile = this.level.getBlockEntity(this.worldPosition.relative(dir));
|
return this.level.getCapability(Registry.pipeConnectableCapability, this.worldPosition.relative(dir), null, null, dir.getOpposite());
|
||||||
if (tile != null)
|
|
||||||
return this.level.getCapability(Registry.pipeConnectableCapability, tile.getBlockPos(), tile.getBlockState(), tile, dir.getOpposite());
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canHaveModules() {
|
public boolean canHaveModules() {
|
||||||
|
|
Loading…
Reference in a new issue