From dd0afac3a8459035827dac36986a690c8a9541ea Mon Sep 17 00:00:00 2001 From: nea Date: Mon, 29 May 2023 23:28:52 +0200 Subject: Add price checker --- .../moe/nea/firmament/keybindings/IKeyBinding.kt | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/kotlin/moe/nea/firmament/keybindings/IKeyBinding.kt (limited to 'src/main/kotlin/moe/nea/firmament/keybindings') 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 + } + } +} -- cgit