diff --git a/src/main/java/de/ellpeck/prettypipes/items/WrenchItem.java b/src/main/java/de/ellpeck/prettypipes/items/WrenchItem.java index 2bc84d6..77586cd 100644 --- a/src/main/java/de/ellpeck/prettypipes/items/WrenchItem.java +++ b/src/main/java/de/ellpeck/prettypipes/items/WrenchItem.java @@ -45,11 +45,10 @@ public class WrenchItem extends Item { if (!world.isClientSide) { if (tile.cover != null) { // remove the cover - tile.removeCover(player, context.getHand()); + tile.removeCover(); Utility.sendBlockEntityToClients(tile); } else { // remove the pipe - PipeBlock.dropItems(world, pos, player); Block.dropResources(state, world, pos, tile, null, ItemStack.EMPTY); world.removeBlock(pos, false); } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java index 169fe32..5832ef6 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java @@ -263,7 +263,12 @@ public class PipeBlock extends BaseEntityBlock implements SimpleWaterloggedBlock network.removeNode(pos); network.onPipeChanged(pos, state); if (worldIn.getBlockEntity(pos) instanceof PipeBlockEntity pipe) { + Utility.dropInventory(pipe, pipe.modules); + for (var item : pipe.getItems()) + item.drop(worldIn, item.getContent()); pipe.getItems().clear(); + if (pipe.cover != null) + pipe.removeCover(); for (var craft : pipe.getActiveCrafts()) { for (var lock : craft.ingredientsToRequest) network.resolveNetworkLock(lock); @@ -273,12 +278,6 @@ public class PipeBlock extends BaseEntityBlock implements SimpleWaterloggedBlock } } - @Override - public BlockState playerWillDestroy(Level worldIn, BlockPos pos, BlockState state, Player player) { - PipeBlock.dropItems(worldIn, pos, player); - return super.playerWillDestroy(worldIn, pos, state, player); - } - @Override public boolean hasAnalogOutputSignal(BlockState state) { return true; @@ -320,15 +319,4 @@ public class PipeBlock extends BaseEntityBlock implements SimpleWaterloggedBlock return BaseEntityBlock.createTickerHelper(type, Registry.pipeBlockEntity, PipeBlockEntity::tick); } - public static void dropItems(Level worldIn, BlockPos pos, Player player) { - var tile = Utility.getBlockEntity(PipeBlockEntity.class, worldIn, pos); - if (tile != null) { - Utility.dropInventory(tile, tile.modules); - for (var item : tile.getItems()) - item.drop(worldIn, item.getContent()); - if (tile.cover != null) - tile.removeCover(player, InteractionHand.MAIN_HAND); - } - } - } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlockEntity.java b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlockEntity.java index 58631d0..7d51e26 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlockEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlockEntity.java @@ -353,10 +353,10 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC return -1; } - public void removeCover(Player player, InteractionHand hand) { + public void removeCover() { if (this.level.isClientSide) return; - var drops = Block.getDrops(this.cover, (ServerLevel) this.level, this.worldPosition, null, player, player.getItemInHand(hand)); + var drops = Block.getDrops(this.cover, (ServerLevel) this.level, this.worldPosition, null); for (var drop : drops) Containers.dropItemStack(this.level, this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), drop); this.cover = null;