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