aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/features
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2023-11-12 14:45:05 +0100
committerLinnea Gräf <nea@nea.moe>2023-11-12 14:45:05 +0100
commit2c9c38868345d5e133179597936f8e584075b8de (patch)
treea055cd6224d71058821558db33296a4900068216 /src/main/kotlin/moe/nea/firmament/features
parent897ab0f06b06e4c14eab31a1bf45365671471c8c (diff)
downloadFirmament-2c9c38868345d5e133179597936f8e584075b8de.tar.gz
Firmament-2c9c38868345d5e133179597936f8e584075b8de.tar.bz2
Firmament-2c9c38868345d5e133179597936f8e584075b8de.zip
Add temporary waypoints and /firm sendcoords
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/features')
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt2
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/world/Waypoints.kt72
2 files changed, 74 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt
index 4888f54..30036b7 100644
--- a/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt
@@ -27,6 +27,7 @@ import moe.nea.firmament.features.inventory.buttons.InventoryButtons
import moe.nea.firmament.features.inventory.storageoverlay.StorageOverlay
import moe.nea.firmament.features.texturepack.CustomSkyBlockTextures
import moe.nea.firmament.features.world.FairySouls
+import moe.nea.firmament.features.world.Waypoints
import moe.nea.firmament.util.data.DataHolder
object FeatureManager : DataHolder<FeatureManager.Config>(serializer(), "features", ::Config) {
@@ -56,6 +57,7 @@ object FeatureManager : DataHolder<FeatureManager.Config>(serializer(), "feature
loadFeature(StorageOverlay)
loadFeature(CraftingOverlay)
loadFeature(PowerUserTools)
+ loadFeature(Waypoints)
loadFeature(ChatLinks)
loadFeature(InventoryButtons)
loadFeature(CompatibliltyFeatures)
diff --git a/src/main/kotlin/moe/nea/firmament/features/world/Waypoints.kt b/src/main/kotlin/moe/nea/firmament/features/world/Waypoints.kt
new file mode 100644
index 0000000..de25a37
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/features/world/Waypoints.kt
@@ -0,0 +1,72 @@
+/*
+ * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+package moe.nea.firmament.features.world
+
+import kotlin.time.Duration.Companion.hours
+import kotlin.time.Duration.Companion.seconds
+import net.minecraft.text.Text
+import net.minecraft.util.math.BlockPos
+import moe.nea.firmament.events.ProcessChatEvent
+import moe.nea.firmament.events.WorldReadyEvent
+import moe.nea.firmament.events.WorldRenderLastEvent
+import moe.nea.firmament.features.FirmamentFeature
+import moe.nea.firmament.gui.config.ManagedConfig
+import moe.nea.firmament.util.TimeMark
+import moe.nea.firmament.util.render.RenderInWorldContext
+
+object Waypoints : FirmamentFeature {
+ override val identifier: String
+ get() = "waypoints"
+
+ object TConfig : ManagedConfig(identifier) {
+ val tempWaypointDuration by duration("temp-waypoint-duration", 0.seconds, 1.hours) { 30.seconds }
+ }
+
+ data class TemporaryWaypoint(
+ val pos: BlockPos,
+ val postedAt: TimeMark,
+ )
+
+ override val config get() = TConfig
+
+ val temporaryWaypointList = mutableMapOf<String, TemporaryWaypoint>()
+ val temporaryWaypointMatcher = "x: (-?[0-9]+),? y: (-?[0-9]+),? z: (-?[0-9]+)".toPattern()
+ override fun onLoad() {
+ WorldRenderLastEvent.subscribe {
+ temporaryWaypointList.entries.removeIf { it.value.postedAt.passedTime() > TConfig.tempWaypointDuration }
+ if (temporaryWaypointList.isNotEmpty())
+ RenderInWorldContext.renderInWorld(it) {
+ color(1f, 1f, 0f, 1f)
+ temporaryWaypointList.forEach { (player, waypoint) ->
+ block(waypoint.pos)
+ }
+ color(1f, 1f, 1f, 1f)
+ temporaryWaypointList.forEach { (player, waypoint) ->
+ waypoint(waypoint.pos, Text.translatable("firmament.waypoint.temporary", player))
+ }
+ }
+ }
+ WorldReadyEvent.subscribe {
+ temporaryWaypointList.clear()
+ }
+ ProcessChatEvent.subscribe {
+ val matcher = temporaryWaypointMatcher.matcher(it.unformattedString)
+ if (it.nameHeuristic != null && TConfig.tempWaypointDuration > 0.seconds && matcher.find()) {
+ temporaryWaypointList.put(
+ it.nameHeuristic, TemporaryWaypoint(
+ BlockPos(
+ matcher.group(1).toInt(),
+ matcher.group(2).toInt(),
+ matcher.group(3).toInt(),
+ ),
+ TimeMark.now()
+ )
+ )
+ }
+ }
+ }
+}