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