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) {
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, world.getBlockState(pos), player); if (!(world instanceof ServerLevel serverLevel))
MinecraftForge.EVENT_BUS.post(event); return InteractionResult.SUCCESS;
if (!event.isCanceled()) {
if (player != null && !player.isCreative()) { BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, world.getBlockState(pos), player);
Block.getDrops(state, (ServerLevel) world, pos, world.getBlockEntity(pos), player, context.getItemInHand()) MinecraftForge.EVENT_BUS.post(event);
.forEach(itemStack -> { if (event.isCanceled())
player.getInventory().placeItemBackInInventory(itemStack); return InteractionResult.SUCCESS;
});
} if (player != null && !player.isCreative()) {
state.spawnAfterBreak((ServerLevel) world, pos, ItemStack.EMPTY); Block.getDrops(state, serverLevel, pos, world.getBlockEntity(pos), player, context.getItemInHand())
world.destroyBlock(pos, false); .forEach(itemStack -> {
playRemoveSound(world, pos); player.getInventory()
} .placeItemBackInInventory(itemStack);
});
} }
state.spawnAfterBreak(serverLevel, pos, ItemStack.EMPTY);
world.destroyBlock(pos, false);
playRemoveSound(world, pos);
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
} }