diff options
author | aPunch <theapunch@yahoo.com> | 2012-03-19 14:12:17 -0500 |
---|---|---|
committer | EvilSeph <evilseph@gmail.com> | 2012-03-21 16:05:07 -0400 |
commit | 169c2ee8cb9ee12bcfbbde11bf764b0cc0503a32 (patch) | |
tree | b0d8121c390fd86a7d530d4a739834d3cd15b993 | |
parent | 96c4bb7da641fda5be5c8110fb432c31b50c2aa4 (diff) | |
download | craftbukkit-169c2ee8cb9ee12bcfbbde11bf764b0cc0503a32.tar craftbukkit-169c2ee8cb9ee12bcfbbde11bf764b0cc0503a32.tar.gz craftbukkit-169c2ee8cb9ee12bcfbbde11bf764b0cc0503a32.tar.lz craftbukkit-169c2ee8cb9ee12bcfbbde11bf764b0cc0503a32.tar.xz craftbukkit-169c2ee8cb9ee12bcfbbde11bf764b0cc0503a32.zip |
[Bleeding] Added Ageable interface for Villagers and Animals to extend. Addresses BUKKIT-1232
4 files changed, 72 insertions, 49 deletions
diff --git a/src/main/java/net/minecraft/server/EntityEgg.java b/src/main/java/net/minecraft/server/EntityEgg.java index 167c1e84..afa0bf8c 100644 --- a/src/main/java/net/minecraft/server/EntityEgg.java +++ b/src/main/java/net/minecraft/server/EntityEgg.java @@ -2,7 +2,7 @@ package net.minecraft.server; // CraftBukkit start import org.bukkit.Location; -import org.bukkit.entity.Animals; +import org.bukkit.entity.Ageable; import org.bukkit.entity.EntityType; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.event.player.PlayerEggThrowEvent; @@ -51,8 +51,8 @@ public class EntityEgg extends EntityProjectile { for (int k = 0; k < numHatching; k++) { org.bukkit.entity.Entity entity = world.getWorld().spawn(new Location(world.getWorld(), this.locX, this.locY, this.locZ, this.yaw, 0.0F), hatchingType.getEntityClass(), SpawnReason.EGG); - if (entity instanceof Animals) { - ((Animals) entity).setBaby(); + if (entity instanceof Ageable) { + ((Ageable) entity).setBaby(); } } } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftAgeable.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftAgeable.java new file mode 100644 index 00000000..ecd630c5 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftAgeable.java @@ -0,0 +1,67 @@ +package org.bukkit.craftbukkit.entity; + +import net.minecraft.server.EntityAgeable; + +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.entity.Ageable; + +public class CraftAgeable extends CraftCreature implements Ageable { + public CraftAgeable(CraftServer server, EntityAgeable entity) { + super(server, entity); + } + + public int getAge() { + return getHandle().getAge(); + } + + public void setAge(int age) { + getHandle().setAge(age); + } + + public void setAgeLock(boolean lock) { + getHandle().ageLocked = lock; + } + + public boolean getAgeLock() { + return getHandle().ageLocked; + } + + public void setBaby() { + if (isAdult()) { + setAge(-24000); + } + } + + public void setAdult() { + if (!isAdult()) { + setAge(0); + } + } + + public boolean isAdult() { + return getAge() >= 0; + } + + + public boolean canBreed() { + return getAge() == 0; + } + + public void setBreed(boolean breed) { + if (breed) { + setAge(0); + } else if (isAdult()) { + setAge(6000); + } + } + + @Override + public EntityAgeable getHandle() { + return (EntityAgeable) entity; + } + + @Override + public String toString() { + return "CraftAgeable"; + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftAnimals.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftAnimals.java index 4e229f57..4b9b0783 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftAnimals.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftAnimals.java @@ -4,61 +4,17 @@ import net.minecraft.server.EntityAnimal; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.Animals; -public class CraftAnimals extends CraftCreature implements Animals { +public class CraftAnimals extends CraftAgeable implements Animals { public CraftAnimals(CraftServer server, EntityAnimal entity) { super(server, entity); } - public int getAge() { - return getHandle().getAge(); - } - - public void setAge(int age) { - getHandle().setAge(age); - } - @Override public EntityAnimal getHandle() { return (EntityAnimal) entity; } - public void setAgeLock(boolean lock) { - getHandle().ageLocked = lock; - } - - public boolean getAgeLock() { - return getHandle().ageLocked; - } - - public void setBaby() { - if (isAdult()) { - setAge(-24000); - } - } - - public void setAdult() { - if (!isAdult()) { - setAge(0); - } - } - - public boolean isAdult() { - return getAge() >= 0; - } - - public boolean canBreed() { - return getAge() == 0; - } - - public void setBreed(boolean breed) { - if (breed) { - setAge(0); - } else if (isAdult()) { - setAge(6000); - } - } - @Override public String toString() { return "CraftAnimals"; diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java index 7cf5e4b7..398029b9 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java @@ -6,7 +6,7 @@ import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.EntityType; import org.bukkit.entity.Villager; -public class CraftVillager extends CraftCreature implements Villager { +public class CraftVillager extends CraftAgeable implements Villager { public CraftVillager(CraftServer server, EntityVillager entity) { super(server, entity); } |