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