From 69afa29e9cd5f8fd808ae5234e1380eacabe878c Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Mon, 14 Nov 2022 20:22:50 -0600 Subject: [PATCH] EntityNPCFlying: -Fixed fly height limit --- .../java/noppes/npcs/entity/EntityNPCFlying.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/entity/EntityNPCFlying.java b/src/main/java/noppes/npcs/entity/EntityNPCFlying.java index 172c62dc9..86dd84c19 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCFlying.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCFlying.java @@ -1,6 +1,7 @@ package noppes.npcs.entity; -import net.minecraft.init.Blocks; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; import net.minecraft.world.World; public abstract class EntityNPCFlying extends EntityNPCInterface { @@ -40,8 +41,19 @@ public abstract class EntityNPCFlying extends EntityNPCInterface { return; } + boolean aboveLimit = false; double heightOffGround = this.posY - this.worldObj.getTopSolidOrLiquidBlock((int) this.posX, (int) this.posZ); - if (heightOffGround > this.ai.flyHeightLimit && this.ai.hasFlyLimit || (heightOffGround < Math.ceil(this.height) && this.motionY == 0)) { + if (heightOffGround < 0) { + Vec3 pos = Vec3.createVectorHelper(this.posX,this.posY,this.posZ); + Vec3 posLimit = Vec3.createVectorHelper(this.posX,this.posY - this.ai.flyHeightLimit,this.posZ); + MovingObjectPosition mob = this.worldObj.rayTraceBlocks(pos,posLimit,true); + if (mob == null || mob.typeOfHit == MovingObjectPosition.MovingObjectType.MISS) { + aboveLimit = true; + } + } else if (heightOffGround > this.ai.flyHeightLimit) { + aboveLimit = true; + } + if (aboveLimit && this.ai.hasFlyLimit || (heightOffGround < Math.ceil(this.height) && this.motionY == 0)) { this.flyLimitAllow = false; if (!this.getNavigator().noPath() && this.motionY > 0) { this.motionY = 0;