mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-01-14 16:26:35 +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();
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue