From 23195e1e1ff61ad72a42de8356f7dd5eda81648f Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Sun, 26 Dec 2021 11:43:19 +0300 Subject: [PATCH] Fix: breaking a shell container not by a player didn't work correctly Fixes #19 --- .../kir/sync/block/AbstractShellContainerBlock.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/dev/kir/sync/block/AbstractShellContainerBlock.java b/src/main/java/dev/kir/sync/block/AbstractShellContainerBlock.java index 2a204e9..e6d613a 100644 --- a/src/main/java/dev/kir/sync/block/AbstractShellContainerBlock.java +++ b/src/main/java/dev/kir/sync/block/AbstractShellContainerBlock.java @@ -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); @@ -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))) {