diff --git a/nms-patches/EntityEgg.patch b/nms-patches/EntityEgg.patch index 424dd94aad..9b33c184c6 100644 --- a/nms-patches/EntityEgg.patch +++ b/nms-patches/EntityEgg.patch @@ -13,7 +13,7 @@ public class EntityEgg extends EntityProjectile { public EntityEgg(World world) { -@@ -19,21 +26,36 @@ +@@ -19,21 +26,37 @@ movingobjectposition.entity.damageEntity(DamageSource.projectile(this, this.getShooter()), 0.0F); } @@ -53,10 +53,11 @@ - } + if (hatching) { + for (int k = 0; k < numHatching; k++) { -+ org.bukkit.entity.Entity entity = world.getWorld().spawn(new org.bukkit.Location(world.getWorld(), this.locX, this.locY, this.locZ, this.yaw, 0.0F), hatchingType.getEntityClass(), org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.EGG); -+ if (entity instanceof Ageable) { -+ ((Ageable) entity).setBaby(); ++ Entity entity = world.getWorld().createEntity(new org.bukkit.Location(world.getWorld(), this.locX, this.locY, this.locZ, this.yaw, 0.0F), hatchingType.getEntityClass()); ++ if (entity.getBukkitEntity() instanceof Ageable) { ++ ((Ageable) entity.getBukkitEntity()).setBaby(); + } ++ world.getWorld().addEntity(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.EGG); + } } + // CraftBukkit end diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 9e158e15d3..8c9ead5570 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -1,5 +1,6 @@ package org.bukkit.craftbukkit; +import com.google.common.base.Preconditions; import java.io.File; import java.util.ArrayList; import java.util.Collection; @@ -882,7 +883,7 @@ public class CraftWorld implements World { } @SuppressWarnings("unchecked") - public T spawn(Location location, Class clazz, SpawnReason reason) throws IllegalArgumentException { + public net.minecraft.server.Entity createEntity(Location location, Class clazz) throws IllegalArgumentException { if (location == null || clazz == null) { throw new IllegalArgumentException("Location or entity class cannot be null"); } @@ -1108,17 +1109,30 @@ public class CraftWorld implements World { } if (entity != null) { - if (entity instanceof EntityInsentient) { - ((EntityInsentient) entity).prepare(getHandle().E(new BlockPosition(entity)), (GroupDataEntity) null); - } - - world.addEntity(entity, reason); - return (T) entity.getBukkitEntity(); + return entity; } throw new IllegalArgumentException("Cannot spawn an entity for " + clazz.getName()); } + @SuppressWarnings("unchecked") + public T addEntity(net.minecraft.server.Entity entity, SpawnReason reason) throws IllegalArgumentException { + Preconditions.checkArgument(entity != null, "Cannot spawn null entity"); + + if (entity instanceof EntityInsentient) { + ((EntityInsentient) entity).prepare(getHandle().E(new BlockPosition(entity)), (GroupDataEntity) null); + } + + world.addEntity(entity, reason); + return (T) entity.getBukkitEntity(); + } + + public T spawn(Location location, Class clazz, SpawnReason reason) throws IllegalArgumentException { + net.minecraft.server.Entity entity = createEntity(location, clazz); + + return addEntity(entity, reason); + } + public ChunkSnapshot getEmptyChunkSnapshot(int x, int z, boolean includeBiome, boolean includeBiomeTempRain) { return CraftChunk.getEmptyChunkSnapshot(x, z, this, includeBiome, includeBiomeTempRain); }