    001package net.minecraft.entity.ai;
    002
    003import net.minecraft.entity.EntityLiving;
    004import net.minecraft.util.MathHelper;
    005
    006public class EntityAILeapAtTarget extends EntityAIBase
    007{
    008    /** The entity that is leaping. */
    009    EntityLiving leaper;
    010
    011    /** The entity that the leaper is leaping towards. */
    012    EntityLiving leapTarget;
    013
    014    /** The entity's motionY after leaping. */
    015    float leapMotionY;
    016
    017    public EntityAILeapAtTarget(EntityLiving par1EntityLiving, float par2)
    018    {
    019        this.leaper = par1EntityLiving;
    020        this.leapMotionY = par2;
    021        this.setMutexBits(5);
    022    }
    023
    024    /**
    025     * Returns whether the EntityAIBase should begin execution.
    026     */
    027    public boolean shouldExecute()
    028    {
    029        this.leapTarget = this.leaper.getAttackTarget();
    030
    031        if (this.leapTarget == null)
    032        {
    033            return false;
    034        }
    035        else
    036        {
    037            double d0 = this.leaper.getDistanceSqToEntity(this.leapTarget);
    038            return d0 >= 4.0D && d0 <= 16.0D ? (!this.leaper.onGround ? false : this.leaper.getRNG().nextInt(5) == 0) : false;
    039        }
    040    }
    041
    042    /**
    043     * Returns whether an in-progress EntityAIBase should continue executing
    044     */
    045    public boolean continueExecuting()
    046    {
    047        return !this.leaper.onGround;
    048    }
    049
    050    /**
    051     * Execute a one shot task or start executing a continuous task
    052     */
    053    public void startExecuting()
    054    {
    055        double d0 = this.leapTarget.posX - this.leaper.posX;
    056        double d1 = this.leapTarget.posZ - this.leaper.posZ;
    057        float f = MathHelper.sqrt_double(d0 * d0 + d1 * d1);
    058        this.leaper.motionX += d0 / (double)f * 0.5D * 0.800000011920929D + this.leaper.motionX * 0.20000000298023224D;
    059        this.leaper.motionZ += d1 / (double)f * 0.5D * 0.800000011920929D + this.leaper.motionZ * 0.20000000298023224D;
    060        this.leaper.motionY = (double)this.leapMotionY;
    061    }
    062}