mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 19:59:56 +00:00
Refactor mount helpers and expose NPC flight state
This commit is contained in:
1 parent
6c84263769
commit
9744209938
31 files changed
+821
-305
No files matched your search
@@ -0,0 +1,63 @@
|
||||
package noppes.npcs.ai;
|
||||
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.ai.EntityAIBase;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
public class EntityAILeapAtTargetNpc extends EntityAIBase {
|
||||
private final EntityNPCInterface npc;
|
||||
private EntityLivingBase leapTarget;
|
||||
private final float leapMotionY;
|
||||
|
||||
public EntityAILeapAtTargetNpc(EntityNPCInterface npc, float leapMotionY) {
|
||||
this.npc = npc;
|
||||
this.leapMotionY = leapMotionY;
|
||||
this.setMutexBits(5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldExecute() {
|
||||
this.leapTarget = this.npc.getAttackTarget();
|
||||
if (this.leapTarget == null) {
|
||||
return false;
|
||||
}
|
||||
double distanceSq = this.npc.getDistanceSqToEntity(this.leapTarget);
|
||||
if (distanceSq < 4.0D || distanceSq > 16.0D) {
|
||||
return false;
|
||||
}
|
||||
if (!this.npc.onGround) {
|
||||
return false;
|
||||
}
|
||||
return this.npc.getRNG().nextInt(5) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean continueExecuting() {
|
||||
boolean airborne = !this.npc.onGround;
|
||||
if (!airborne) {
|
||||
this.npc.setNpcJumpingState(false);
|
||||
}
|
||||
return airborne;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startExecuting() {
|
||||
double d0 = this.leapTarget.posX - this.npc.posX;
|
||||
double d1 = this.leapTarget.posZ - this.npc.posZ;
|
||||
float f = MathHelper.sqrt_double(d0 * d0 + d1 * d1);
|
||||
|
||||
if ((double) f >= 1.0E-4D) {
|
||||
this.npc.motionX += d0 / (double) f * 0.5D * 0.8D + this.npc.motionX * 0.2D;
|
||||
this.npc.motionZ += d1 / (double) f * 0.5D * 0.8D + this.npc.motionZ * 0.2D;
|
||||
}
|
||||
|
||||
this.npc.motionY = this.leapMotionY;
|
||||
this.npc.setNpcJumpingState(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetTask() {
|
||||
this.npc.setNpcJumpingState(false);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user