001 package net.minecraft.src; 002 003 public class EntityAIDefendVillage extends EntityAITarget 004 { 005 EntityIronGolem irongolem; 006 007 /** 008 * The aggressor of the iron golem's village which is now the golem's attack target. 009 */ 010 EntityLiving villageAgressorTarget; 011 012 public EntityAIDefendVillage(EntityIronGolem par1EntityIronGolem) 013 { 014 super(par1EntityIronGolem, 16.0F, false, true); 015 this.irongolem = par1EntityIronGolem; 016 this.setMutexBits(1); 017 } 018 019 /** 020 * Returns whether the EntityAIBase should begin execution. 021 */ 022 public boolean shouldExecute() 023 { 024 Village var1 = this.irongolem.getVillage(); 025 026 if (var1 == null) 027 { 028 return false; 029 } 030 else 031 { 032 this.villageAgressorTarget = var1.findNearestVillageAggressor(this.irongolem); 033 034 if (!this.isSuitableTarget(this.villageAgressorTarget, false)) 035 { 036 if (this.taskOwner.getRNG().nextInt(20) == 0) 037 { 038 this.villageAgressorTarget = var1.func_82685_c(this.irongolem); 039 return this.isSuitableTarget(this.villageAgressorTarget, false); 040 } 041 else 042 { 043 return false; 044 } 045 } 046 else 047 { 048 return true; 049 } 050 } 051 } 052 053 /** 054 * Execute a one shot task or start executing a continuous task 055 */ 056 public void startExecuting() 057 { 058 this.irongolem.setAttackTarget(this.villageAgressorTarget); 059 super.startExecuting(); 060 } 061 }