From 0cb976ce078b9b0217c9a8e5763638764d89a31e Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Tue, 7 May 2024 19:05:55 +0200 Subject: Add skipping ordered waypoints --- .../moe/nea/firmament/features/world/Waypoints.kt | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/main/kotlin/moe/nea/firmament') diff --git a/src/main/kotlin/moe/nea/firmament/features/world/Waypoints.kt b/src/main/kotlin/moe/nea/firmament/features/world/Waypoints.kt index b41c31a..bad82b0 100644 --- a/src/main/kotlin/moe/nea/firmament/features/world/Waypoints.kt +++ b/src/main/kotlin/moe/nea/firmament/features/world/Waypoints.kt @@ -45,9 +45,8 @@ object Waypoints : FirmamentFeature { object TConfig : ManagedConfig(identifier) { val tempWaypointDuration by duration("temp-waypoint-duration", 0.seconds, 1.hours) { 30.seconds } val showIndex by toggle("show-index") { true } + val skipToNearest by toggle("skip-to-nearest") { false } // TODO: look ahead size - // TODO: skip to nearest/skip to next only - // TODO: skip command } data class TemporaryWaypoint( @@ -148,6 +147,16 @@ object Waypoints : FirmamentFeature { source.sendFeedback(Text.translatable("firmament.command.waypoint.ordered.toggle.$ordered")) } } + thenLiteral("skip") { + thenExecute { + if (ordered && waypoints.isNotEmpty()) { + orderedIndex = (orderedIndex + 1) % waypoints.size + source.sendFeedback(Text.translatable("firmament.command.waypoint.skip")) + } else { + source.sendError(Text.translatable("firmament.command.waypoint.skip.error")) + } + } + } thenLiteral("remove") { thenArgument("index", IntegerArgumentType.integer(0)) { indexArg -> thenExecute { @@ -230,8 +239,13 @@ object Waypoints : FirmamentFeature { if (waypoints.isEmpty() || !ordered) return@subscribe orderedIndex %= waypoints.size val p = MC.player?.pos ?: return@subscribe - if (waypoints[orderedIndex].isWithinDistance(p, 3.0)) { - orderedIndex = (orderedIndex + 1) % waypoints.size + if (TConfig.skipToNearest) { + orderedIndex = + (waypoints.withIndex().minBy { it.value.getSquaredDistance(p) }.index + 1) % waypoints.size + } else { + if (waypoints[orderedIndex].isWithinDistance(p, 3.0)) { + orderedIndex = (orderedIndex + 1) % waypoints.size + } } } ProcessChatEvent.subscribe { -- cgit