001    package net.minecraft.src;
002    
003    public abstract class EntityAIDoorInteract extends EntityAIBase
004    {
005        protected EntityLiving theEntity;
006        protected int entityPosX;
007        protected int entityPosY;
008        protected int entityPosZ;
009        protected BlockDoor targetDoor;
010        boolean field_75350_f;
011        float entityPositionX;
012        float entityPositionZ;
013    
014        public EntityAIDoorInteract(EntityLiving par1EntityLiving)
015        {
016            this.theEntity = par1EntityLiving;
017        }
018    
019        /**
020         * Returns whether the EntityAIBase should begin execution.
021         */
022        public boolean shouldExecute()
023        {
024            if (!this.theEntity.isCollidedHorizontally)
025            {
026                return false;
027            }
028            else
029            {
030                PathNavigate var1 = this.theEntity.getNavigator();
031                PathEntity var2 = var1.getPath();
032    
033                if (var2 != null && !var2.isFinished() && var1.getCanBreakDoors())
034                {
035                    for (int var3 = 0; var3 < Math.min(var2.getCurrentPathIndex() + 2, var2.getCurrentPathLength()); ++var3)
036                    {
037                        PathPoint var4 = var2.getPathPointFromIndex(var3);
038                        this.entityPosX = var4.xCoord;
039                        this.entityPosY = var4.yCoord + 1;
040                        this.entityPosZ = var4.zCoord;
041    
042                        if (this.theEntity.getDistanceSq((double)this.entityPosX, this.theEntity.posY, (double)this.entityPosZ) <= 2.25D)
043                        {
044                            this.targetDoor = this.findUsableDoor(this.entityPosX, this.entityPosY, this.entityPosZ);
045    
046                            if (this.targetDoor != null)
047                            {
048                                return true;
049                            }
050                        }
051                    }
052    
053                    this.entityPosX = MathHelper.floor_double(this.theEntity.posX);
054                    this.entityPosY = MathHelper.floor_double(this.theEntity.posY + 1.0D);
055                    this.entityPosZ = MathHelper.floor_double(this.theEntity.posZ);
056                    this.targetDoor = this.findUsableDoor(this.entityPosX, this.entityPosY, this.entityPosZ);
057                    return this.targetDoor != null;
058                }
059                else
060                {
061                    return false;
062                }
063            }
064        }
065    
066        /**
067         * Returns whether an in-progress EntityAIBase should continue executing
068         */
069        public boolean continueExecuting()
070        {
071            return !this.field_75350_f;
072        }
073    
074        /**
075         * Execute a one shot task or start executing a continuous task
076         */
077        public void startExecuting()
078        {
079            this.field_75350_f = false;
080            this.entityPositionX = (float)((double)((float)this.entityPosX + 0.5F) - this.theEntity.posX);
081            this.entityPositionZ = (float)((double)((float)this.entityPosZ + 0.5F) - this.theEntity.posZ);
082        }
083    
084        /**
085         * Updates the task
086         */
087        public void updateTask()
088        {
089            float var1 = (float)((double)((float)this.entityPosX + 0.5F) - this.theEntity.posX);
090            float var2 = (float)((double)((float)this.entityPosZ + 0.5F) - this.theEntity.posZ);
091            float var3 = this.entityPositionX * var1 + this.entityPositionZ * var2;
092    
093            if (var3 < 0.0F)
094            {
095                this.field_75350_f = true;
096            }
097        }
098    
099        /**
100         * Determines if a door can be broken with AI.
101         */
102        private BlockDoor findUsableDoor(int par1, int par2, int par3)
103        {
104            int var4 = this.theEntity.worldObj.getBlockId(par1, par2, par3);
105            return var4 != Block.doorWood.blockID ? null : (BlockDoor)Block.blocksList[var4];
106        }
107    }