From a1eb8ff91b5837ce851aab07c6ac1400ae81bf9d Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Mon, 7 Nov 2022 13:01:57 -0600 Subject: [PATCH] Fixed odd NPC bobbing and NPCs with fly height limits not being able to path --- .../npcs/ai/pathfinder/FlyingMoveHelper.java | 13 ++----------- .../java/noppes/npcs/entity/EntityNPCFlying.java | 14 +++++++++++--- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/main/java/noppes/npcs/ai/pathfinder/FlyingMoveHelper.java b/src/main/java/noppes/npcs/ai/pathfinder/FlyingMoveHelper.java index 6132cd3b1..a003880bf 100644 --- a/src/main/java/noppes/npcs/ai/pathfinder/FlyingMoveHelper.java +++ b/src/main/java/noppes/npcs/ai/pathfinder/FlyingMoveHelper.java @@ -4,6 +4,7 @@ import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.EntityMoveHelper; import net.minecraft.init.Blocks; import net.minecraft.util.MathHelper; +import noppes.npcs.entity.EntityNPCFlying; import noppes.npcs.entity.EntityNPCInterface; public class FlyingMoveHelper extends EntityMoveHelper{ @@ -37,21 +38,11 @@ public class FlyingMoveHelper extends EntityMoveHelper{ double d5 = MathHelper.sqrt_double(d4); speed = Math.min(d5/5.0D,speed); - double heightOffGround = 0; - if(this.entity.ai.hasFlyLimit) { - for (int blockY = (int) this.posY; blockY > 0; blockY--) { - heightOffGround = this.posY - blockY; - if (this.entity.worldObj.getBlock((int) this.posX, blockY, (int) this.posZ) != Blocks.air || heightOffGround > this.entity.ai.flyHeightLimit){ - break; - } - } - } - if (this.entity.hurtTime == 0 && d4 > 0.5D) { this.entity.motionX += (speed * (d0 / d5) - this.entity.motionX) * speed; this.entity.motionZ += (speed * (d2 / d5) - this.entity.motionZ) * speed; - if (heightOffGround < this.entity.ai.flyHeightLimit || !this.entity.ai.hasFlyLimit) { + if (((EntityNPCFlying)this.entity).flyLimitAllow || !this.entity.ai.hasFlyLimit) { this.entity.motionY = verticalSpeed * (d1 / d5); if (this.entity.motionY > 0) { this.entity.motionY += 0.1D; diff --git a/src/main/java/noppes/npcs/entity/EntityNPCFlying.java b/src/main/java/noppes/npcs/entity/EntityNPCFlying.java index 65db536bc..dcadb4d1e 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCFlying.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCFlying.java @@ -5,6 +5,8 @@ import net.minecraft.world.World; public abstract class EntityNPCFlying extends EntityNPCInterface { + public boolean flyLimitAllow = false; + public EntityNPCFlying(World world) { super(world); } @@ -39,10 +41,16 @@ public abstract class EntityNPCFlying extends EntityNPCInterface { } double heightOffGround = this.posY - this.worldObj.getTopSolidOrLiquidBlock((int) this.posX, (int) this.posZ); - if (heightOffGround > this.ai.flyHeightLimit && this.ai.hasFlyLimit || heightOffGround < this.height) { - super.moveEntityWithHeading(p_70612_1_,p_70612_2_); - return; + if (heightOffGround > this.ai.flyHeightLimit && this.ai.hasFlyLimit || (heightOffGround < this.height && this.motionY == 0)) { + this.flyLimitAllow = false; + if (!this.getNavigator().noPath() && this.motionY > 0) { + this.motionY = 0; + } else { + super.moveEntityWithHeading(p_70612_1_, p_70612_2_); + return; + } } + this.flyLimitAllow = true; double d3 = this.motionY; super.moveEntityWithHeading(p_70612_1_, p_70612_2_);