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