From f7664fb62342e6b08462da634b19a2b05100c040 Mon Sep 17 00:00:00 2001 From: NetheriteMiner <88792142+NetheriteMiner@users.noreply.github.com> Date: Wed, 2 Aug 2023 07:52:04 -0400 Subject: Merge pull request #340 * Add Harp Keyboard --- .../skyhanni/features/misc/HarpKeybinds.kt | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/HarpKeybinds.kt (limited to 'src/main/java/at/hannibal2/skyhanni/features/misc') diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/HarpKeybinds.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/HarpKeybinds.kt new file mode 100644 index 000000000..08bb4cfee --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/HarpKeybinds.kt @@ -0,0 +1,49 @@ +package at.hannibal2.skyhanni.features.misc + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.utils.InventoryUtils.openInventoryName +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.inventory.GuiChest +import net.minecraftforge.client.event.GuiScreenEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import org.lwjgl.input.Keyboard +import kotlin.time.Duration.Companion.milliseconds + +// Delaying key presses by 300ms comes from NotEnoughUpdates +class HarpKeybinds { + private var lastClick = SimpleTimeMark.farPast() + + private val keys = listOf( + Keyboard.KEY_1, + Keyboard.KEY_2, + Keyboard.KEY_3, + Keyboard.KEY_4, + Keyboard.KEY_5, + Keyboard.KEY_6, + Keyboard.KEY_7 + ) + + @SubscribeEvent + fun onGui(event: GuiScreenEvent) { + if (!SkyHanniMod.feature.misc.harpKeybinds) return + if (!openInventoryName().startsWith("Harp")) return + val chest = event.gui as? GuiChest ?: return + + for (key in keys) { + if (Keyboard.isKeyDown(key)) { + if (lastClick.passedSince() > 200.milliseconds) { + Minecraft.getMinecraft().playerController.windowClick( + chest.inventorySlots.windowId, + 35 + key, + 2, + 3, + Minecraft.getMinecraft().thePlayer + ) // middle clicks > left clicks + lastClick = SimpleTimeMark.now() + } + break + } + } + } +} \ No newline at end of file -- cgit