001    package net.minecraft.src;
002    
003    public class EntityAIMoveTowardsTarget extends EntityAIBase
004    {
005        private EntityCreature theEntity;
006        private EntityLiving targetEntity;
007        private double movePosX;
008        private double movePosY;
009        private double movePosZ;
010        private float field_75425_f;
011        private float field_75426_g;
012    
013        public EntityAIMoveTowardsTarget(EntityCreature par1EntityCreature, float par2, float par3)
014        {
015            this.theEntity = par1EntityCreature;
016            this.field_75425_f = par2;
017            this.field_75426_g = par3;
018            this.setMutexBits(1);
019        }
020    
021        /**
022         * Returns whether the EntityAIBase should begin execution.
023         */
024        public boolean shouldExecute()
025        {
026            this.targetEntity = this.theEntity.getAttackTarget();
027    
028            if (this.targetEntity == null)
029            {
030                return false;
031            }
032            else if (this.targetEntity.getDistanceSqToEntity(this.theEntity) > (double)(this.field_75426_g * this.field_75426_g))
033            {
034                return false;
035            }
036            else
037            {
038                Vec3 var1 = RandomPositionGenerator.findRandomTargetBlockTowards(this.theEntity, 16, 7, Vec3.getVec3Pool().getVecFromPool(this.targetEntity.posX, this.targetEntity.posY, this.targetEntity.posZ));
039    
040                if (var1 == null)
041                {
042                    return false;
043                }
044                else
045                {
046                    this.movePosX = var1.xCoord;
047                    this.movePosY = var1.yCoord;
048                    this.movePosZ = var1.zCoord;
049                    return true;
050                }
051            }
052        }
053    
054        /**
055         * Returns whether an in-progress EntityAIBase should continue executing
056         */
057        public boolean continueExecuting()
058        {
059            return !this.theEntity.getNavigator().noPath() && this.targetEntity.isEntityAlive() && this.targetEntity.getDistanceSqToEntity(this.theEntity) < (double)(this.field_75426_g * this.field_75426_g);
060        }
061    
062        /**
063         * Resets the task
064         */
065        public void resetTask()
066        {
067            this.targetEntity = null;
068        }
069    
070        /**
071         * Execute a one shot task or start executing a continuous task
072         */
073        public void startExecuting()
074        {
075            this.theEntity.getNavigator().tryMoveToXYZ(this.movePosX, this.movePosY, this.movePosZ, this.field_75425_f);
076        }
077    }