001 package net.minecraft.entity.ai;
002
003 import java.util.Iterator;
004 import java.util.List;
005 import net.minecraft.entity.EntityLiving;
006 import net.minecraft.entity.player.EntityPlayer;
007 import net.minecraft.util.AxisAlignedBB;
008
009 public class EntityAIHurtByTarget extends EntityAITarget
010 {
011 boolean field_75312_a;
012
013 /** The PathNavigate of our entity. */
014 EntityLiving entityPathNavigate;
015
016 public EntityAIHurtByTarget(EntityLiving par1EntityLiving, boolean par2)
017 {
018 super(par1EntityLiving, 16.0F, false);
019 this.field_75312_a = par2;
020 this.setMutexBits(1);
021 }
022
023 /**
024 * Returns whether the EntityAIBase should begin execution.
025 */
026 public boolean shouldExecute()
027 {
028 return this.isSuitableTarget(this.taskOwner.getAITarget(), true);
029 }
030
031 /**
032 * Returns whether an in-progress EntityAIBase should continue executing
033 */
034 public boolean continueExecuting()
035 {
036 return this.taskOwner.getAITarget() != null && this.taskOwner.getAITarget() != this.entityPathNavigate;
037 }
038
039 /**
040 * Execute a one shot task or start executing a continuous task
041 */
042 public void startExecuting()
043 {
044 this.taskOwner.setAttackTarget(this.taskOwner.getAITarget());
045 this.entityPathNavigate = this.taskOwner.getAITarget();
046
047 if (this.field_75312_a)
048 {
049 List var1 = this.taskOwner.worldObj.getEntitiesWithinAABB(this.taskOwner.getClass(), AxisAlignedBB.getAABBPool().addOrModifyAABBInPool(this.taskOwner.posX, this.taskOwner.posY, this.taskOwner.posZ, this.taskOwner.posX + 1.0D, this.taskOwner.posY + 1.0D, this.taskOwner.posZ + 1.0D).expand((double)this.targetDistance, 4.0D, (double)this.targetDistance));
050 Iterator var2 = var1.iterator();
051
052 while (var2.hasNext())
053 {
054 EntityLiving var3 = (EntityLiving)var2.next();
055
056 if (this.taskOwner != var3 && var3.getAttackTarget() == null)
057 {
058 var3.setAttackTarget(this.taskOwner.getAITarget());
059 }
060 }
061 }
062
063 super.startExecuting();
064 }
065
066 /**
067 * Resets the task
068 */
069 public void resetTask()
070 {
071 if (this.taskOwner.getAttackTarget() != null && this.taskOwner.getAttackTarget() instanceof EntityPlayer && ((EntityPlayer)this.taskOwner.getAttackTarget()).capabilities.disableDamage)
072 {
073 super.resetTask();
074 }
075 }
076 }