diff options
author | NetheriteMiner <88792142+NetheriteMiner@users.noreply.github.com> | 2023-08-02 07:52:04 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-02 13:52:04 +0200 |
commit | f7664fb62342e6b08462da634b19a2b05100c040 (patch) | |
tree | 44d1e9d2196f5b803a5880a6f6f229d1ca016f86 /src/main/java/at/hannibal2/skyhanni/features/misc | |
parent | 6ad284e2ea1e0692769cd6a8461cdff285a7b111 (diff) | |
download | skyhanni-f7664fb62342e6b08462da634b19a2b05100c040.tar.gz skyhanni-f7664fb62342e6b08462da634b19a2b05100c040.tar.bz2 skyhanni-f7664fb62342e6b08462da634b19a2b05100c040.zip |
Merge pull request #340
* Add Harp Keyboard
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/misc')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/HarpKeybinds.kt | 49 |
1 files changed, 49 insertions, 0 deletions
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 |