    001    package net.minecraft.src;
    002
    003    public class EntityAIBreakDoor extends EntityAIDoorInteract
    004    {
    005        private int breakingTime;
    006        private int field_75358_j = -1;
    007
    008        public EntityAIBreakDoor(EntityLiving par1EntityLiving)
    009        {
    010            super(par1EntityLiving);
    011        }
    012
    013        /**
    014         * Returns whether the EntityAIBase should begin execution.
    015         */
    016        public boolean shouldExecute()
    017        {
    018            return !super.shouldExecute() ? false : (!this.theEntity.worldObj.func_82736_K().func_82766_b("mobGriefing") ? false : !this.targetDoor.isDoorOpen(this.theEntity.worldObj, this.entityPosX, this.entityPosY, this.entityPosZ));
    019        }
    020
    021        /**
    022         * Execute a one shot task or start executing a continuous task
    023         */
    024        public void startExecuting()
    025        {
    026            super.startExecuting();
    027            this.breakingTime = 0;
    028        }
    029
    030        /**
    031         * Returns whether an in-progress EntityAIBase should continue executing
    032         */
    033        public boolean continueExecuting()
    034        {
    035            double var1 = this.theEntity.getDistanceSq((double)this.entityPosX, (double)this.entityPosY, (double)this.entityPosZ);
    036            return this.breakingTime <= 240 && !this.targetDoor.isDoorOpen(this.theEntity.worldObj, this.entityPosX, this.entityPosY, this.entityPosZ) && var1 < 4.0D;
    037        }
    038
    039        /**
    040         * Resets the task
    041         */
    042        public void resetTask()
    043        {
    044            super.resetTask();
    045            this.theEntity.worldObj.destroyBlockInWorldPartially(this.theEntity.entityId, this.entityPosX, this.entityPosY, this.entityPosZ, -1);
    046        }
    047
    048        /**
    049         * Updates the task
    050         */
    051        public void updateTask()
    052        {
    053            super.updateTask();
    054
    055            if (this.theEntity.getRNG().nextInt(20) == 0)
    056            {
    057                this.theEntity.worldObj.playAuxSFX(1010, this.entityPosX, this.entityPosY, this.entityPosZ, 0);
    058            }
    059
    060            ++this.breakingTime;
    061            int var1 = (int)((float)this.breakingTime / 240.0F * 10.0F);
    062
    063            if (var1 != this.field_75358_j)
    064            {
    065                this.theEntity.worldObj.destroyBlockInWorldPartially(this.theEntity.entityId, this.entityPosX, this.entityPosY, this.entityPosZ, var1);
    066                this.field_75358_j = var1;
    067            }
    068
    069            if (this.breakingTime == 240 && this.theEntity.worldObj.difficultySetting == 3)
    070            {
    071                this.theEntity.worldObj.setBlockWithNotify(this.entityPosX, this.entityPosY, this.entityPosZ, 0);
    072                this.theEntity.worldObj.playAuxSFX(1012, this.entityPosX, this.entityPosY, this.entityPosZ, 0);
    073                this.theEntity.worldObj.playAuxSFX(2001, this.entityPosX, this.entityPosY, this.entityPosZ, this.targetDoor.blockID);
    074            }
    075        }
    076    }