aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/features/inventory/SaveCursorPosition.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-09-14 19:46:52 +0200
committerLinnea Gräf <nea@nea.moe>2025-09-14 19:46:52 +0200
commit0a96dd618acba15269627c7eae8a2291fb2dc84a (patch)
treef31a66cbd13cefbfb2d006f07d3ef3da1010f7e7 /src/main/kotlin/features/inventory/SaveCursorPosition.kt
parent9abe9f46f04f188037687adb2740b32220ad21b2 (diff)
downloadFirmament-0a96dd618acba15269627c7eae8a2291fb2dc84a.tar.gz
Firmament-0a96dd618acba15269627c7eae8a2291fb2dc84a.tar.bz2
Firmament-0a96dd618acba15269627c7eae8a2291fb2dc84a.zip
snapshot
Diffstat (limited to 'src/main/kotlin/features/inventory/SaveCursorPosition.kt')
-rw-r--r--src/main/kotlin/features/inventory/SaveCursorPosition.kt93
1 files changed, 43 insertions, 50 deletions
diff --git a/src/main/kotlin/features/inventory/SaveCursorPosition.kt b/src/main/kotlin/features/inventory/SaveCursorPosition.kt
index 2a08730..3e55d02 100644
--- a/src/main/kotlin/features/inventory/SaveCursorPosition.kt
+++ b/src/main/kotlin/features/inventory/SaveCursorPosition.kt
@@ -1,64 +1,57 @@
-
-
package moe.nea.firmament.features.inventory
import org.lwjgl.glfw.GLFW
import kotlin.math.absoluteValue
import kotlin.time.Duration.Companion.milliseconds
-import net.minecraft.client.util.InputUtil
-import moe.nea.firmament.features.FirmamentFeature
-import moe.nea.firmament.util.data.ManagedConfig
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.TimeMark
import moe.nea.firmament.util.assertNotNullOr
import moe.nea.firmament.util.data.Config
+import moe.nea.firmament.util.data.ManagedConfig
-object SaveCursorPosition : FirmamentFeature {
- override val identifier: String
- get() = "save-cursor-position"
+object SaveCursorPosition {
+ val identifier: String
+ get() = "save-cursor-position"
@Config
- object TConfig : ManagedConfig(identifier, Category.INVENTORY) {
- val enable by toggle("enable") { true }
- val tolerance by duration("tolerance", 10.milliseconds, 5000.milliseconds) { 500.milliseconds }
- }
-
- override val config: TConfig
- get() = TConfig
-
- var savedPositionedP1: Pair<Double, Double>? = null
- var savedPosition: SavedPosition? = null
-
- data class SavedPosition(
- val middle: Pair<Double, Double>,
- val cursor: Pair<Double, Double>,
- val savedAt: TimeMark = TimeMark.now()
- )
-
- @JvmStatic
- fun saveCursorOriginal(positionedX: Double, positionedY: Double) {
- savedPositionedP1 = Pair(positionedX, positionedY)
- }
-
- @JvmStatic
- fun loadCursor(middleX: Double, middleY: Double): Pair<Double, Double>? {
- if (!TConfig.enable) return null
- val lastPosition = savedPosition?.takeIf { it.savedAt.passedTime() < TConfig.tolerance }
- savedPosition = null
- if (lastPosition != null &&
- (lastPosition.middle.first - middleX).absoluteValue < 1 &&
- (lastPosition.middle.second - middleY).absoluteValue < 1
- ) {
+ object TConfig : ManagedConfig(identifier, Category.INVENTORY) {
+ val enable by toggle("enable") { true }
+ val tolerance by duration("tolerance", 10.milliseconds, 5000.milliseconds) { 500.milliseconds }
+ }
+
+ var savedPositionedP1: Pair<Double, Double>? = null
+ var savedPosition: SavedPosition? = null
+
+ data class SavedPosition(
+ val middle: Pair<Double, Double>,
+ val cursor: Pair<Double, Double>,
+ val savedAt: TimeMark = TimeMark.now()
+ )
+
+ @JvmStatic
+ fun saveCursorOriginal(positionedX: Double, positionedY: Double) {
+ savedPositionedP1 = Pair(positionedX, positionedY)
+ }
+
+ @JvmStatic
+ fun loadCursor(middleX: Double, middleY: Double): Pair<Double, Double>? {
+ if (!TConfig.enable) return null
+ val lastPosition = savedPosition?.takeIf { it.savedAt.passedTime() < TConfig.tolerance }
+ savedPosition = null
+ if (lastPosition != null &&
+ (lastPosition.middle.first - middleX).absoluteValue < 1 &&
+ (lastPosition.middle.second - middleY).absoluteValue < 1
+ ) {
GLFW.glfwSetCursorPos(MC.window.handle, lastPosition.cursor.first, lastPosition.cursor.second);
- return lastPosition.cursor
- }
- return null
- }
-
- @JvmStatic
- fun saveCursorMiddle(middleX: Double, middleY: Double) {
- if (!TConfig.enable) return
- val cursorPos = assertNotNullOr(savedPositionedP1) { return }
- savedPosition = SavedPosition(Pair(middleX, middleY), cursorPos)
- }
+ return lastPosition.cursor
+ }
+ return null
+ }
+
+ @JvmStatic
+ fun saveCursorMiddle(middleX: Double, middleY: Double) {
+ if (!TConfig.enable) return
+ val cursorPos = assertNotNullOr(savedPositionedP1) { return }
+ savedPosition = SavedPosition(Pair(middleX, middleY), cursorPos)
+ }
}