    001package net.minecraft.entity.ai;
    002
    003import java.util.Iterator;
    004import java.util.List;
    005import net.minecraft.entity.EntityLiving;
    006import net.minecraft.entity.player.EntityPlayer;
    007import net.minecraft.util.AxisAlignedBB;
    008
    009public 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 list = this.taskOwner.worldObj.getEntitiesWithinAABB(this.taskOwner.getClass(), AxisAlignedBB.getAABBPool().getAABB(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, 10.0D, (double)this.targetDistance));
    050            Iterator iterator = list.iterator();
    051
    052            while (iterator.hasNext())
    053            {
    054                EntityLiving entityliving = (EntityLiving)iterator.next();
    055
    056                if (this.taskOwner != entityliving && entityliving.getAttackTarget() == null)
    057                {
    058                    entityliving.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}