001 package net.minecraft.entity.ai;
002
003 import java.util.Iterator;
004 import java.util.List;
005 import net.minecraft.entity.passive.EntityAnimal;
006
007 public class EntityAIFollowParent extends EntityAIBase
008 {
009 /** The child that is following its parent. */
010 EntityAnimal childAnimal;
011 EntityAnimal parentAnimal;
012 float field_75347_c;
013 private int field_75345_d;
014
015 public EntityAIFollowParent(EntityAnimal par1EntityAnimal, float par2)
016 {
017 this.childAnimal = par1EntityAnimal;
018 this.field_75347_c = par2;
019 }
020
021 /**
022 * Returns whether the EntityAIBase should begin execution.
023 */
024 public boolean shouldExecute()
025 {
026 if (this.childAnimal.getGrowingAge() >= 0)
027 {
028 return false;
029 }
030 else
031 {
032 List var1 = this.childAnimal.worldObj.getEntitiesWithinAABB(this.childAnimal.getClass(), this.childAnimal.boundingBox.expand(8.0D, 4.0D, 8.0D));
033 EntityAnimal var2 = null;
034 double var3 = Double.MAX_VALUE;
035 Iterator var5 = var1.iterator();
036
037 while (var5.hasNext())
038 {
039 EntityAnimal var6 = (EntityAnimal)var5.next();
040
041 if (var6.getGrowingAge() >= 0)
042 {
043 double var7 = this.childAnimal.getDistanceSqToEntity(var6);
044
045 if (var7 <= var3)
046 {
047 var3 = var7;
048 var2 = var6;
049 }
050 }
051 }
052
053 if (var2 == null)
054 {
055 return false;
056 }
057 else if (var3 < 9.0D)
058 {
059 return false;
060 }
061 else
062 {
063 this.parentAnimal = var2;
064 return true;
065 }
066 }
067 }
068
069 /**
070 * Returns whether an in-progress EntityAIBase should continue executing
071 */
072 public boolean continueExecuting()
073 {
074 if (!this.parentAnimal.isEntityAlive())
075 {
076 return false;
077 }
078 else
079 {
080 double var1 = this.childAnimal.getDistanceSqToEntity(this.parentAnimal);
081 return var1 >= 9.0D && var1 <= 256.0D;
082 }
083 }
084
085 /**
086 * Execute a one shot task or start executing a continuous task
087 */
088 public void startExecuting()
089 {
090 this.field_75345_d = 0;
091 }
092
093 /**
094 * Resets the task
095 */
096 public void resetTask()
097 {
098 this.parentAnimal = null;
099 }
100
101 /**
102 * Updates the task
103 */
104 public void updateTask()
105 {
106 if (--this.field_75345_d <= 0)
107 {
108 this.field_75345_d = 10;
109 this.childAnimal.getNavigator().tryMoveToEntityLiving(this.parentAnimal, this.field_75347_c);
110 }
111 }
112 }