From c05e366dc7928283c558126ee5a7e6bb96202af0 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Tue, 16 Jul 2024 19:15:45 +0200 Subject: [PATCH] Refactor IWrenchable.onSneakWrenched --- .../content/equipment/wrench/IWrenchable.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/equipment/wrench/IWrenchable.java b/src/main/java/com/simibubi/create/content/equipment/wrench/IWrenchable.java index 232a9dd5e..8abcca734 100644 --- a/src/main/java/com/simibubi/create/content/equipment/wrench/IWrenchable.java +++ b/src/main/java/com/simibubi/create/content/equipment/wrench/IWrenchable.java @@ -56,21 +56,26 @@ public interface IWrenchable { Level world = context.getLevel(); BlockPos pos = context.getClickedPos(); Player player = context.getPlayer(); - if (world instanceof ServerLevel) { - BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, world.getBlockState(pos), player); - MinecraftForge.EVENT_BUS.post(event); - if (!event.isCanceled()) { - if (player != null && !player.isCreative()) { - Block.getDrops(state, (ServerLevel) world, pos, world.getBlockEntity(pos), player, context.getItemInHand()) - .forEach(itemStack -> { - player.getInventory().placeItemBackInInventory(itemStack); - }); - } - state.spawnAfterBreak((ServerLevel) world, pos, ItemStack.EMPTY); - world.destroyBlock(pos, false); - playRemoveSound(world, pos); - } + + if (!(world instanceof ServerLevel serverLevel)) + return InteractionResult.SUCCESS; + + BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, world.getBlockState(pos), player); + MinecraftForge.EVENT_BUS.post(event); + if (event.isCanceled()) + return InteractionResult.SUCCESS; + + if (player != null && !player.isCreative()) { + Block.getDrops(state, serverLevel, pos, world.getBlockEntity(pos), player, context.getItemInHand()) + .forEach(itemStack -> { + player.getInventory() + .placeItemBackInInventory(itemStack); + }); } + + state.spawnAfterBreak(serverLevel, pos, ItemStack.EMPTY); + world.destroyBlock(pos, false); + playRemoveSound(world, pos); return InteractionResult.SUCCESS; }