diff options
author | md_5 <git@md-5.net> | 2015-06-12 16:00:08 +1000 |
---|---|---|
committer | md_5 <git@md-5.net> | 2015-06-21 09:20:07 +1000 |
commit | 994b2aae3f9988d87fe89614083108ca194e6236 (patch) | |
tree | bf3950f1f1c6965166df156670553e507ce38f7c | |
parent | 0dfb243c86eb2a1e214f5d7b7a43291381412d30 (diff) | |
download | craftbukkit-994b2aae3f9988d87fe89614083108ca194e6236.tar craftbukkit-994b2aae3f9988d87fe89614083108ca194e6236.tar.gz craftbukkit-994b2aae3f9988d87fe89614083108ca194e6236.tar.lz craftbukkit-994b2aae3f9988d87fe89614083108ca194e6236.tar.xz craftbukkit-994b2aae3f9988d87fe89614083108ca194e6236.zip |
SPIGOT-892: Set chicken egg baby age before adding it to world.
-rw-r--r-- | nms-patches/EntityEgg.patch | 9 | ||||
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/CraftWorld.java | 28 |
2 files changed, 26 insertions, 11 deletions
diff --git a/nms-patches/EntityEgg.patch b/nms-patches/EntityEgg.patch index 424dd94a..9b33c184 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 9e158e15..8c9ead55 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 extends Entity> T spawn(Location location, Class<T> clazz, SpawnReason reason) throws IllegalArgumentException { + public net.minecraft.server.Entity createEntity(Location location, Class<? extends Entity> 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 extends Entity> 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 extends Entity> T spawn(Location location, Class<T> 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); } |