Implement SpawnReason.NETHER_PORTAL and DISPENSE_EGG. Fixes BUKKIT-3148

Previously any entities spawned through dispensers (monster eggs) or
by nether portals were given the incorrect SpawnReason of SPAWNER_EGG.
This made it impossible to distinguish what exactly happened in regards
to the creature being spawned.

A method in ItemMonsterEgg has been added to further fine tune reasons
for spawning creatures. This permits the DISPENSE_EGG reason to be used
correctly and accuratly as well as the NETHER_PORTAL reason due to how
BlockPortal spawns the mobs.

The redirected method, a(World, int, double, double, double), is still
called by the ItemMonsterEgg itself and therefore uses the default reason
of SPAWNER_EGG. This does not change previous behaviour.
Dieser Commit ist enthalten in:
Kodekpl 2014-01-31 12:07:39 +01:00 committet von turt2live
Ursprung c59ba98ae6
Commit 3e896afe6b
3 geänderte Dateien mit 10 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -23,7 +23,8 @@ public class BlockPortal extends BlockHalfTransparent {
} }
if (l > 0 && !world.getType(i, l + 1, k).r()) { if (l > 0 && !world.getType(i, l + 1, k).r()) {
Entity entity = ItemMonsterEgg.a(world, 57, (double) i + 0.5D, (double) l + 1.1D, (double) k + 0.5D); // CraftBukkit - set spawn reason to NETHER_PORTAL
Entity entity = ItemMonsterEgg.spawnCreature(world, 57, (double) i + 0.5D, (double) l + 1.1D, (double) k + 0.5D, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NETHER_PORTAL);
if (entity != null) { if (entity != null) {
entity.portalCooldown = entity.ai(); entity.portalCooldown = entity.ai();

Datei anzeigen

@ -44,7 +44,7 @@ final class DispenseBehaviorMonsterEgg extends DispenseBehaviorItem {
itemstack1 = CraftItemStack.asNMSCopy(event.getItem()); itemstack1 = CraftItemStack.asNMSCopy(event.getItem());
Entity entity = ItemMonsterEgg.a(isourceblock.k(), itemstack.getData(), event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ()); Entity entity = ItemMonsterEgg.spawnCreature(isourceblock.k(), itemstack.getData(), event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DISPENSE_EGG);
if (entity instanceof EntityLiving && itemstack.hasName()) { if (entity instanceof EntityLiving && itemstack.hasName()) {
((EntityInsentient) entity).setCustomName(itemstack.getName()); ((EntityInsentient) entity).setCustomName(itemstack.getName());

Datei anzeigen

@ -92,6 +92,12 @@ public class ItemMonsterEgg extends Item {
} }
public static Entity a(World world, int i, double d0, double d1, double d2) { public static Entity a(World world, int i, double d0, double d1, double d2) {
// CraftBukkit start - delegate to spawnCreature
return spawnCreature(world, i, d0, d1, d2, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER_EGG);
}
public static Entity spawnCreature(World world, int i, double d0, double d1, double d2, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) {
// CraftBukkit end
if (!EntityTypes.a.containsKey(Integer.valueOf(i))) { if (!EntityTypes.a.containsKey(Integer.valueOf(i))) {
return null; return null;
} else { } else {
@ -106,7 +112,7 @@ public class ItemMonsterEgg extends Item {
entityinsentient.aP = entityinsentient.yaw; entityinsentient.aP = entityinsentient.yaw;
entityinsentient.aN = entityinsentient.yaw; entityinsentient.aN = entityinsentient.yaw;
entityinsentient.a((GroupDataEntity) null); entityinsentient.a((GroupDataEntity) null);
world.addEntity(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER_EGG); // CraftBukkit world.addEntity(entity, spawnReason); // CraftBukkit
entityinsentient.r(); entityinsentient.r();
} }
} }