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