Make NavigatorParameters#run run consistently

This commit is contained in:
fullwall 2022-02-13 21:39:22 +08:00
parent 676590f5fe
commit 5bf9fdc6c9
5 changed files with 8 additions and 9 deletions

View File

@ -136,7 +136,7 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
} }
Location loc = npc.getEntity().getLocation(NPC_LOCATION); Location loc = npc.getEntity().getLocation(NPC_LOCATION);
/* Proper door movement - gets stuck on corners at times /* Proper door movement - gets stuck on corners at times
Block block = currLoc.getWorld().getBlockAt(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); Block block = currLoc.getWorld().getBlockAt(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
if (MinecraftBlockExaminer.isDoor(block.getType())) { if (MinecraftBlockExaminer.isDoor(block.getType())) {
Door door = (Door) block.getState().getData(); Door door = (Door) block.getState().getData();
@ -176,7 +176,6 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
npc.getEntity().setVelocity(dir); npc.getEntity().setVelocity(dir);
Util.faceLocation(npc.getEntity(), dest); Util.faceLocation(npc.getEntity(), dest);
} }
params.run();
plan.run(npc); plan.run(npc);
return false; return false;
} }

View File

@ -161,8 +161,8 @@ public class CitizensNavigator implements Navigator, Runnable {
if (!isNavigating() || !npc.isSpawned() || isPaused()) if (!isNavigating() || !npc.isSpawned() || isPaused())
return; return;
Location npcLoc = npc.getStoredLocation(); Location npcLoc = npc.getStoredLocation();
if (!npcLoc.getWorld().equals(getTargetAsLocation().getWorld()) Location targetLoc = getTargetAsLocation();
|| Math.pow(localParams.range(), 2) < npc.getStoredLocation().distanceSquared(getTargetAsLocation())) { if (!npcLoc.getWorld().equals(targetLoc.getWorld()) || localParams.range() < npcLoc.distance(targetLoc)) {
stopNavigating(CancelReason.STUCK); stopNavigating(CancelReason.STUCK);
return; return;
} }
@ -170,6 +170,9 @@ public class CitizensNavigator implements Navigator, Runnable {
return; return;
updatePathfindingRange(); updatePathfindingRange();
boolean finished = executing.update(); boolean finished = executing.update();
if (!finished) {
localParams.run();
}
if (localParams.lookAtFunction() != null) { if (localParams.lookAtFunction() != null) {
Util.faceLocation(npc.getEntity(), localParams.lookAtFunction().apply(this), true, true); Util.faceLocation(npc.getEntity(), localParams.lookAtFunction().apply(this), true, true);
Entity entity = npc.getEntity().getPassenger(); Entity entity = npc.getEntity().getPassenger();
@ -182,9 +185,9 @@ public class CitizensNavigator implements Navigator, Runnable {
} }
} }
if (localParams.destinationTeleportMargin() > 0 if (localParams.destinationTeleportMargin() > 0
&& npcLoc.distance(getTargetAsLocation()) < localParams.destinationTeleportMargin()) { && npcLoc.distance(targetLoc) < localParams.destinationTeleportMargin()) {
// TODO: easing? // TODO: easing?
npc.teleport(getTargetAsLocation(), TeleportCause.PLUGIN); npc.teleport(targetLoc, TeleportCause.PLUGIN);
finished = true; finished = true;
} }
if (!finished) { if (!finished) {

View File

@ -181,7 +181,6 @@ public class FlyingAStarNavigationStrategy extends AbstractPathStrategy {
NMS.setVerticalMovement(npc.getEntity(), 0.5); NMS.setVerticalMovement(npc.getEntity(), 0.5);
Util.faceLocation(npc.getEntity(), centeredDest.toLocation(npc.getEntity().getWorld())); Util.faceLocation(npc.getEntity(), centeredDest.toLocation(npc.getEntity().getWorld()));
} }
parameters.run();
plan.run(npc); plan.run(npc);
return false; return false;
} }

View File

@ -76,7 +76,6 @@ public class MCNavigationStrategy extends AbstractPathStrategy {
if (getCancelReason() != null) if (getCancelReason() != null)
return true; return true;
boolean wasFinished = navigator.update(); boolean wasFinished = navigator.update();
parameters.run();
Location loc = handle.getLocation(HANDLE_LOCATION); Location loc = handle.getLocation(HANDLE_LOCATION);
double dX = target.getX() - loc.getX(); double dX = target.getX() - loc.getX();
double dZ = target.getZ() - loc.getZ(); double dZ = target.getZ() - loc.getZ();

View File

@ -120,7 +120,6 @@ public class StraightLineNavigationStrategy extends AbstractPathStrategy {
Util.faceLocation(npc.getEntity(), destLoc); Util.faceLocation(npc.getEntity(), destLoc);
npc.getEntity().setVelocity(dir); npc.getEntity().setVelocity(dir);
} }
params.run();
return false; return false;
} }