--- a/net/minecraft/world/entity/item/EntityFallingBlock.java +++ b/net/minecraft/world/entity/item/EntityFallingBlock.java @@ -52,6 +52,11 @@ import net.minecraft.world.phys.Vec3D; import org.slf4j.Logger; +// CraftBukkit start; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.event.entity.EntityRemoveEvent; +// CraftBukkit end + public class EntityFallingBlock extends Entity { private static final Logger LOGGER = LogUtils.getLogger(); @@ -87,10 +92,17 @@ } public static EntityFallingBlock fall(World world, BlockPosition blockposition, IBlockData iblockdata) { + // CraftBukkit start + return fall(world, blockposition, iblockdata, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT); + } + + public static EntityFallingBlock fall(World world, BlockPosition blockposition, IBlockData iblockdata, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) { + // CraftBukkit end EntityFallingBlock entityfallingblock = new EntityFallingBlock(world, (double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D, iblockdata.hasProperty(BlockProperties.WATERLOGGED) ? (IBlockData) iblockdata.setValue(BlockProperties.WATERLOGGED, false) : iblockdata); + if (!CraftEventFactory.callEntityChangeBlockEvent(entityfallingblock, blockposition, iblockdata.getFluidState().createLegacyBlock())) return entityfallingblock; // CraftBukkit world.setBlock(blockposition, iblockdata.getFluidState().createLegacyBlock(), 3); - world.addFreshEntity(entityfallingblock); + world.addFreshEntity(entityfallingblock, spawnReason); // CraftBukkit return entityfallingblock; } @@ -130,7 +142,7 @@ @Override public void tick() { if (this.blockState.isAir()) { - this.discard(); + this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause } else { Block block = this.blockState.getBlock(); @@ -159,7 +171,7 @@ this.spawnAtLocation((IMaterial) block); } - this.discard(); + this.discard(EntityRemoveEvent.Cause.DROP); // CraftBukkit - add Bukkit remove cause } } else { IBlockData iblockdata = this.level().getBlockState(blockposition); @@ -176,9 +188,15 @@ this.blockState = (IBlockData) this.blockState.setValue(BlockProperties.WATERLOGGED, true); } + // CraftBukkit start + if (!CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, this.blockState)) { + this.discard(EntityRemoveEvent.Cause.DESPAWN); // SPIGOT-6586 called before the event in previous versions + return; + } + // CraftBukkit end if (this.level().setBlock(blockposition, this.blockState, 3)) { ((WorldServer) this.level()).getChunkSource().chunkMap.broadcast(this, new PacketPlayOutBlockChange(blockposition, this.level().getBlockState(blockposition))); - this.discard(); + this.discard(EntityRemoveEvent.Cause.DESPAWN); if (block instanceof Fallable) { ((Fallable) block).onLand(this.level(), blockposition, this.blockState, iblockdata, this); } @@ -206,19 +224,19 @@ } } } else if (this.dropItem && this.level().getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) { - this.discard(); + this.discard(EntityRemoveEvent.Cause.DROP); // CraftBukkit - add Bukkit remove cause this.callOnBrokenAfterFall(block, blockposition); this.spawnAtLocation((IMaterial) block); } } else { - this.discard(); + this.discard(EntityRemoveEvent.Cause.DROP); // CraftBukkit - add Bukkit remove cause if (this.dropItem && this.level().getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) { this.callOnBrokenAfterFall(block, blockposition); this.spawnAtLocation((IMaterial) block); } } } else { - this.discard(); + this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause this.callOnBrokenAfterFall(block, blockposition); } }