diff --git a/main/src/main/java/net/citizensnpcs/npc/ai/AStarNavigationStrategy.java b/main/src/main/java/net/citizensnpcs/npc/ai/AStarNavigationStrategy.java index 710fa088b..f19bb929c 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/AStarNavigationStrategy.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/AStarNavigationStrategy.java @@ -136,7 +136,7 @@ public class AStarNavigationStrategy extends AbstractPathStrategy { } Location loc = npc.getEntity().getLocation(NPC_LOCATION); /* Proper door movement - gets stuck on corners at times - + Block block = currLoc.getWorld().getBlockAt(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); if (MinecraftBlockExaminer.isDoor(block.getType())) { Door door = (Door) block.getState().getData(); @@ -176,7 +176,6 @@ public class AStarNavigationStrategy extends AbstractPathStrategy { npc.getEntity().setVelocity(dir); Util.faceLocation(npc.getEntity(), dest); } - params.run(); plan.run(npc); return false; } diff --git a/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java b/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java index 905140437..58baae96a 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java @@ -161,8 +161,8 @@ public class CitizensNavigator implements Navigator, Runnable { if (!isNavigating() || !npc.isSpawned() || isPaused()) return; Location npcLoc = npc.getStoredLocation(); - if (!npcLoc.getWorld().equals(getTargetAsLocation().getWorld()) - || Math.pow(localParams.range(), 2) < npc.getStoredLocation().distanceSquared(getTargetAsLocation())) { + Location targetLoc = getTargetAsLocation(); + if (!npcLoc.getWorld().equals(targetLoc.getWorld()) || localParams.range() < npcLoc.distance(targetLoc)) { stopNavigating(CancelReason.STUCK); return; } @@ -170,6 +170,9 @@ public class CitizensNavigator implements Navigator, Runnable { return; updatePathfindingRange(); boolean finished = executing.update(); + if (!finished) { + localParams.run(); + } if (localParams.lookAtFunction() != null) { Util.faceLocation(npc.getEntity(), localParams.lookAtFunction().apply(this), true, true); Entity entity = npc.getEntity().getPassenger(); @@ -182,9 +185,9 @@ public class CitizensNavigator implements Navigator, Runnable { } } if (localParams.destinationTeleportMargin() > 0 - && npcLoc.distance(getTargetAsLocation()) < localParams.destinationTeleportMargin()) { + && npcLoc.distance(targetLoc) < localParams.destinationTeleportMargin()) { // TODO: easing? - npc.teleport(getTargetAsLocation(), TeleportCause.PLUGIN); + npc.teleport(targetLoc, TeleportCause.PLUGIN); finished = true; } if (!finished) { diff --git a/main/src/main/java/net/citizensnpcs/npc/ai/FlyingAStarNavigationStrategy.java b/main/src/main/java/net/citizensnpcs/npc/ai/FlyingAStarNavigationStrategy.java index 032531901..4329d9019 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/FlyingAStarNavigationStrategy.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/FlyingAStarNavigationStrategy.java @@ -181,7 +181,6 @@ public class FlyingAStarNavigationStrategy extends AbstractPathStrategy { NMS.setVerticalMovement(npc.getEntity(), 0.5); Util.faceLocation(npc.getEntity(), centeredDest.toLocation(npc.getEntity().getWorld())); } - parameters.run(); plan.run(npc); return false; } diff --git a/main/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java b/main/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java index f87f4852b..d3dfd6bf2 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java @@ -76,7 +76,6 @@ public class MCNavigationStrategy extends AbstractPathStrategy { if (getCancelReason() != null) return true; boolean wasFinished = navigator.update(); - parameters.run(); Location loc = handle.getLocation(HANDLE_LOCATION); double dX = target.getX() - loc.getX(); double dZ = target.getZ() - loc.getZ(); diff --git a/main/src/main/java/net/citizensnpcs/npc/ai/StraightLineNavigationStrategy.java b/main/src/main/java/net/citizensnpcs/npc/ai/StraightLineNavigationStrategy.java index 39321c7e3..a0510a63c 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/StraightLineNavigationStrategy.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/StraightLineNavigationStrategy.java @@ -120,7 +120,6 @@ public class StraightLineNavigationStrategy extends AbstractPathStrategy { Util.faceLocation(npc.getEntity(), destLoc); npc.getEntity().setVelocity(dir); } - params.run(); return false; }