diff options
author | Linnea Gräf <nea@nea.moe> | 2025-03-22 18:56:19 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2025-03-22 18:56:19 +0100 |
commit | ba3f2785b0faf7cb044374e0c49df307ee101e35 (patch) | |
tree | 465db3365f868f9516a0ac7d39cc28bb2b1b392b | |
parent | 40ac97026918f89a6bef77ce660efe0df6e4e6ef (diff) | |
download | Firmament-ba3f2785b0faf7cb044374e0c49df307ee101e35.tar.gz Firmament-ba3f2785b0faf7cb044374e0c49df307ee101e35.tar.bz2 Firmament-ba3f2785b0faf7cb044374e0c49df307ee101e35.zip |
feat: Allow changing the order of ordered waypoints
-rw-r--r-- | src/main/kotlin/features/world/Waypoints.kt | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/main/kotlin/features/world/Waypoints.kt b/src/main/kotlin/features/world/Waypoints.kt index 342f355..e86223e 100644 --- a/src/main/kotlin/features/world/Waypoints.kt +++ b/src/main/kotlin/features/world/Waypoints.kt @@ -6,7 +6,6 @@ import kotlin.time.Duration.Companion.hours import kotlin.time.Duration.Companion.seconds import net.minecraft.command.argument.BlockPosArgumentType import net.minecraft.text.Text -import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.commands.get @@ -18,7 +17,6 @@ import moe.nea.firmament.events.TickEvent import moe.nea.firmament.events.WorldRenderLastEvent import moe.nea.firmament.features.FirmamentFeature import moe.nea.firmament.gui.config.ManagedConfig -import moe.nea.firmament.util.ClipboardUtils import moe.nea.firmament.util.MC import moe.nea.firmament.util.mc.asFakeServer import moe.nea.firmament.util.render.RenderInWorldContext @@ -123,6 +121,34 @@ object Waypoints : FirmamentFeature { } } event.subcommand(WAYPOINTS_SUBCOMMAND) { + thenLiteral("changeindex") { + thenArgument("from", IntegerArgumentType.integer(0)) { fromIndex -> + thenArgument("to", IntegerArgumentType.integer(0)) { toIndex -> + thenExecute { + val w = useEditableWaypoints() + val toIndex = toIndex.get(this) + val fromIndex = fromIndex.get(this) + if (fromIndex !in w.waypoints.indices) { + source.sendError(textInvalidIndex(fromIndex)) + return@thenExecute + } + if (toIndex !in w.waypoints.indices) { + source.sendError(textInvalidIndex(toIndex)) + return@thenExecute + } + val waypoint = w.waypoints.removeAt(fromIndex) + w.waypoints.add( + if (toIndex > fromIndex) toIndex - 1 + else toIndex, + waypoint) + source.sendFeedback( + tr("firmament.command.waypoint.indexchange", + "Moved waypoint from index $fromIndex to $toIndex. Note that this only matters for ordered waypoints.") + ) + } + } + } + } thenLiteral("clear") { thenExecute { waypoints = null @@ -170,6 +196,10 @@ object Waypoints : FirmamentFeature { } } + fun textInvalidIndex(index: Int) = + tr("firmament.command.waypoint.invalid-index", + "Invalid index $index provided.") + fun textNothingToExport(): Text = tr("firmament.command.waypoint.export.nowaypoints", "No waypoints to export found. Add some with /firm waypoint ~ ~ ~.") |