001package net.minecraft.entity.ai;
002
003import net.minecraft.entity.EntityLiving;
004import net.minecraft.world.World;
005
006public class EntityAIOcelotAttack extends EntityAIBase
007{
008    World theWorld;
009    EntityLiving theEntity;
010    EntityLiving theVictim;
011    int attackCountdown = 0;
012
013    public EntityAIOcelotAttack(EntityLiving par1EntityLiving)
014    {
015        this.theEntity = par1EntityLiving;
016        this.theWorld = par1EntityLiving.worldObj;
017        this.setMutexBits(3);
018    }
019
020    /**
021     * Returns whether the EntityAIBase should begin execution.
022     */
023    public boolean shouldExecute()
024    {
025        EntityLiving entityliving = this.theEntity.getAttackTarget();
026
027        if (entityliving == null)
028        {
029            return false;
030        }
031        else
032        {
033            this.theVictim = entityliving;
034            return true;
035        }
036    }
037
038    /**
039     * Returns whether an in-progress EntityAIBase should continue executing
040     */
041    public boolean continueExecuting()
042    {
043        return !this.theVictim.isEntityAlive() ? false : (this.theEntity.getDistanceSqToEntity(this.theVictim) > 225.0D ? false : !this.theEntity.getNavigator().noPath() || this.shouldExecute());
044    }
045
046    /**
047     * Resets the task
048     */
049    public void resetTask()
050    {
051        this.theVictim = null;
052        this.theEntity.getNavigator().clearPathEntity();
053    }
054
055    /**
056     * Updates the task
057     */
058    public void updateTask()
059    {
060        this.theEntity.getLookHelper().setLookPositionWithEntity(this.theVictim, 30.0F, 30.0F);
061        double d0 = (double)(this.theEntity.width * 2.0F * this.theEntity.width * 2.0F);
062        double d1 = this.theEntity.getDistanceSq(this.theVictim.posX, this.theVictim.boundingBox.minY, this.theVictim.posZ);
063        float f = 0.23F;
064
065        if (d1 > d0 && d1 < 16.0D)
066        {
067            f = 0.4F;
068        }
069        else if (d1 < 225.0D)
070        {
071            f = 0.18F;
072        }
073
074        this.theEntity.getNavigator().tryMoveToEntityLiving(this.theVictim, f);
075        this.attackCountdown = Math.max(this.attackCountdown - 1, 0);
076
077        if (d1 <= d0)
078        {
079            if (this.attackCountdown <= 0)
080            {
081                this.attackCountdown = 20;
082                this.theEntity.attackEntityAsMob(this.theVictim);
083            }
084        }
085    }
086}