From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Mon, 9 Aug 2021 20:45:46 -0700 Subject: [PATCH] Fire EntityChangeBlockEvent in more places Co-authored-by: ChristopheG <61288881+chrisgdt@users.noreply.github.com> diff --git a/src/main/java/net/minecraft/world/entity/LightningBolt.java b/src/main/java/net/minecraft/world/entity/LightningBolt.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/LightningBolt.java +++ b/src/main/java/net/minecraft/world/entity/LightningBolt.java @@ -0,0 +0,0 @@ public class LightningBolt extends Entity { } this.powerLightningRod(); - LightningBolt.clearCopperOnLightningStrike(this.level, this.getStrikePosition()); + LightningBolt.clearCopperOnLightningStrike(this.level, this.getStrikePosition(), this); // Paper - transmit LightningBolt instance to call EntityChangeBlockEvent this.gameEvent(GameEvent.LIGHTNING_STRIKE); } } @@ -0,0 +0,0 @@ public class LightningBolt extends Entity { } } - private static void clearCopperOnLightningStrike(Level world, BlockPos pos) { + private static void clearCopperOnLightningStrike(Level world, BlockPos pos, Entity lightning) { // Paper - transmit LightningBolt instance to call EntityChangeBlockEvent BlockState iblockdata = world.getBlockState(pos); BlockPos blockposition1; BlockState iblockdata1; @@ -0,0 +0,0 @@ public class LightningBolt extends Entity { } if (iblockdata1.getBlock() instanceof WeatheringCopper) { - world.setBlockAndUpdate(blockposition1, WeatheringCopper.getFirst(world.getBlockState(blockposition1))); + // Paper start - call EntityChangeBlockEvent + BlockState newBlock = WeatheringCopper.getFirst(world.getBlockState(blockposition1)); + if (!CraftEventFactory.callEntityChangeBlockEvent(lightning, blockposition1, newBlock).isCancelled()) { + world.setBlockAndUpdate(blockposition1, newBlock); + } + // Paper end BlockPos.MutableBlockPos blockposition_mutableblockposition = pos.mutable(); int i = world.random.nextInt(3) + 3; for (int j = 0; j < i; ++j) { int k = world.random.nextInt(8) + 1; - LightningBolt.randomWalkCleaningCopper(world, blockposition1, blockposition_mutableblockposition, k); + LightningBolt.randomWalkCleaningCopper(world, blockposition1, blockposition_mutableblockposition, k, lightning); // Paper - transmit LightningBolt instance to call EntityChangeBlockEvent } } } - private static void randomWalkCleaningCopper(Level world, BlockPos pos, BlockPos.MutableBlockPos mutablePos, int count) { + private static void randomWalkCleaningCopper(Level world, BlockPos pos, BlockPos.MutableBlockPos mutablePos, int count, Entity lightning) { // Paper - transmit LightningBolt instance to call EntityChangeBlockEvent mutablePos.set(pos); for (int j = 0; j < count; ++j) { - Optional optional = LightningBolt.randomStepCleaningCopper(world, mutablePos); + Optional optional = LightningBolt.randomStepCleaningCopper(world, mutablePos, lightning); // Paper - transmit LightningBolt instance to call EntityChangeBlockEvent if (!optional.isPresent()) { break; @@ -0,0 +0,0 @@ public class LightningBolt extends Entity { } - private static Optional randomStepCleaningCopper(Level world, BlockPos pos) { + private static Optional randomStepCleaningCopper(Level world, BlockPos pos, Entity lightning) { // Paper - transmit LightningBolt instance to call EntityChangeBlockEvent Iterator iterator = BlockPos.randomInCube(world.random, 10, pos, 1).iterator(); BlockPos blockposition1; @@ -0,0 +0,0 @@ public class LightningBolt extends Entity { BlockPos blockposition1Final = blockposition1; // CraftBukkit - decompile error WeatheringCopper.getPrevious(iblockdata).ifPresent((iblockdata1) -> { + if (!CraftEventFactory.callEntityChangeBlockEvent(lightning, blockposition1Final, iblockdata1).isCancelled()) // Paper - call EntityChangeBlockEvent world.setBlockAndUpdate(blockposition1Final, iblockdata1); // CraftBukkit - decompile error }); world.levelEvent(3002, blockposition1, -1); diff --git a/src/main/java/net/minecraft/world/item/AxeItem.java b/src/main/java/net/minecraft/world/item/AxeItem.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/item/AxeItem.java +++ b/src/main/java/net/minecraft/world/item/AxeItem.java @@ -0,0 +0,0 @@ public class AxeItem extends DiggerItem { } if (optional4.isPresent()) { + // Paper start - EntityChangeBlockEvent + if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(player, blockPos, optional4.get()).isCancelled()) { + return InteractionResult.PASS; + } + // Paper end if (player instanceof ServerPlayer) { CriteriaTriggers.ITEM_USED_ON_BLOCK.trigger((ServerPlayer)player, blockPos, itemStack); } diff --git a/src/main/java/net/minecraft/world/item/HoneycombItem.java b/src/main/java/net/minecraft/world/item/HoneycombItem.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/item/HoneycombItem.java +++ b/src/main/java/net/minecraft/world/item/HoneycombItem.java @@ -0,0 +0,0 @@ public class HoneycombItem extends Item { return getWaxed(blockState).map((state) -> { Player player = context.getPlayer(); ItemStack itemStack = context.getItemInHand(); + // Paper start - EntityChangeBlockEvent + if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(player, blockPos, state).isCancelled()) { + return InteractionResult.PASS; + } + // Paper end if (player instanceof ServerPlayer) { CriteriaTriggers.ITEM_USED_ON_BLOCK.trigger((ServerPlayer)player, blockPos, itemStack); } diff --git a/src/main/java/net/minecraft/world/item/ShovelItem.java b/src/main/java/net/minecraft/world/item/ShovelItem.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/item/ShovelItem.java +++ b/src/main/java/net/minecraft/world/item/ShovelItem.java @@ -0,0 +0,0 @@ public class ShovelItem extends DiggerItem { Player player = context.getPlayer(); BlockState blockState2 = FLATTENABLES.get(blockState.getBlock()); BlockState blockState3 = null; + Runnable afterAction = null; // Paper if (blockState2 != null && level.getBlockState(blockPos.above()).isAir()) { - level.playSound(player, blockPos, SoundEvents.SHOVEL_FLATTEN, SoundSource.BLOCKS, 1.0F, 1.0F); + afterAction = () -> level.playSound(player, blockPos, SoundEvents.SHOVEL_FLATTEN, SoundSource.BLOCKS, 1.0F, 1.0F); // Paper blockState3 = blockState2; } else if (blockState.getBlock() instanceof CampfireBlock && blockState.getValue(CampfireBlock.LIT)) { + afterAction = () -> { // Paper if (!level.isClientSide()) { level.levelEvent((Player)null, 1009, blockPos, 0); } CampfireBlock.dowse(context.getPlayer(), level, blockPos, blockState); + }; // Paper blockState3 = blockState.setValue(CampfireBlock.LIT, Boolean.valueOf(false)); } if (blockState3 != null) { if (!level.isClientSide) { + // Paper start + if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(context.getPlayer(), blockPos, blockState3).isCancelled()) { + return InteractionResult.PASS; + } + afterAction.run(); + // Paper end level.setBlock(blockPos, blockState3, 11); level.gameEvent(GameEvent.BLOCK_CHANGE, blockPos, GameEvent.Context.of(player, blockState3)); if (player != null) { diff --git a/src/main/java/net/minecraft/world/level/block/ComposterBlock.java b/src/main/java/net/minecraft/world/level/block/ComposterBlock.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/level/block/ComposterBlock.java +++ b/src/main/java/net/minecraft/world/level/block/ComposterBlock.java @@ -0,0 +0,0 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder { if (i < 8 && ComposterBlock.COMPOSTABLES.containsKey(itemstack.getItem())) { if (i < 7 && !world.isClientSide) { - BlockState iblockdata1 = ComposterBlock.addItem(state, world, pos, itemstack); + // Paper start - EntityChangeBlockEvent + double rand = world.getRandom().nextDouble(); + BlockState dummyBlockState = ComposterBlock.addItem(state, org.bukkit.craftbukkit.util.DummyGeneratorAccess.INSTANCE, pos, itemstack, rand); + if (state != dummyBlockState && org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(player, pos, dummyBlockState).isCancelled()) { // if block state will change and event cancelled + return InteractionResult.sidedSuccess(world.isClientSide); + } + BlockState iblockdata1 = ComposterBlock.addItem(state, world, pos, itemstack, rand); + // Paper end world.levelEvent(1500, pos, state != iblockdata1 ? 1 : 0); player.awardStat(Stats.ITEM_USED.get(itemstack.getItem()));