Skip to content

Commit

Permalink
Update guided help
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Sep 12, 2023
1 parent 8ca064a commit bec5329
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
Expand Up @@ -96,17 +96,28 @@ public void begin() {
Messaging.sendTr(player, Messages.GUIDED_WAYPOINT_EDITOR_BEGIN);
}

private void createWaypointMarkers() {
for (Waypoint waypoint : waypoints()) {
createWaypointMarkerWithData(waypoint);
private void createDestinationMarker(Waypoint element) {
NPC npc = createMarker(element);
if (npc != null) {
npc.data().set(NPC.Metadata.GLOWING, true);
}
}

private void createWaypointMarkerWithData(Waypoint element) {
private NPC createMarker(Waypoint element) {
Entity entity = markers.createMarker(element, element.getLocation().clone().add(0, 1, 0));
if (entity == null)
return;
return null;
((NPCHolder) entity).getNPC().data().setPersistent("waypointhashcode", element.hashCode());
return ((NPCHolder) entity).getNPC();
}

private void createWaypointMarkers() {
for (Waypoint waypoint : guides) {
createMarker(waypoint);
}
for (Waypoint waypoint : destinations) {
createDestinationMarker(waypoint);
}
}

@Override
Expand Down Expand Up @@ -168,7 +179,11 @@ public void onPlayerInteract(PlayerInteractEvent event) {
Messaging.sendTr(player, Messages.GUIDED_WAYPOINT_EDITOR_ADDED_GUIDE);
}
if (showPath) {
createWaypointMarkerWithData(element);
if (player.isSneaking()) {
createDestinationMarker(element);
} else {
createMarker(element);
}
}
rebuildTree();
}
Expand Down Expand Up @@ -304,6 +319,7 @@ public Iterable<Waypoint> waypoints() {

private class GuidedAIGoal implements Goal {
private GuidedPlan plan;
private Waypoint target;

public void onProviderChanged() {
if (plan == null)
Expand All @@ -317,11 +333,15 @@ public void onProviderChanged() {
@Override
public void reset() {
plan = null;
target = null;
}

@Override
public void run(GoalSelector selector) {
if (plan == null || plan.isComplete()) {
if (plan.isComplete()) {
target.onReach(npc);
}
selector.finish();
return;
}
Expand All @@ -343,7 +363,7 @@ public boolean shouldExecute(GoalSelector selector) {
if (paused || destinations.size() == 0 || !npc.isSpawned() || npc.getNavigator().isNavigating())
return false;

Waypoint target = destinations.get(Util.getFastRandom().nextInt(destinations.size()));
this.target = destinations.get(Util.getFastRandom().nextInt(destinations.size()));
plan = ASTAR.runFully(new GuidedGoal(target), new GuidedNode(null, new Waypoint(npc.getStoredLocation())));
return plan != null;
}
Expand Down
2 changes: 1 addition & 1 deletion main/src/main/resources/messages_en.properties
Expand Up @@ -419,7 +419,7 @@ citizens.editors.waypoints.wander.added-region=[[Added]] wanderable region at ({
citizens.editors.waypoints.wander.removed-region=[[Removed]] wanderable region at ({0}) ([[{1}]] remaining).
citizens.editors.waypoints.wander.editing-regions=Now editing regions!<br> [[Left click]] to add a new wanderable region using the xrange/yrange box centred at that block.<br> [[Right click]] an existing marker to remove that region.<br> Type [[regions]] to stop or simply exit the editor. Regions should be overlap or touch each other.
citizens.editors.waypoints.guided.end=Exited the guided waypoint editor.
citizens.editors.waypoints.guided.begin=Entered the guided waypoint editor! The NPC will randomly walk to a [[destination]] waypoint following the nearest [[guide]] point. For example, try putting guide points on a road and destinations inside houses!<br> [[Left click]] to add a guide waypoint and [[right click]] to remove an existing waypoint.<br> [[Sneak]] while left clicking to add a destination waypoint.<br> Type [[toggle path]] to toggle showing entities at waypoints.<br> Type [[clear]] to clear all waypoints.
citizens.editors.waypoints.guided.begin=Entered the guided waypoint editor! The NPC will randomly walk to a [[destination]] waypoint following the nearest [[guide]] point. For example, try putting guide points on a road and destinations inside houses!<br> [[Left click]] to add a guide waypoint and [[right click]] to remove.<br> [[Sneak]] while left clicking to add a destination waypoint.<br> Type [[toggle path]] to toggle showing entities at waypoints.<br> Type [[clear]] to clear all waypoints.<br> Type [[distance <distance>]] to adjust the pathfinding range.
citizens.editors.waypoints.guided.added-guide=Added a [[guide]] waypoint which the NPC will follow on the way to their destination.
citizens.editors.waypoints.guided.added-available=Added a [[destination]] waypoint which the NPC will randomly pathfind between.
citizens.editors.waypoints.guided.already-taken=There is already a waypoint here.
Expand Down

0 comments on commit bec5329

Please sign in to comment.