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

Dieser Commit ist enthalten in:
aPunch 2012-03-19 14:12:17 -05:00 committet von EvilSeph
Ursprung 96c4bb7da6
Commit 169c2ee8cb
4 geänderte Dateien mit 72 neuen und 49 gelöschten Zeilen

Datei anzeigen

@ -2,7 +2,7 @@ package net.minecraft.server;
// CraftBukkit start // CraftBukkit start
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Animals; import org.bukkit.entity.Ageable;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.player.PlayerEggThrowEvent; import org.bukkit.event.player.PlayerEggThrowEvent;
@ -51,8 +51,8 @@ public class EntityEgg extends EntityProjectile {
for (int k = 0; k < numHatching; k++) { 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); 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) { if (entity instanceof Ageable) {
((Animals) entity).setBaby(); ((Ageable) entity).setBaby();
} }
} }
} }

Datei anzeigen

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

Datei anzeigen

@ -4,61 +4,17 @@ import net.minecraft.server.EntityAnimal;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Animals; 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) { public CraftAnimals(CraftServer server, EntityAnimal entity) {
super(server, entity); super(server, entity);
} }
public int getAge() {
return getHandle().getAge();
}
public void setAge(int age) {
getHandle().setAge(age);
}
@Override @Override
public EntityAnimal getHandle() { public EntityAnimal getHandle() {
return (EntityAnimal) entity; 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 @Override
public String toString() { public String toString() {
return "CraftAnimals"; return "CraftAnimals";

Datei anzeigen

@ -6,7 +6,7 @@ import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Villager; 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) { public CraftVillager(CraftServer server, EntityVillager entity) {
super(server, entity); super(server, entity);
} }