mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-02 04:56:50 +01:00
[Bleeding] Added Ageable interface for Villagers and Animals to extend. Addresses BUKKIT-1232
This commit is contained in:
parent
96c4bb7da6
commit
169c2ee8cb
4 changed files with 72 additions and 49 deletions
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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";
|
||||||
|
}
|
||||||
|
}
|
|
@ -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";
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue