Refactor IWrenchable.onSneakWrenched

This commit is contained in:
simibubi 2024-07-16 19:15:45 +02:00
parent f67341df7e
commit c05e366dc7

View file

@ -56,21 +56,26 @@ public interface IWrenchable {
Level world = context.getLevel(); Level world = context.getLevel();
BlockPos pos = context.getClickedPos(); BlockPos pos = context.getClickedPos();
Player player = context.getPlayer(); Player player = context.getPlayer();
if (world instanceof ServerLevel) {
if (!(world instanceof ServerLevel serverLevel))
return InteractionResult.SUCCESS;
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, world.getBlockState(pos), player); BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, world.getBlockState(pos), player);
MinecraftForge.EVENT_BUS.post(event); MinecraftForge.EVENT_BUS.post(event);
if (!event.isCanceled()) { if (event.isCanceled())
return InteractionResult.SUCCESS;
if (player != null && !player.isCreative()) { if (player != null && !player.isCreative()) {
Block.getDrops(state, (ServerLevel) world, pos, world.getBlockEntity(pos), player, context.getItemInHand()) Block.getDrops(state, serverLevel, pos, world.getBlockEntity(pos), player, context.getItemInHand())
.forEach(itemStack -> { .forEach(itemStack -> {
player.getInventory().placeItemBackInInventory(itemStack); player.getInventory()
.placeItemBackInInventory(itemStack);
}); });
} }
state.spawnAfterBreak((ServerLevel) world, pos, ItemStack.EMPTY);
state.spawnAfterBreak(serverLevel, pos, ItemStack.EMPTY);
world.destroyBlock(pos, false); world.destroyBlock(pos, false);
playRemoveSound(world, pos); playRemoveSound(world, pos);
}
}
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
} }