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