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