--- a/net/minecraft/world/entity/LightningBolt.java +++ b/net/minecraft/world/entity/LightningBolt.java @@ -30,6 +30,10 @@ import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; +// CraftBukkit start +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.event.entity.EntityRemoveEvent; +// CraftBukkit end public class LightningBolt extends Entity { @@ -94,7 +98,7 @@ } this.powerLightningRod(); - LightningBolt.clearCopperOnLightningStrike(this.level(), this.getStrikePosition()); + LightningBolt.clearCopperOnLightningStrike(this.level(), this.getStrikePosition(), this); // Paper - Call EntityChangeBlockEvent this.gameEvent(GameEvent.LIGHTNING_STRIKE); } } @@ -120,7 +124,7 @@ } } - this.discard(); + this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause } else if (this.life < -this.random.nextInt(10)) { --this.flashes; this.life = 1; @@ -129,7 +133,7 @@ } } - if (this.life >= 0) { + if (this.life >= 0 && !this.visualOnly) { // CraftBukkit - add !this.visualOnly if (!(this.level() instanceof ServerLevel)) { this.level().setSkyFlashTime(2); } else if (!this.visualOnly) { @@ -169,8 +173,12 @@ BlockState iblockdata = BaseFireBlock.getState(this.level(), blockposition); if (this.level().getBlockState(blockposition).isAir() && iblockdata.canSurvive(this.level(), blockposition)) { - this.level().setBlockAndUpdate(blockposition, iblockdata); - ++this.blocksSetOnFire; + // CraftBukkit start - add "!visualOnly" + if (!this.visualOnly && !CraftEventFactory.callBlockIgniteEvent(this.level(), blockposition, this).isCancelled()) { + this.level().setBlockAndUpdate(blockposition, iblockdata); + ++this.blocksSetOnFire; + } + // CraftBukkit end } for (int j = 0; j < spreadAttempts; ++j) { @@ -178,8 +186,12 @@ iblockdata = BaseFireBlock.getState(this.level(), blockposition1); if (this.level().getBlockState(blockposition1).isAir() && iblockdata.canSurvive(this.level(), blockposition1)) { - this.level().setBlockAndUpdate(blockposition1, iblockdata); - ++this.blocksSetOnFire; + // CraftBukkit start - add "!visualOnly" + if (!this.visualOnly && !CraftEventFactory.callBlockIgniteEvent(this.level(), blockposition1, this).isCancelled()) { + this.level().setBlockAndUpdate(blockposition1, iblockdata); + ++this.blocksSetOnFire; + } + // CraftBukkit end } } @@ -190,7 +202,7 @@ } - private static void clearCopperOnLightningStrike(Level world, BlockPos pos) { + private static void clearCopperOnLightningStrike(Level world, BlockPos pos, Entity lightning) { // Paper - Call EntityChangeBlockEvent BlockState iblockdata = world.getBlockState(pos); BlockPos blockposition1; BlockState iblockdata1; @@ -204,24 +216,29 @@ } 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)) { + world.setBlockAndUpdate(blockposition1, newBlock); + } + // Paper end - Call EntityChangeBlockEvent 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.isEmpty()) { break; @@ -232,7 +249,7 @@ } - 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; @@ -247,8 +264,10 @@ iblockdata = world.getBlockState(blockposition1); } while (!(iblockdata.getBlock() instanceof WeatheringCopper)); + BlockPos blockposition1Final = blockposition1; // CraftBukkit - decompile error WeatheringCopper.getPrevious(iblockdata).ifPresent((iblockdata1) -> { - world.setBlockAndUpdate(blockposition1, iblockdata1); + if (CraftEventFactory.callEntityChangeBlockEvent(lightning, blockposition1Final, iblockdata1)) // Paper - call EntityChangeBlockEvent + world.setBlockAndUpdate(blockposition1Final, iblockdata1); // CraftBukkit - decompile error }); world.levelEvent(3002, blockposition1, -1); return Optional.of(blockposition1);