[Bleeding] Added Ageable interface for Villagers and Animals to extend. Addresses BUKKIT-1232

By: aPunch <theapunch@yahoo.com>
This commit is contained in:
CraftBukkit/Spigot 2012-03-19 14:12:17 -05:00
parent 4e5359c080
commit d6e7e41468
3 changed files with 69 additions and 46 deletions

View file

@ -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";
}
}

View file

@ -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";

View file

@ -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);
}