001 package net.minecraft.entity; 002 003 import net.minecraft.entity.player.EntityPlayer; 004 import net.minecraft.item.Item; 005 import net.minecraft.item.ItemStack; 006 import net.minecraft.nbt.NBTTagCompound; 007 import net.minecraft.world.World; 008 009 public abstract class EntityAgeable extends EntityCreature 010 { 011 public EntityAgeable(World par1World) 012 { 013 super(par1World); 014 } 015 016 public abstract EntityAgeable func_90011_a(EntityAgeable var1); 017 018 /** 019 * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig. 020 */ 021 public boolean interact(EntityPlayer par1EntityPlayer) 022 { 023 ItemStack var2 = par1EntityPlayer.inventory.getCurrentItem(); 024 025 if (var2 != null && var2.itemID == Item.monsterPlacer.shiftedIndex && !this.worldObj.isRemote) 026 { 027 Class var3 = EntityList.func_90035_a(var2.getItemDamage()); 028 029 if (var3 != null && var3.isAssignableFrom(this.getClass())) 030 { 031 EntityAgeable var4 = this.func_90011_a(this); 032 033 if (var4 != null) 034 { 035 var4.setGrowingAge(-24000); 036 var4.setLocationAndAngles(this.posX, this.posY, this.posZ, 0.0F, 0.0F); 037 this.worldObj.spawnEntityInWorld(var4); 038 } 039 } 040 } 041 042 return super.interact(par1EntityPlayer); 043 } 044 045 protected void entityInit() 046 { 047 super.entityInit(); 048 this.dataWatcher.addObject(12, new Integer(0)); 049 } 050 051 /** 052 * The age value may be negative or positive or zero. If it's negative, it get's incremented on each tick, if it's 053 * positive, it get's decremented each tick. Don't confuse this with EntityLiving.getAge. With a negative value the 054 * Entity is considered a child. 055 */ 056 public int getGrowingAge() 057 { 058 return this.dataWatcher.getWatchableObjectInt(12); 059 } 060 061 /** 062 * The age value may be negative or positive or zero. If it's negative, it get's incremented on each tick, if it's 063 * positive, it get's decremented each tick. With a negative value the Entity is considered a child. 064 */ 065 public void setGrowingAge(int par1) 066 { 067 this.dataWatcher.updateObject(12, Integer.valueOf(par1)); 068 } 069 070 /** 071 * (abstract) Protected helper method to write subclass entity data to NBT. 072 */ 073 public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) 074 { 075 super.writeEntityToNBT(par1NBTTagCompound); 076 par1NBTTagCompound.setInteger("Age", this.getGrowingAge()); 077 } 078 079 /** 080 * (abstract) Protected helper method to read subclass entity data from NBT. 081 */ 082 public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) 083 { 084 super.readEntityFromNBT(par1NBTTagCompound); 085 this.setGrowingAge(par1NBTTagCompound.getInteger("Age")); 086 } 087 088 /** 089 * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons 090 * use this to react to sunlight and start to burn. 091 */ 092 public void onLivingUpdate() 093 { 094 super.onLivingUpdate(); 095 int var1 = this.getGrowingAge(); 096 097 if (var1 < 0) 098 { 099 ++var1; 100 this.setGrowingAge(var1); 101 } 102 else if (var1 > 0) 103 { 104 --var1; 105 this.setGrowingAge(var1); 106 } 107 } 108 109 /** 110 * If Animal, checks if the age timer is negative 111 */ 112 public boolean isChild() 113 { 114 return this.getGrowingAge() < 0; 115 } 116 }