    001    package net.minecraft.src;
    002
    003    public class EntityAIRestrictOpenDoor extends EntityAIBase
    004    {
    005        private EntityCreature entityObj;
    006        private VillageDoorInfo frontDoor;
    007
    008        public EntityAIRestrictOpenDoor(EntityCreature par1EntityCreature)
    009        {
    010            this.entityObj = par1EntityCreature;
    011        }
    012
    013        /**
    014         * Returns whether the EntityAIBase should begin execution.
    015         */
    016        public boolean shouldExecute()
    017        {
    018            if (this.entityObj.worldObj.isDaytime())
    019            {
    020                return false;
    021            }
    022            else
    023            {
    024                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), 16);
    025
    026                if (var1 == null)
    027                {
    028                    return false;
    029                }
    030                else
    031                {
    032                    this.frontDoor = var1.findNearestDoor(MathHelper.floor_double(this.entityObj.posX), MathHelper.floor_double(this.entityObj.posY), MathHelper.floor_double(this.entityObj.posZ));
    033                    return this.frontDoor == null ? false : (double)this.frontDoor.getInsideDistanceSquare(MathHelper.floor_double(this.entityObj.posX), MathHelper.floor_double(this.entityObj.posY), MathHelper.floor_double(this.entityObj.posZ)) < 2.25D;
    034                }
    035            }
    036        }
    037
    038        /**
    039         * Returns whether an in-progress EntityAIBase should continue executing
    040         */
    041        public boolean continueExecuting()
    042        {
    043            return this.entityObj.worldObj.isDaytime() ? false : !this.frontDoor.isDetachedFromVillageFlag && this.frontDoor.isInside(MathHelper.floor_double(this.entityObj.posX), MathHelper.floor_double(this.entityObj.posZ));
    044        }
    045
    046        /**
    047         * Execute a one shot task or start executing a continuous task
    048         */
    049        public void startExecuting()
    050        {
    051            this.entityObj.getNavigator().setBreakDoors(false);
    052            this.entityObj.getNavigator().setEnterDoors(false);
    053        }
    054
    055        /**
    056         * Resets the task
    057         */
    058        public void resetTask()
    059        {
    060            this.entityObj.getNavigator().setBreakDoors(true);
    061            this.entityObj.getNavigator().setEnterDoors(true);
    062            this.frontDoor = null;
    063        }
    064
    065        /**
    066         * Updates the task
    067         */
    068        public void updateTask()
    069        {
    070            this.frontDoor.incrementDoorOpeningRestrictionCounter();
    071        }
    072    }