    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 var1 = this.leaper.getDistanceSqToEntity(this.leapTarget);
    038            return var1 >= 4.0D && var1 <= 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 var1 = this.leapTarget.posX - this.leaper.posX;
    056        double var3 = this.leapTarget.posZ - this.leaper.posZ;
    057        float var5 = MathHelper.sqrt_double(var1 * var1 + var3 * var3);
    058        this.leaper.motionX += var1 / (double)var5 * 0.5D * 0.800000011920929D + this.leaper.motionX * 0.20000000298023224D;
    059        this.leaper.motionZ += var3 / (double)var5 * 0.5D * 0.800000011920929D + this.leaper.motionZ * 0.20000000298023224D;
    060        this.leaper.motionY = (double)this.leapMotionY;
    061    }
    062}