Implemented path navigator and move helper for flying NPCs (npc.getNavigator() and npc.getMoveHelper() used to return the default navigator and move helper, added override function).

Improved Flying AI getting stuck when trying to get over a block towards the enemy.
This commit is contained in:
luisc committed 2021-12-07 03:57:57 -06:00
1 parent 12333de3a1
commit 43b3241801
4 files changed
+602 -68

No files matched your search

@@ -31,7 +31,7 @@ public abstract class EntityNPCFlying extends EntityNPCInterface {
public void onLivingUpdate()
{
if(!canFly()){
if(!canFly() || this.isJumping){
super.onLivingUpdate();
return;
}
@@ -41,23 +41,24 @@ public abstract class EntityNPCFlying extends EntityNPCInterface {
if(isEntityAlive()) {
if (!this.worldObj.isRemote) {
Entity entity = this.getAttackTarget();
if (entity != null && entity.isEntityAlive()) {
double d0 = entity.posX - this.posX;
double d2 = entity.posZ - this.posZ;
double d3 = d0 * d0 + d2 * d2;
Entity target = this.getAttackTarget();
if (target != null && target.isEntityAlive()) {
double d0 = target.posX - this.posX;
double d1 = target.posY - this.posY;
double d2 = target.posZ - this.posZ;
double d4 = d0 * d0 + d1 * d1 + d2 * d2;
if(this.hurtTime == 0) {
if (this.posY != entity.posY) {
if (this.motionY * Math.signum(this.posY - entity.posY) > 0.0D) {
if (this.posY != target.posY) {
if (this.motionY * Math.signum(this.posY - target.posY) > 0.0D) {
this.motionY = 0.0D;
}
this.motionY -= Math.signum(this.posY - entity.posY) * (speed * speedMult) * this.ai.flySpeed;
this.motionY -= Math.signum(this.posY - target.posY) * (speed * speedMult) * this.ai.flySpeed;
}
if (d3 > 9.0D) {
double d5 = MathHelper.sqrt_double(d3);
if (d4 > 0.5D) {
double d5 = MathHelper.sqrt_double(d4);
this.motionX += (d0 / d5 * speed - this.motionX) * speed * speedMult;
this.motionZ += (d2 / d5 * speed - this.motionZ) * speed * speedMult;
}