Skip to content

Commit

Permalink
Fix: breaking a shell container not by a player didn't work correctly
Browse files Browse the repository at this point in the history
Fixes #19
  • Loading branch information
Kir-Antipov committed Dec 26, 2021
1 parent 99adac6 commit 23195e1
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/main/java/dev/kir/sync/block/AbstractShellContainerBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ public void onEntityCollision(BlockState state, World world, BlockPos pos, Entit
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
boolean bottom = isBottom(state);
BlockPos bottomPos = bottom ? pos : pos.down();
if (world.getBlockEntity(bottomPos) instanceof AbstractShellContainerBlockEntity shellContainer) {
shellContainer.onBreak(world, bottomPos);
}
if (!world.isClient && player.isCreative()) {
if (!bottom) {
BlockState blockState = world.getBlockState(bottomPos);
Expand All @@ -145,6 +142,16 @@ public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity pl
super.onBreak(world, pos, state, player);
}

@Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
if (!state.isOf(newState.getBlock())) {
if (isBottom(state) && world.getBlockEntity(pos) instanceof AbstractShellContainerBlockEntity shellContainer) {
shellContainer.onBreak(world, pos);
}
world.removeBlockEntity(pos);
}
}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (ItemUtil.isWrench(player.getStackInHand(hand))) {
Expand Down

0 comments on commit 23195e1

Please sign in to comment.