mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-01-14 00:06:52 +01:00
Refactor IWrenchable.onSneakWrenched
This commit is contained in:
parent
f67341df7e
commit
c05e366dc7
1 changed files with 19 additions and 14 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue