package net.minecraft.entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
public abstract class EntityAgeable extends EntityCreature
{
private float field_98056_d = -1.0F;
private float field_98057_e;
private static final String __OBFID = "CL_00001530";
public EntityAgeable(World p_i1578_1_)
{
super(p_i1578_1_);
}
public abstract EntityAgeable createChild(EntityAgeable p_90011_1_);
/**
* Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
*/
public boolean interact(EntityPlayer p_70085_1_)
{
ItemStack itemstack = p_70085_1_.inventory.getCurrentItem();
if (itemstack != null && itemstack.getItem() == Items.spawn_egg)
{
if (!this.worldObj.isRemote)
{
Class oclass = EntityList.getClassFromID(itemstack.getMetadata());
if (oclass != null && oclass.isAssignableFrom(this.getClass()))
{
EntityAgeable entityageable = this.createChild(this);
if (entityageable != null)
{
entityageable.setGrowingAge(-24000);
entityageable.setLocationAndAngles(this.posX, this.posY, this.posZ, 0.0F, 0.0F);
this.worldObj.spawnEntityInWorld(entityageable);
if (itemstack.hasDisplayName())
{
entityageable.setCustomNameTag(itemstack.getDisplayName());
}
if (!p_70085_1_.capabilities.isCreativeMode)
{
--itemstack.stackSize;
if (itemstack.stackSize <= 0)
{
p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem, (ItemStack)null);
}
}
}
}
}
return true;
}
else
{
return false;
}
}
protected void entityInit()
{
super.entityInit();
this.dataWatcher.addObject(12, new Integer(0));
}
/**
* The age value may be negative or positive or zero. If it's negative, it get's incremented on each tick, if it's
* positive, it get's decremented each tick. Don't confuse this with EntityLiving.getAge. With a negative value the
* Entity is considered a child.
*/
public int getGrowingAge()
{
return this.dataWatcher.getWatchableObjectInt(12);
}
/**
* "Adds the value of the parameter times 20 to the age of this entity. If the entity is an adult (if the entity's
* age is greater than 0), it will have no effect."
*/
public void addGrowth(int p_110195_1_)
{
int j = this.getGrowingAge();
j += p_110195_1_ * 20;
if (j > 0)
{
j = 0;
}
this.setGrowingAge(j);
}
/**
* The age value may be negative or positive or zero. If it's negative, it get's incremented on each tick, if it's
* positive, it get's decremented each tick. With a negative value the Entity is considered a child.
*/
public void setGrowingAge(int p_70873_1_)
{
this.dataWatcher.updateObject(12, Integer.valueOf(p_70873_1_));
this.setScaleForAge(this.isChild());
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
public void writeEntityToNBT(NBTTagCompound tagCompound)
{
super.writeEntityToNBT(tagCompound);
tagCompound.setInteger("Age", this.getGrowingAge());
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
public void readEntityFromNBT(NBTTagCompound tagCompund)
{
super.readEntityFromNBT(tagCompund);
this.setGrowingAge(tagCompund.getInteger("Age"));
}
/**
* Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
* use this to react to sunlight and start to burn.
*/
public void onLivingUpdate()
{
super.onLivingUpdate();
if (this.worldObj.isRemote)
{
this.setScaleForAge(this.isChild());
}
else
{
int i = this.getGrowingAge();
if (i < 0)
{
++i;
this.setGrowingAge(i);
}
else if (i > 0)
{
--i;
this.setGrowingAge(i);
}
}
}
/**
* If Animal, checks if the age timer is negative
*/
public boolean isChild()
{
return this.getGrowingAge() < 0;
}
/**
* "Sets the scale for an ageable entity according to the boolean parameter, which says if it's a child."
*/
public void setScaleForAge(boolean p_98054_1_)
{
this.setScale(p_98054_1_ ? 0.5F : 1.0F);
}
/**
* Sets the width and height of the entity. Args: width, height
*/
protected final void setSize(float width, float height)
{
boolean flag = this.field_98056_d > 0.0F;
this.field_98056_d = width;
this.field_98057_e = height;
if (!flag)
{
this.setScale(1.0F);
}
}
protected final void setScale(float p_98055_1_)
{
super.setSize(this.field_98056_d * p_98055_1_, this.field_98057_e * p_98055_1_);
}
}