2012-03-01 11:49:23 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
public abstract class EntityAgeable extends EntityCreature {
|
2013-03-13 23:33:27 +01:00
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
private float bp = -1.0F;
|
|
|
|
private float bq;
|
2012-03-01 11:49:23 +01:00
|
|
|
public boolean ageLocked = false; // CraftBukkit
|
|
|
|
|
|
|
|
public EntityAgeable(World world) {
|
|
|
|
super(world);
|
|
|
|
}
|
|
|
|
|
2012-11-06 13:05:28 +01:00
|
|
|
public abstract EntityAgeable createChild(EntityAgeable entityageable);
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
public boolean a(EntityHuman entityhuman) {
|
2012-11-06 13:05:28 +01:00
|
|
|
ItemStack itemstack = entityhuman.inventory.getItemInHand();
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (itemstack != null && itemstack.getItem() == Items.MONSTER_EGG) {
|
2013-07-01 13:03:00 +02:00
|
|
|
if (!this.world.isStatic) {
|
|
|
|
Class oclass = EntityTypes.a(itemstack.getData());
|
2012-11-06 13:05:28 +01:00
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
if (oclass != null && oclass.isAssignableFrom(this.getClass())) {
|
|
|
|
EntityAgeable entityageable = this.createChild(this);
|
2012-11-06 13:05:28 +01:00
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
if (entityageable != null) {
|
|
|
|
entityageable.setAge(-24000);
|
|
|
|
entityageable.setPositionRotation(this.locX, this.locY, this.locZ, 0.0F, 0.0F);
|
|
|
|
this.world.addEntity(entityageable, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER_EGG); // CraftBukkit
|
|
|
|
if (itemstack.hasName()) {
|
|
|
|
entityageable.setCustomName(itemstack.getName());
|
|
|
|
}
|
2013-03-13 23:33:27 +01:00
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
if (!entityhuman.abilities.canInstantlyBuild) {
|
|
|
|
--itemstack.count;
|
|
|
|
if (itemstack.count == 0) { // CraftBukkit - allow less than 0 stacks as "infinite"
|
|
|
|
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, (ItemStack) null);
|
|
|
|
}
|
2012-11-23 04:42:34 +01:00
|
|
|
}
|
2012-11-20 15:27:47 +01:00
|
|
|
}
|
2012-11-06 13:05:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-06 13:05:28 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
protected void c() {
|
|
|
|
super.c();
|
2012-03-01 11:49:23 +01:00
|
|
|
this.datawatcher.a(12, new Integer(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getAge() {
|
|
|
|
return this.datawatcher.getInt(12);
|
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
public void a(int i) {
|
|
|
|
int j = this.getAge();
|
|
|
|
|
|
|
|
j += i * 20;
|
|
|
|
if (j > 0) {
|
|
|
|
j = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setAge(j);
|
|
|
|
}
|
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
public void setAge(int i) {
|
|
|
|
this.datawatcher.watch(12, Integer.valueOf(i));
|
2013-03-13 23:33:27 +01:00
|
|
|
this.a(this.isBaby());
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void b(NBTTagCompound nbttagcompound) {
|
|
|
|
super.b(nbttagcompound);
|
|
|
|
nbttagcompound.setInt("Age", this.getAge());
|
|
|
|
nbttagcompound.setBoolean("AgeLocked", this.ageLocked); // CraftBukkit
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(NBTTagCompound nbttagcompound) {
|
|
|
|
super.a(nbttagcompound);
|
|
|
|
this.setAge(nbttagcompound.getInt("Age"));
|
|
|
|
this.ageLocked = nbttagcompound.getBoolean("AgeLocked"); // CraftBukkit
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public void e() {
|
|
|
|
super.e();
|
2013-03-13 23:33:27 +01:00
|
|
|
if (this.world.isStatic || this.ageLocked) { // CraftBukkit
|
|
|
|
this.a(this.isBaby());
|
|
|
|
} else {
|
|
|
|
int i = this.getAge();
|
|
|
|
|
|
|
|
if (i < 0) {
|
|
|
|
++i;
|
|
|
|
this.setAge(i);
|
|
|
|
} else if (i > 0) {
|
|
|
|
--i;
|
|
|
|
this.setAge(i);
|
|
|
|
}
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isBaby() {
|
|
|
|
return this.getAge() < 0;
|
|
|
|
}
|
2013-03-13 23:33:27 +01:00
|
|
|
|
|
|
|
public void a(boolean flag) {
|
2013-07-01 13:03:00 +02:00
|
|
|
this.a(flag ? 0.5F : 1.0F);
|
2013-03-13 23:33:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected final void a(float f, float f1) {
|
2013-07-01 13:03:00 +02:00
|
|
|
boolean flag = this.bp > 0.0F;
|
2013-03-13 23:33:27 +01:00
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
this.bp = f;
|
|
|
|
this.bq = f1;
|
2013-03-13 23:33:27 +01:00
|
|
|
if (!flag) {
|
2013-07-01 13:03:00 +02:00
|
|
|
this.a(1.0F);
|
2013-03-13 23:33:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
protected final void a(float f) {
|
|
|
|
super.a(this.bp * f, this.bq * f);
|
2013-03-13 23:33:27 +01:00
|
|
|
}
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|