Skip to content

Commit

Permalink
Fix crash when placing a channel by clicking the bottom of another ch…
Browse files Browse the repository at this point in the history
…annel (#73)
  • Loading branch information
KnightMiner committed Mar 10, 2021
1 parent ca17c6a commit a61b820
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/main/java/knightminer/ceramics/blocks/ChannelBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,22 +192,24 @@ public BlockState getStateForPlacement(BlockItemUseContext context) {
BlockState state = this.getDefaultState().with(POWERED, world.isBlockPowered(pos));
Direction side = context.getFace();

// we cannot connect upwards, so done here
if (side == Direction.DOWN) {
return state;
}
// if placed on the top face, try to connect down
if (side == Direction.UP) {
return state.with(DOWN, canConnect(world, pos, Direction.DOWN));
}

// if placed on a fluid handler, connect to that
ChannelConnection connection = ChannelConnection.NONE;
if (side != Direction.DOWN) {
BlockPos placedOn = pos.offset(side.getOpposite());
// on another channel means in or out
if (world.getBlockState(placedOn).isIn(this)) {
PlayerEntity player = context.getPlayer();
connection = player != null && player.isSneaking() ? ChannelConnection.IN : ChannelConnection.OUT;
} else if (isFluidHandler(world, side, placedOn)) {
connection = ChannelConnection.OUT;
}
BlockPos placedOn = pos.offset(side.getOpposite());
// on another channel means in or out
if (world.getBlockState(placedOn).isIn(this)) {
PlayerEntity player = context.getPlayer();
connection = player != null && player.isSneaking() ? ChannelConnection.IN : ChannelConnection.OUT;
} else if (isFluidHandler(world, side, placedOn)) {
connection = ChannelConnection.OUT;
}
return state.with(DIRECTION_MAP.get(side.getOpposite()), connection);
}
Expand Down

0 comments on commit a61b820

Please sign in to comment.