diff options
author | nea <nea@nea.moe> | 2023-05-29 23:28:52 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-05-29 23:28:52 +0200 |
commit | dd0afac3a8459035827dac36986a690c8a9541ea (patch) | |
tree | 2bc3ab50b69590a6811a8265f4c533163d07457c /src/main/kotlin/moe/nea/firmament/keybindings | |
parent | c133505e3b1f8e5aeb62c1a0e99513ec4bfcf239 (diff) | |
download | Firmament-dd0afac3a8459035827dac36986a690c8a9541ea.tar.gz Firmament-dd0afac3a8459035827dac36986a690c8a9541ea.tar.bz2 Firmament-dd0afac3a8459035827dac36986a690c8a9541ea.zip |
Add price checker
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/keybindings')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/keybindings/IKeyBinding.kt | 27 |
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 + } + } +} |