diff options
author | Linnea Gräf <nea@nea.moe> | 2025-03-22 20:19:34 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2025-03-22 20:19:34 +0100 |
commit | 7c2d984d330e8a4988e6916394a3e97f2f2d2a5b (patch) | |
tree | 2df327dee4547f3dbe842bef078e36a65d1f3283 | |
parent | b532572cbfe1fad2a22a9dd7586d6dd747466fa6 (diff) | |
download | Firmament-feat/betterwaypoints.tar.gz Firmament-feat/betterwaypoints.tar.bz2 Firmament-feat/betterwaypoints.zip |
feat: Allow locally saving waypoint setsHEADmasterfeat/betterwaypoints
-rw-r--r-- | src/main/kotlin/features/world/FirmWaypointManager.kt | 49 | ||||
-rw-r--r-- | src/main/kotlin/features/world/FirmWaypoints.kt | 2 |
2 files changed, 45 insertions, 6 deletions
diff --git a/src/main/kotlin/features/world/FirmWaypointManager.kt b/src/main/kotlin/features/world/FirmWaypointManager.kt index 6b68a94..d18483c 100644 --- a/src/main/kotlin/features/world/FirmWaypointManager.kt +++ b/src/main/kotlin/features/world/FirmWaypointManager.kt @@ -1,11 +1,13 @@ package moe.nea.firmament.features.world +import com.mojang.brigadier.arguments.StringArgumentType import kotlinx.serialization.serializer import net.minecraft.text.Text import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.commands.DefaultSource import moe.nea.firmament.commands.RestArgumentType import moe.nea.firmament.commands.get +import moe.nea.firmament.commands.suggestsList import moe.nea.firmament.commands.thenArgument import moe.nea.firmament.commands.thenExecute import moe.nea.firmament.commands.thenLiteral @@ -45,23 +47,24 @@ object FirmWaypointManager { } fun loadWaypoints(waypoints: FirmWaypoints, sendFeedback: (Text) -> Unit) { - if (waypoints.isRelativeTo != null) { + val copy = waypoints.deepCopy() + if (copy.isRelativeTo != null) { val origin = MC.player!!.blockPos - waypoints.waypoints.replaceAll { + copy.waypoints.replaceAll { it.copy( x = it.x + origin.x, y = it.y + origin.y, z = it.z + origin.z, ) } - waypoints.lastRelativeImport = origin.toImmutable() + copy.lastRelativeImport = origin.toImmutable() sendFeedback(tr("firmament.command.waypoint.import.ordered.success", - "Imported ${waypoints.size} relative waypoints. Make sure you stand in the correct spot while loading the waypoints: ${waypoints.isRelativeTo}.")) + "Imported ${copy.size} relative waypoints. Make sure you stand in the correct spot while loading the waypoints: ${copy.isRelativeTo}.")) } else { sendFeedback(tr("firmament.command.waypoint.import.success", - "Imported ${waypoints.size} waypoints.")) + "Imported ${copy.size} waypoints.")) } - Waypoints.waypoints = waypoints + Waypoints.waypoints = copy } fun setOrigin(source: DefaultSource, text: String?) { @@ -95,6 +98,40 @@ object FirmWaypointManager { "Unset the origin of the waypoints. Run /firm waypoints export to save the waypoints with absolute coordinates.")) } } + thenLiteral("save") { + thenArgument("name", StringArgumentType.string()) { name -> + suggestsList { DataHolder.list().keys } + thenExecute { + val waypoints = Waypoints.useNonEmptyWaypoints() + if (waypoints == null) { + source.sendError(Waypoints.textNothingToExport()) + return@thenExecute + } + waypoints.id = get(name) + val exportableWaypoints = createExportableCopy(waypoints) + DataHolder.insert(get(name), exportableWaypoints) + DataHolder.save() + source.sendFeedback(tr("firmament.command.waypoint.saved", + "Saved waypoints locally as ${get(name)}. Use /firm waypoints load to load them again.")) + } + } + } + thenLiteral("load") { + thenArgument("name", StringArgumentType.string()) { name -> + suggestsList { DataHolder.list().keys } + thenExecute { + val name = get(name) + val waypoints = DataHolder.list()[name] + if (waypoints == null) { + source.sendError( + tr("firmament.command.waypoint.nosaved", + "No saved waypoint for ${name}. Use tab completion to see available names.")) + return@thenExecute + } + loadWaypoints(waypoints, source::sendFeedback) + } + } + } thenLiteral("export") { thenExecute { val waypoints = Waypoints.useNonEmptyWaypoints() diff --git a/src/main/kotlin/features/world/FirmWaypoints.kt b/src/main/kotlin/features/world/FirmWaypoints.kt index d149501..d0cd55a 100644 --- a/src/main/kotlin/features/world/FirmWaypoints.kt +++ b/src/main/kotlin/features/world/FirmWaypoints.kt @@ -16,6 +16,8 @@ data class FirmWaypoints( var isOrdered: Boolean, // TODO: val resetOnSwap: Boolean, ) { + + fun deepCopy() = copy(waypoints = waypoints.toMutableList()) @Transient var lastRelativeImport: BlockPos? = null |