    001    package net.minecraft.entity.ai;
    002
    003    import net.minecraft.entity.EntityLiving;
    004    import net.minecraft.world.World;
    005
    006    public 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 var1 = this.theEntity.getAttackTarget();
    026
    027            if (var1 == null)
    028            {
    029                return false;
    030            }
    031            else
    032            {
    033                this.theVictim = var1;
    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 var1 = (double)(this.theEntity.width * 2.0F * this.theEntity.width * 2.0F);
    062            double var3 = this.theEntity.getDistanceSq(this.theVictim.posX, this.theVictim.boundingBox.minY, this.theVictim.posZ);
    063            float var5 = 0.23F;
    064
    065            if (var3 > var1 && var3 < 16.0D)
    066            {
    067                var5 = 0.4F;
    068            }
    069            else if (var3 < 225.0D)
    070            {
    071                var5 = 0.18F;
    072            }
    073
    074            this.theEntity.getNavigator().tryMoveToEntityLiving(this.theVictim, var5);
    075            this.attackCountdown = Math.max(this.attackCountdown - 1, 0);
    076
    077            if (var3 <= var1)
    078            {
    079                if (this.attackCountdown <= 0)
    080                {
    081                    this.attackCountdown = 20;
    082                    this.theEntity.attackEntityAsMob(this.theVictim);
    083                }
    084            }
    085        }
    086    }