001 package net.minecraft.entity.ai; 002 003 import net.minecraft.entity.EntityLiving; 004 005 public 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 var1 = 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) && var1 < 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 var1 = (int)((float)this.breakingTime / 240.0F * 10.0F); 064 065 if (var1 != this.field_75358_j) 066 { 067 this.theEntity.worldObj.destroyBlockInWorldPartially(this.theEntity.entityId, this.entityPosX, this.entityPosY, this.entityPosZ, var1); 068 this.field_75358_j = var1; 069 } 070 071 if (this.breakingTime == 240 && this.theEntity.worldObj.difficultySetting == 3) 072 { 073 this.theEntity.worldObj.setBlockWithNotify(this.entityPosX, this.entityPosY, this.entityPosZ, 0); 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 }