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