001 package net.minecraft.src;
002
003 public abstract class EntityAgeable extends EntityCreature
004 {
005 public EntityAgeable(World par1World)
006 {
007 super(par1World);
008 }
009
010 protected void entityInit()
011 {
012 super.entityInit();
013 this.dataWatcher.addObject(12, new Integer(0));
014 }
015
016 /**
017 * The age value may be negative or positive or zero. If it's negative, it get's incremented on each tick, if it's
018 * positive, it get's decremented each tick. Don't confuse this with EntityLiving.getAge. With a negative value the
019 * Entity is considered a child.
020 */
021 public int getGrowingAge()
022 {
023 return this.dataWatcher.getWatchableObjectInt(12);
024 }
025
026 /**
027 * The age value may be negative or positive or zero. If it's negative, it get's incremented on each tick, if it's
028 * positive, it get's decremented each tick. With a negative value the Entity is considered a child.
029 */
030 public void setGrowingAge(int par1)
031 {
032 this.dataWatcher.updateObject(12, Integer.valueOf(par1));
033 }
034
035 /**
036 * (abstract) Protected helper method to write subclass entity data to NBT.
037 */
038 public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
039 {
040 super.writeEntityToNBT(par1NBTTagCompound);
041 par1NBTTagCompound.setInteger("Age", this.getGrowingAge());
042 }
043
044 /**
045 * (abstract) Protected helper method to read subclass entity data from NBT.
046 */
047 public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
048 {
049 super.readEntityFromNBT(par1NBTTagCompound);
050 this.setGrowingAge(par1NBTTagCompound.getInteger("Age"));
051 }
052
053 /**
054 * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
055 * use this to react to sunlight and start to burn.
056 */
057 public void onLivingUpdate()
058 {
059 super.onLivingUpdate();
060 int var1 = this.getGrowingAge();
061
062 if (var1 < 0)
063 {
064 ++var1;
065 this.setGrowingAge(var1);
066 }
067 else if (var1 > 0)
068 {
069 --var1;
070 this.setGrowingAge(var1);
071 }
072 }
073
074 /**
075 * If Animal, checks if the age timer is negative
076 */
077 public boolean isChild()
078 {
079 return this.getGrowingAge() < 0;
080 }
081 }