aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/keybindings/IKeyBinding.kt
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-05-29 23:28:52 +0200
committernea <nea@nea.moe>2023-05-29 23:28:52 +0200
commitdd0afac3a8459035827dac36986a690c8a9541ea (patch)
tree2bc3ab50b69590a6811a8265f4c533163d07457c /src/main/kotlin/moe/nea/firmament/keybindings/IKeyBinding.kt
parentc133505e3b1f8e5aeb62c1a0e99513ec4bfcf239 (diff)
downloadFirmament-dd0afac3a8459035827dac36986a690c8a9541ea.tar.gz
Firmament-dd0afac3a8459035827dac36986a690c8a9541ea.tar.bz2
Firmament-dd0afac3a8459035827dac36986a690c8a9541ea.zip
Add price checker
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/keybindings/IKeyBinding.kt')
-rw-r--r--src/main/kotlin/moe/nea/firmament/keybindings/IKeyBinding.kt27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/keybindings/IKeyBinding.kt b/src/main/kotlin/moe/nea/firmament/keybindings/IKeyBinding.kt
new file mode 100644
index 0000000..7cb2720
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/keybindings/IKeyBinding.kt
@@ -0,0 +1,27 @@
+package moe.nea.firmament.keybindings
+
+import net.minecraft.client.option.KeyBinding
+
+interface IKeyBinding {
+ fun matches(keyCode: Int, scanCode: Int, modifiers: Int): Boolean
+
+ fun withModifiers(wantedModifiers: Int): IKeyBinding {
+ val old = this
+ return object : IKeyBinding {
+ override fun matches(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
+ return old.matches(keyCode, scanCode, modifiers) && (modifiers and wantedModifiers) == wantedModifiers
+ }
+ }
+ }
+
+ companion object {
+ fun minecraft(keyBinding: KeyBinding) = object : IKeyBinding {
+ override fun matches(keyCode: Int, scanCode: Int, modifiers: Int) =
+ keyBinding.matchesKey(keyCode, scanCode)
+ }
+
+ fun ofKeyCode(wantedKeyCode: Int) = object : IKeyBinding {
+ override fun matches(keyCode: Int, scanCode: Int, modifiers: Int): Boolean = keyCode == wantedKeyCode
+ }
+ }
+}