| 1 | package net.minecraft.entity.ai;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.entity.passive.EntityAnimal;
|
| 5 |
|
| 6 | public class EntityAIFollowParent extends EntityAIBase
|
| 7 | {
|
| 8 | /** The child that is following its parent. */
|
| 9 | EntityAnimal childAnimal;
|
| 10 | EntityAnimal parentAnimal;
|
| 11 | double moveSpeed;
|
| 12 | private int delayCounter;
|
| 13 |
|
| 14 | public EntityAIFollowParent(EntityAnimal animal, double speed)
|
| 15 | {
|
| 16 | this.childAnimal = animal;
|
| 17 | this.moveSpeed = speed;
|
| 18 | }
|
| 19 |
|
| 20 | /**
|
| 21 | * Returns whether the EntityAIBase should begin execution.
|
| 22 | */
|
| 23 | public boolean shouldExecute()
|
| 24 | {
|
| 25 | if (this.childAnimal.getGrowingAge() >= 0)
|
| 26 | {
|
| 27 | return false;
|
| 28 | }
|
| 29 | else
|
| 30 | {
|
| 31 | List<EntityAnimal> list = this.childAnimal.worldObj.<EntityAnimal>getEntitiesWithinAABB(this.childAnimal.getClass(), this.childAnimal.getEntityBoundingBox().expand(8.0D, 4.0D, 8.0D));
|
| 32 | EntityAnimal entityanimal = null;
|
| 33 | double d0 = Double.MAX_VALUE;
|
| 34 |
|
| 35 | for (EntityAnimal entityanimal1 : list)
|
| 36 | {
|
| 37 | if (entityanimal1.getGrowingAge() >= 0)
|
| 38 | {
|
| 39 | double d1 = this.childAnimal.getDistanceSqToEntity(entityanimal1);
|
| 40 |
|
| 41 | if (d1 <= d0)
|
| 42 | {
|
| 43 | d0 = d1;
|
| 44 | entityanimal = entityanimal1;
|
| 45 | }
|
| 46 | }
|
| 47 | }
|
| 48 |
|
| 49 | if (entityanimal == null)
|
| 50 | {
|
| 51 | return false;
|
| 52 | }
|
| 53 | else if (d0 < 9.0D)
|
| 54 | {
|
| 55 | return false;
|
| 56 | }
|
| 57 | else
|
| 58 | {
|
| 59 | this.parentAnimal = entityanimal;
|
| 60 | return true;
|
| 61 | }
|
| 62 | }
|
| 63 | }
|
| 64 |
|
| 65 | /**
|
| 66 | * Returns whether an in-progress EntityAIBase should continue executing
|
| 67 | */
|
| 68 | public boolean continueExecuting()
|
| 69 | {
|
| 70 | if (this.childAnimal.getGrowingAge() >= 0)
|
| 71 | {
|
| 72 | return false;
|
| 73 | }
|
| 74 | else if (!this.parentAnimal.isEntityAlive())
|
| 75 | {
|
| 76 | return false;
|
| 77 | }
|
| 78 | else
|
| 79 | {
|
| 80 | double d0 = this.childAnimal.getDistanceSqToEntity(this.parentAnimal);
|
| 81 | return d0 >= 9.0D && d0 <= 256.0D;
|
| 82 | }
|
| 83 | }
|
| 84 |
|
| 85 | /**
|
| 86 | * Execute a one shot task or start executing a continuous task
|
| 87 | */
|
| 88 | public void startExecuting()
|
| 89 | {
|
| 90 | this.delayCounter = 0;
|
| 91 | }
|
| 92 |
|
| 93 | /**
|
| 94 | * Resets the task
|
| 95 | */
|
| 96 | public void resetTask()
|
| 97 | {
|
| 98 | this.parentAnimal = null;
|
| 99 | }
|
| 100 |
|
| 101 | /**
|
| 102 | * Updates the task
|
| 103 | */
|
| 104 | public void updateTask()
|
| 105 | {
|
| 106 | if (--this.delayCounter <= 0)
|
| 107 | {
|
| 108 | this.delayCounter = 10;
|
| 109 | this.childAnimal.getNavigator().tryMoveToEntityLiving(this.parentAnimal, this.moveSpeed);
|
| 110 | }
|
| 111 | }
|
| 112 | }
|
| 113 |
|