    001    package net.minecraft.src;
    002
    003    public class EntityAIMoveIndoors extends EntityAIBase
    004    {
    005        private EntityCreature entityObj;
    006        private VillageDoorInfo doorInfo;
    007        private int insidePosX = -1;
    008        private int insidePosZ = -1;
    009
    010        public EntityAIMoveIndoors(EntityCreature par1EntityCreature)
    011        {
    012            this.entityObj = par1EntityCreature;
    013            this.setMutexBits(1);
    014        }
    015
    016        /**
    017         * Returns whether the EntityAIBase should begin execution.
    018         */
    019        public boolean shouldExecute()
    020        {
    021            if ((!this.entityObj.worldObj.isDaytime() || this.entityObj.worldObj.isRaining()) && !this.entityObj.worldObj.provider.hasNoSky)
    022            {
    023                if (this.entityObj.getRNG().nextInt(50) != 0)
    024                {
    025                    return false;
    026                }
    027                else if (this.insidePosX != -1 && this.entityObj.getDistanceSq((double)this.insidePosX, this.entityObj.posY, (double)this.insidePosZ) < 4.0D)
    028                {
    029                    return false;
    030                }
    031                else
    032                {
    033                    Village var1 = this.entityObj.worldObj.villageCollectionObj.findNearestVillage(MathHelper.floor_double(this.entityObj.posX), MathHelper.floor_double(this.entityObj.posY), MathHelper.floor_double(this.entityObj.posZ), 14);
    034
    035                    if (var1 == null)
    036                    {
    037                        return false;
    038                    }
    039                    else
    040                    {
    041                        this.doorInfo = var1.findNearestDoorUnrestricted(MathHelper.floor_double(this.entityObj.posX), MathHelper.floor_double(this.entityObj.posY), MathHelper.floor_double(this.entityObj.posZ));
    042                        return this.doorInfo != null;
    043                    }
    044                }
    045            }
    046            else
    047            {
    048                return false;
    049            }
    050        }
    051
    052        /**
    053         * Returns whether an in-progress EntityAIBase should continue executing
    054         */
    055        public boolean continueExecuting()
    056        {
    057            return !this.entityObj.getNavigator().noPath();
    058        }
    059
    060        /**
    061         * Execute a one shot task or start executing a continuous task
    062         */
    063        public void startExecuting()
    064        {
    065            this.insidePosX = -1;
    066
    067            if (this.entityObj.getDistanceSq((double)this.doorInfo.getInsidePosX(), (double)this.doorInfo.posY, (double)this.doorInfo.getInsidePosZ()) > 256.0D)
    068            {
    069                Vec3 var1 = RandomPositionGenerator.findRandomTargetBlockTowards(this.entityObj, 14, 3, this.entityObj.worldObj.getWorldVec3Pool().getVecFromPool((double)this.doorInfo.getInsidePosX() + 0.5D, (double)this.doorInfo.getInsidePosY(), (double)this.doorInfo.getInsidePosZ() + 0.5D));
    070
    071                if (var1 != null)
    072                {
    073                    this.entityObj.getNavigator().tryMoveToXYZ(var1.xCoord, var1.yCoord, var1.zCoord, 0.3F);
    074                }
    075            }
    076            else
    077            {
    078                this.entityObj.getNavigator().tryMoveToXYZ((double)this.doorInfo.getInsidePosX() + 0.5D, (double)this.doorInfo.getInsidePosY(), (double)this.doorInfo.getInsidePosZ() + 0.5D, 0.3F);
    079            }
    080        }
    081
    082        /**
    083         * Resets the task
    084         */
    085        public void resetTask()
    086        {
    087            this.insidePosX = this.doorInfo.getInsidePosX();
    088            this.insidePosZ = this.doorInfo.getInsidePosZ();
    089            this.doorInfo = null;
    090        }
    091    }