mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-07 11:05:13 +01:00
SPIGOT-7001: Fix entity already exists in CraftWorld#spawnFallingBlock
By: Doc <nachito94@msn.com>
This commit is contained in:
parent
e935d60d1d
commit
14aabc2648
2 changed files with 19 additions and 14 deletions
|
@ -9,15 +9,26 @@
|
||||||
public class EntityFallingBlock extends Entity {
|
public class EntityFallingBlock extends Entity {
|
||||||
|
|
||||||
private static final Logger LOGGER = LogUtils.getLogger();
|
private static final Logger LOGGER = LogUtils.getLogger();
|
||||||
@@ -81,6 +83,7 @@
|
@@ -80,10 +82,17 @@
|
||||||
|
}
|
||||||
|
|
||||||
public static EntityFallingBlock fall(World world, BlockPosition blockposition, IBlockData iblockdata) {
|
public static EntityFallingBlock fall(World world, BlockPosition blockposition, IBlockData iblockdata) {
|
||||||
|
+ // CraftBukkit start
|
||||||
|
+ return fall(world, blockposition, iblockdata, false);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public static EntityFallingBlock fall(World world, BlockPosition blockposition, IBlockData iblockdata, boolean isCustom) {
|
||||||
|
+ // 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);
|
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()).isCancelled()) return entityfallingblock; // CraftBukkit
|
+ if (CraftEventFactory.callEntityChangeBlockEvent(entityfallingblock, blockposition, iblockdata.getFluidState().createLegacyBlock()).isCancelled()) return entityfallingblock; // CraftBukkit
|
||||||
|
|
||||||
world.setBlock(blockposition, iblockdata.getFluidState().createLegacyBlock(), 3);
|
world.setBlock(blockposition, iblockdata.getFluidState().createLegacyBlock(), 3);
|
||||||
world.addFreshEntity(entityfallingblock);
|
- world.addFreshEntity(entityfallingblock);
|
||||||
@@ -166,6 +169,12 @@
|
+ world.addFreshEntity(entityfallingblock, (isCustom) ? org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.CUSTOM : org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT); // CraftBukkit - keep logic in SpawnReason if the method is use by API
|
||||||
|
return entityfallingblock;
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -166,6 +175,12 @@
|
||||||
this.blockState = (IBlockData) this.blockState.setValue(BlockProperties.WATERLOGGED, true);
|
this.blockState = (IBlockData) this.blockState.setValue(BlockProperties.WATERLOGGED, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +41,7 @@
|
||||||
if (this.level.setBlock(blockposition, this.blockState, 3)) {
|
if (this.level.setBlock(blockposition, this.blockState, 3)) {
|
||||||
((WorldServer) this.level).getChunkSource().chunkMap.broadcast(this, new PacketPlayOutBlockChange(blockposition, this.level.getBlockState(blockposition)));
|
((WorldServer) this.level).getChunkSource().chunkMap.broadcast(this, new PacketPlayOutBlockChange(blockposition, this.level.getBlockState(blockposition)));
|
||||||
this.discard();
|
this.discard();
|
||||||
@@ -236,7 +245,7 @@
|
@@ -236,7 +251,7 @@
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -39,7 +50,7 @@
|
||||||
DamageSource damagesource1;
|
DamageSource damagesource1;
|
||||||
|
|
||||||
if (this.blockState.getBlock() instanceof Fallable) {
|
if (this.blockState.getBlock() instanceof Fallable) {
|
||||||
@@ -252,7 +261,9 @@
|
@@ -252,7 +267,9 @@
|
||||||
float f2 = (float) Math.min(MathHelper.floor((float) i * this.fallDamagePerDistance), this.fallDamageMax);
|
float f2 = (float) Math.min(MathHelper.floor((float) i * this.fallDamagePerDistance), this.fallDamageMax);
|
||||||
|
|
||||||
this.level.getEntities((Entity) this, this.getBoundingBox(), predicate).forEach((entity) -> {
|
this.level.getEntities((Entity) this, this.getBoundingBox(), predicate).forEach((entity) -> {
|
||||||
|
|
|
@ -1145,22 +1145,16 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||||
Validate.notNull(material, "Material cannot be null");
|
Validate.notNull(material, "Material cannot be null");
|
||||||
Validate.isTrue(material.isBlock(), "Material must be a block");
|
Validate.isTrue(material.isBlock(), "Material must be a block");
|
||||||
|
|
||||||
EntityFallingBlock entity = EntityFallingBlock.fall(world, new BlockPosition(location.getX(), location.getY(), location.getZ()), CraftMagicNumbers.getBlock(material).defaultBlockState());
|
EntityFallingBlock entity = EntityFallingBlock.fall(world, new BlockPosition(location.getX(), location.getY(), location.getZ()), CraftMagicNumbers.getBlock(material).defaultBlockState(), true);
|
||||||
entity.time = 1;
|
|
||||||
|
|
||||||
world.addFreshEntity(entity, SpawnReason.CUSTOM);
|
|
||||||
return (FallingBlock) entity.getBukkitEntity();
|
return (FallingBlock) entity.getBukkitEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FallingBlock spawnFallingBlock(Location location, BlockData data) throws IllegalArgumentException {
|
public FallingBlock spawnFallingBlock(Location location, BlockData data) throws IllegalArgumentException {
|
||||||
Validate.notNull(location, "Location cannot be null");
|
Validate.notNull(location, "Location cannot be null");
|
||||||
Validate.notNull(data, "Material cannot be null");
|
Validate.notNull(data, "BlockData cannot be null");
|
||||||
|
|
||||||
EntityFallingBlock entity = EntityFallingBlock.fall(world, new BlockPosition(location.getX(), location.getY(), location.getZ()), ((CraftBlockData) data).getState());
|
EntityFallingBlock entity = EntityFallingBlock.fall(world, new BlockPosition(location.getX(), location.getY(), location.getZ()), ((CraftBlockData) data).getState(), true);
|
||||||
entity.time = 1;
|
|
||||||
|
|
||||||
world.addFreshEntity(entity, SpawnReason.CUSTOM);
|
|
||||||
return (FallingBlock) entity.getBukkitEntity();
|
return (FallingBlock) entity.getBukkitEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue