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