From 9a7758a27bea7ce75cdd62978fe77c2c4501b134 Mon Sep 17 00:00:00 2001 From: KAMKEEL <28842281+KAMKEEL@users.noreply.github.com> Date: Thu, 1 Oct 2026 02:58:31 -0400 Subject: [PATCH] Cut wasted NPC tick work and stop the flying flag flipping every tick --- src/main/java/noppes/npcs/entity/EntityNPCFlying.java | 6 +++--- src/main/java/noppes/npcs/entity/EntityNPCInterface.java | 9 +++++++-- src/main/java/noppes/npcs/entity/data/DataTimers.java | 3 +++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/noppes/npcs/entity/EntityNPCFlying.java b/src/main/java/noppes/npcs/entity/EntityNPCFlying.java index c41e0e843..3c3189fd2 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCFlying.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCFlying.java @@ -46,7 +46,7 @@ public abstract class EntityNPCFlying extends EntityNPCInterface { return; if (!this.canFly() || this.hurtTime != 0 || !this.canBreathe()) { setNpcFlyingState(false); - super.moveEntityWithHeading(p_70612_1_, p_70612_2_); + moveWithoutMountHandling(p_70612_1_, p_70612_2_); return; } @@ -70,7 +70,7 @@ public abstract class EntityNPCFlying extends EntityNPCInterface { } else if (heightOffGround < Math.ceil(this.height) && this.motionY == 0) { this.flyLimitAllow = false; setNpcFlyingState(false); - super.moveEntityWithHeading(p_70612_1_, p_70612_2_); + moveWithoutMountHandling(p_70612_1_, p_70612_2_); return; } this.flyLimitAllow = true; @@ -81,7 +81,7 @@ public abstract class EntityNPCFlying extends EntityNPCInterface { desiredMotionY = -Math.abs(this.ais.flyGravity); } this.motionY = desiredMotionY; - super.moveEntityWithHeading(p_70612_1_, p_70612_2_); + moveWithoutMountHandling(p_70612_1_, p_70612_2_); this.motionY = desiredMotionY; this.updateLimbSwing(); diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 954db1f58..19d7e3ae9 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -434,7 +434,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti if (this.ticksExisted % 20 == 0) faction = getFaction(); if (!worldObj.isRemote) { - if (!isKilled() && this.ticksExisted % 20 == 0) { + if (this.ticksExisted % 20 == 0 && !isKilled()) { if (this.getHealth() < this.getMaxHealth()) { if (stats.healthRegen > 0 && !isAttacking()) heal(stats.healthRegen); @@ -1423,7 +1423,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti } public void onCollide() { - if (!isEntityAlive() || ticksExisted % 4 != 0) + if (ticksExisted % 4 != 0 || !isEntityAlive()) return; AxisAlignedBB axisalignedbb = null; @@ -2277,6 +2277,11 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti if (handleMountedMovement(strafe, forward)) { return; } + moveWithoutMountHandling(strafe, forward); + } + + /** Normal movement, for callers that already ran the mount handling this tick. */ + protected void moveWithoutMountHandling(float strafe, float forward) { double d0 = this.posX; double d1 = this.posY; double d2 = this.posZ; diff --git a/src/main/java/noppes/npcs/entity/data/DataTimers.java b/src/main/java/noppes/npcs/entity/data/DataTimers.java index 9f555cdca..953883c49 100644 --- a/src/main/java/noppes/npcs/entity/data/DataTimers.java +++ b/src/main/java/noppes/npcs/entity/data/DataTimers.java @@ -140,6 +140,9 @@ public class DataTimers implements ITimers { } public void update() { + // Runs every tick for every npc and player. Most have no timers, so skip the copy. + if (this.timers.isEmpty()) + return; Iterator var1 = (new ArrayList<>(this.timers.values())).iterator(); while (var1.hasNext()) {