2021-03-16 09:00:00 +11:00
--- a/net/minecraft/world/entity/item/EntityFallingBlock.java
+++ b/net/minecraft/world/entity/item/EntityFallingBlock.java
2024-06-14 01:05:00 +10:00
@@ -52,6 +52,11 @@
2021-03-16 09:00:00 +11:00
import net.minecraft.world.phys.Vec3D;
2022-03-01 02:00:00 +11:00
import org.slf4j.Logger;
2014-11-26 08:32:16 +11:00
2023-06-24 17:15:05 +10:00
+// CraftBukkit start;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
2024-02-21 20:55:34 +11:00
+import org.bukkit.event.entity.EntityRemoveEvent;
2023-06-24 17:15:05 +10:00
+// CraftBukkit end
2014-11-26 08:32:16 +11:00
+
public class EntityFallingBlock extends Entity {
2022-03-01 02:00:00 +11:00
private static final Logger LOGGER = LogUtils.getLogger();
2024-06-14 01:05:00 +10:00
@@ -87,10 +92,17 @@
2022-04-18 11:05:12 +10:00
}
2022-03-11 16:24:02 +11:00
public static EntityFallingBlock fall(World world, BlockPosition blockposition, IBlockData iblockdata) {
2022-04-18 11:05:12 +10:00
+ // CraftBukkit start
2022-04-18 11:05:15 +10:00
+ return fall(world, blockposition, iblockdata, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT);
2022-04-18 11:05:12 +10:00
+ }
+
2022-04-18 11:05:15 +10:00
+ public static EntityFallingBlock fall(World world, BlockPosition blockposition, IBlockData iblockdata, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) {
2022-04-18 11:05:12 +10:00
+ // CraftBukkit end
2022-03-11 16:24:02 +11:00
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);
2023-06-24 17:15:05 +10:00
+ if (!CraftEventFactory.callEntityChangeBlockEvent(entityfallingblock, blockposition, iblockdata.getFluidState().createLegacyBlock())) return entityfallingblock; // CraftBukkit
2022-03-11 16:24:02 +11:00
world.setBlock(blockposition, iblockdata.getFluidState().createLegacyBlock(), 3);
2022-04-18 11:05:12 +10:00
- world.addFreshEntity(entityfallingblock);
2022-04-18 11:05:15 +10:00
+ world.addFreshEntity(entityfallingblock, spawnReason); // CraftBukkit
2022-04-18 11:05:12 +10:00
return entityfallingblock;
}
2024-06-14 01:05:00 +10:00
@@ -130,7 +142,7 @@
2024-02-21 20:55:34 +11:00
@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();
2024-06-14 01:05:00 +10:00
@@ -159,7 +171,7 @@
2024-02-21 20:55:34 +11:00
this.spawnAtLocation((IMaterial) block);
}
- this.discard();
+ this.discard(EntityRemoveEvent.Cause.DROP); // CraftBukkit - add Bukkit remove cause
}
} else {
IBlockData iblockdata = this.level().getBlockState(blockposition);
2024-06-14 01:05:00 +10:00
@@ -176,9 +188,15 @@
2021-11-22 09:00:00 +11:00
this.blockState = (IBlockData) this.blockState.setValue(BlockProperties.WATERLOGGED, true);
2019-04-23 12:00:00 +10:00
}
2016-03-22 18:04:02 +11:00
2019-04-23 12:00:00 +10:00
+ // CraftBukkit start
2023-06-24 17:15:05 +10:00
+ if (!CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, this.blockState)) {
2024-02-21 20:55:34 +11:00
+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // SPIGOT-6586 called before the event in previous versions
2015-02-26 22:41:06 +00:00
+ return;
+ }
+ // CraftBukkit end
2023-06-08 01:30:00 +10:00
if (this.level().setBlock(blockposition, this.blockState, 3)) {
((WorldServer) this.level()).getChunkSource().chunkMap.broadcast(this, new PacketPlayOutBlockChange(blockposition, this.level().getBlockState(blockposition)));
2024-02-21 20:55:34 +11:00
- this.discard();
+ this.discard(EntityRemoveEvent.Cause.DESPAWN);
if (block instanceof Fallable) {
((Fallable) block).onLand(this.level(), blockposition, this.blockState, iblockdata, this);
}
2024-06-14 01:05:00 +10:00
@@ -206,19 +224,19 @@
2024-02-21 20:55:34 +11:00
}
}
} 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);
}
}