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 f39c07598..08b726042 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/AStarNavigationStrategy.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/AStarNavigationStrategy.java @@ -26,6 +26,7 @@ public class AStarNavigationStrategy extends AbstractPathStrategy { private final NPC npc; private final NavigatorParameters params; private Path plan; + private boolean planned = false; private Vector vector; public AStarNavigationStrategy(NPC npc, Iterable path, NavigatorParameters params) { @@ -42,11 +43,6 @@ public class AStarNavigationStrategy extends AbstractPathStrategy { this.params = params; this.destination = dest; this.npc = npc; - Location location = npc.getEntity().getLocation(); - VectorGoal goal = new VectorGoal(dest, (float) params.pathDistanceMargin()); - setPlan(ASTAR.runFully(goal, - new VectorNode(goal, location, new ChunkBlockSource(location, params.range()), params.examiners()), - 50000)); } @Override @@ -61,6 +57,7 @@ public class AStarNavigationStrategy extends AbstractPathStrategy { public void setPlan(Path path) { this.plan = path; + this.planned = true; if (plan == null || plan.isComplete()) { setCancelReason(CancelReason.STUCK); } else { @@ -81,6 +78,13 @@ public class AStarNavigationStrategy extends AbstractPathStrategy { @Override public boolean update() { + if (!planned) { + Location location = npc.getEntity().getLocation(); + VectorGoal goal = new VectorGoal(destination, (float) params.pathDistanceMargin()); + setPlan(ASTAR.runFully(goal, + new VectorNode(goal, location, new ChunkBlockSource(location, params.range()), params.examiners()), + 50000)); + } if (getCancelReason() != null || plan == null || plan.isComplete()) { return true; } 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 0226fac69..98cd565c3 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/FlyingAStarNavigationStrategy.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/FlyingAStarNavigationStrategy.java @@ -28,6 +28,7 @@ public class FlyingAStarNavigationStrategy extends AbstractPathStrategy { private final NPC npc; private final NavigatorParameters parameters; private Path plan; + private boolean planned; private final Location target; private Vector vector; @@ -45,21 +46,6 @@ public class FlyingAStarNavigationStrategy extends AbstractPathStrategy { this.target = dest; this.parameters = params; this.npc = npc; - Location location = npc.getEntity().getLocation(); - VectorGoal goal = new VectorGoal(dest, (float) params.pathDistanceMargin()); - boolean found = false; - for (BlockExaminer examiner : params.examiners()) { - if (examiner instanceof FlyingBlockExaminer) { - found = true; - break; - } - } - if (!found) { - params.examiner(new FlyingBlockExaminer()); - } - setPlan(ASTAR.runFully(goal, - new VectorNode(goal, location, new ChunkBlockSource(location, params.range()), params.examiners()), - 50000)); } @Override @@ -94,6 +80,22 @@ public class FlyingAStarNavigationStrategy extends AbstractPathStrategy { @Override public boolean update() { + if (!planned) { + Location location = npc.getEntity().getLocation(); + VectorGoal goal = new VectorGoal(target, (float) parameters.pathDistanceMargin()); + boolean found = false; + for (BlockExaminer examiner : parameters.examiners()) { + if (examiner instanceof FlyingBlockExaminer) { + found = true; + break; + } + } + if (!found) { + parameters.examiner(new FlyingBlockExaminer()); + } + setPlan(ASTAR.runFully(goal, new VectorNode(goal, location, + new ChunkBlockSource(location, parameters.range()), parameters.examiners()), 50000)); + } if (getCancelReason() != null || plan == null || plan.isComplete()) { return true; } diff --git a/main/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java b/main/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java index 8673a3cab..0e2b5efab 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java @@ -24,7 +24,7 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget { private final NavigatorParameters parameters; private final Entity target; private final TargetNavigator targetNavigator; - private int updateCounter; + private int updateCounter = -1; public MCTargetStrategy(NPC npc, org.bukkit.entity.Entity target, boolean aggro, NavigatorParameters params) { this.npc = npc; @@ -115,7 +115,7 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget { if (!aggro && distanceSquared() <= parameters.distanceMargin()) { stop(); return false; - } else if (updateCounter++ > parameters.updatePathRate()) { + } else if (updateCounter == -1 || updateCounter++ > parameters.updatePathRate()) { targetNavigator.setPath(); updateCounter = 0; } @@ -141,10 +141,6 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget { private int failureTimes = 0; private PathStrategy strategy; - public AStarTargeter() { - setStrategy(); - } - @Override public Iterable getPath() { return strategy.getPath();