tcr/java/src/game/ai/EntityAILeapAtTarget.java

63 lines
1.8 KiB
Java
Raw Normal View History

2025-03-11 00:23:54 +01:00
package game.ai;
import game.entity.types.EntityLiving;
import game.util.ExtMath;
2025-03-11 00:23:54 +01:00
public class EntityAILeapAtTarget extends EntityAIBase
{
/** The entity that is leaping. */
EntityLiving leaper;
/** The entity that the leaper is leaping towards. */
EntityLiving leapTarget;
/** The entity's motionY after leaping. */
float leapMotionY;
public EntityAILeapAtTarget(EntityLiving leapingEntity, float leapMotionYIn)
{
this.leaper = leapingEntity;
this.leapMotionY = leapMotionYIn;
this.setMutexBits(5);
}
/**
* Returns whether the EntityAIBase should begin execution.
*/
public boolean shouldExecute()
{
this.leapTarget = this.leaper.getAttackTarget();
if (this.leapTarget == null)
{
return false;
}
else
{
double d0 = this.leaper.getDistanceSqToEntity(this.leapTarget);
return d0 >= 4.0D && d0 <= 16.0D ? (!this.leaper.onGround ? false : this.leaper.getRNG().zrange(5) == 0) : false;
}
}
/**
* Returns whether an in-progress EntityAIBase should continue executing
*/
public boolean continueExecuting()
{
return !this.leaper.onGround;
}
/**
* Execute a one shot task or start executing a continuous task
*/
public void startExecuting()
{
double d0 = this.leapTarget.posX - this.leaper.posX;
double d1 = this.leapTarget.posZ - this.leaper.posZ;
float f = ExtMath.sqrtd(d0 * d0 + d1 * d1);
this.leaper.motionX += d0 / (double)f * 0.5D * 0.800000011920929D + this.leaper.motionX * 0.20000000298023224D;
this.leaper.motionZ += d1 / (double)f * 0.5D * 0.800000011920929D + this.leaper.motionZ * 0.20000000298023224D;
this.leaper.motionY = (double)this.leapMotionY;
}
}