diff options
author | nea <nea@nea.moe> | 2023-08-31 19:38:38 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-08-31 21:22:26 +0200 |
commit | cb032e7c221e40736ab26b193eea4e32d06113d9 (patch) | |
tree | e49047b3b78fb9887d72cbe9458af44ecbc179d4 /src/main/kotlin/moe/nea/firmament/keybindings | |
parent | b7b01f1c6fbf889ae9bfcdb5b34c5ccfa48d5ba0 (diff) | |
download | Firmament-cb032e7c221e40736ab26b193eea4e32d06113d9.tar.gz Firmament-cb032e7c221e40736ab26b193eea4e32d06113d9.tar.bz2 Firmament-cb032e7c221e40736ab26b193eea4e32d06113d9.zip |
Add price tooltips
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/keybindings')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt b/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt index e0f0c50..606485b 100644 --- a/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt +++ b/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt @@ -6,8 +6,11 @@ package moe.nea.firmament.keybindings -import kotlinx.serialization.Serializable import org.lwjgl.glfw.GLFW +import kotlinx.serialization.Serializable +import net.minecraft.client.MinecraftClient +import net.minecraft.client.util.InputUtil +import moe.nea.firmament.util.MC @Serializable data class SavedKeyBinding( @@ -35,6 +38,43 @@ data class SavedKeyBinding( } } + fun hasShiftDown(): Boolean { + return InputUtil.isKeyPressed( + MinecraftClient.getInstance().window.handle, + GLFW.GLFW_KEY_LEFT_SHIFT + ) || InputUtil.isKeyPressed( + MinecraftClient.getInstance().window.handle, GLFW.GLFW_KEY_RIGHT_SHIFT + ) + } + + fun hasAltDown(): Boolean { + return InputUtil.isKeyPressed( + MinecraftClient.getInstance().window.handle, + GLFW.GLFW_KEY_LEFT_ALT + ) || InputUtil.isKeyPressed( + MinecraftClient.getInstance().window.handle, GLFW.GLFW_KEY_RIGHT_ALT + ) + } + + fun isPressed(): Boolean { + val h = MC.window.handle + if (!InputUtil.isKeyPressed(h, keyCode)) return false + + val ctrl = if (MinecraftClient.IS_SYSTEM_MAC) { + InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_SUPER) + || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_SUPER) + } else InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_CONTROL) + || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_CONTROL) + val shift = InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_SHIFT) + || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_SHIFT) + val alt = InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_ALT) + || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_ALT) + + return (ctrl == this.ctrl) && + (alt == this.alt) && + (shift == this.shift) + } + override fun matches(keyCode: Int, scanCode: Int, modifiers: Int): Boolean { return keyCode == this.keyCode && getMods(modifiers) == Triple(shift, ctrl, alt) } |