Skip to content

Commit

Permalink
Add a way to show all ordered waypoints at once (#688)
Browse files Browse the repository at this point in the history
  • Loading branch information
AzureAaron authored May 9, 2024
1 parent 6d1a731 commit 301ad26
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class OrderedWaypoints {
private static final float[] LIGHT_GRAY = { 192 / 255f, 192 / 255f, 192 / 255f };

private static CompletableFuture<Void> loaded;
private static boolean showAll;

public static void init() {
ClientLifecycleEvents.CLIENT_STARTED.register(_client -> load());
Expand Down Expand Up @@ -114,6 +115,8 @@ private static void registerCommands(CommandDispatcher<FabricClientCommandSource
.then(argument("groupName", word())
.suggests((source, builder) -> CommandSource.suggestMatching(WAYPOINTS.keySet(), builder))
.executes(context -> toggleGroup(context.getSource(), getString(context, "groupName")))))
.then(literal("showAll")
.executes(context -> showAll(context.getSource())))
.then(literal("import")
.then(literal("coleWeight")
.then(argument("groupName", word())
Expand Down Expand Up @@ -215,39 +218,54 @@ private static int toggleGroup(FabricClientCommandSource source, String groupNam
return Command.SINGLE_SUCCESS;
}

private static int showAll(FabricClientCommandSource source) {
source.sendFeedback(Constants.PREFIX.get().append(Text.translatable("skyblocker.waypoints.ordered.showAll")));
showAll = !showAll;

return Command.SINGLE_SUCCESS;
}

private static void render(WorldRenderContext wrc) {
if ((Utils.isInCrystalHollows() || Utils.isInDwarvenMines()) && loaded.isDone() && SEMAPHORE.tryAcquire()) {
for (OrderedWaypointGroup group : WAYPOINTS.values()) {
if (group.enabled()) {
List<OrderedWaypoint> waypoints = group.waypoints();
if (waypoints.isEmpty()) continue;
ClientPlayerEntity player = MinecraftClient.getInstance().player;
int centreIndex = INDEX_STORE.computeIfAbsent(group.name(), name -> 0);

for (int i = 0; i < waypoints.size(); i++) {
OrderedWaypoint waypoint = waypoints.get(i);
if (!showAll) {
ClientPlayerEntity player = MinecraftClient.getInstance().player;
int centreIndex = INDEX_STORE.computeIfAbsent(group.name(), name -> 0);

if (waypoint.getPos().isWithinDistance(player.getPos(), RADIUS)) {
centreIndex = i;
INDEX_STORE.put(group.name(), i);
for (int i = 0; i < waypoints.size(); i++) {
OrderedWaypoint waypoint = waypoints.get(i);

break;
if (waypoint.getPos().isWithinDistance(player.getPos(), RADIUS)) {
centreIndex = i;
INDEX_STORE.put(group.name(), i);

break;
}
}
}

int previousIndex = (centreIndex - 1 + waypoints.size()) % waypoints.size();
int currentIndex = (centreIndex + waypoints.size()) % waypoints.size();
int nextIndex = (centreIndex + 1) % waypoints.size();
int previousIndex = (centreIndex - 1 + waypoints.size()) % waypoints.size();
int currentIndex = (centreIndex + waypoints.size()) % waypoints.size();
int nextIndex = (centreIndex + 1) % waypoints.size();

OrderedWaypoint previous = waypoints.get(previousIndex);
OrderedWaypoint current = waypoints.get(currentIndex);
OrderedWaypoint next = waypoints.get(nextIndex);
OrderedWaypoint previous = waypoints.get(previousIndex);
OrderedWaypoint current = waypoints.get(currentIndex);
OrderedWaypoint next = waypoints.get(nextIndex);

previous.render(wrc, RelativeIndex.PREVIOUS, previousIndex);
current.render(wrc, RelativeIndex.CURRENT, currentIndex);
next.render(wrc, RelativeIndex.NEXT, nextIndex);
previous.render(wrc, RelativeIndex.PREVIOUS, previousIndex);
current.render(wrc, RelativeIndex.CURRENT, currentIndex);
next.render(wrc, RelativeIndex.NEXT, nextIndex);

RenderHelper.renderLineFromCursor(wrc, Vec3d.ofCenter(next.getPos().up()), LIGHT_GRAY, 1f, 5f);
RenderHelper.renderLineFromCursor(wrc, Vec3d.ofCenter(next.getPos().up()), LIGHT_GRAY, 1f, 5f);
} else {
for (int i = 0; i < waypoints.size(); i++) {
//Render them as white by default
waypoints.get(i).render(wrc, RelativeIndex.CURRENT, i);
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@
"skyblocker.waypoints.ordered.remove.success": "Successfully removed the waypoint at %s from group %s.",
"skyblocker.waypoints.ordered.removeAt.success": "Successfully removed the waypoint at index %d from group %s.",
"skyblocker.waypoints.ordered.toggle.success": "Toggled the waypoint group %s.",
"skyblocker.waypoints.ordered.showAll": "Toggled showing all waypoints from enabled groups.",
"skyblocker.waypoints.ordered.export.success": "Successfully copied your waypoints to your clipboard!",
"skyblocker.waypoints.ordered.export.fail": "§cFailed to export your waypoints, check the latest.log for more information.",
"skyblocker.waypoints.ordered.import.skyblocker.success": "Successfully imported waypoints from the Skyblocker Ordered Waypoints format!",
Expand Down

0 comments on commit 301ad26

Please sign in to comment.