Skip to content

Commit

Permalink
Check destination world matches NPC world in guided AI goal
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Nov 2, 2023
1 parent 4705cff commit 3395502
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ public boolean shouldExecute(GoalSelector selector) {
return false;

this.target = destinations.get(Util.getFastRandom().nextInt(destinations.size()));
if (target.getLocation().getWorld().equals(npc.getEntity().getWorld())) {
target = null;
return false;
}

plan = ASTAR.runFully(new GuidedGoal(target), new GuidedNode(null, new Waypoint(npc.getStoredLocation())));
return plan != null;
}
Expand Down Expand Up @@ -436,12 +441,12 @@ public boolean equals(Object obj) {
@Override
public Iterable<AStarNode> getNeighbours() {
PhTree<Waypoint> source = getParent() == null ? tree : treePlusDestinations;
PhRangeQuery<Waypoint> rq = source.rangeQuery(
PhRangeQuery<Waypoint> query = source.rangeQuery(
distance == -1 ? npc.getNavigator().getDefaultParameters().range() : distance,
waypoint.getLocation().getBlockX(), waypoint.getLocation().getBlockY(),
waypoint.getLocation().getBlockZ());
List<AStarNode> neighbours = Lists.newArrayList();
rq.forEachRemaining(n -> neighbours.add(new GuidedNode(this, n)));
query.forEachRemaining(wp -> neighbours.add(new GuidedNode(this, wp)));

return neighbours;
}
Expand Down

0 comments on commit 3395502

Please sign in to comment.