aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
authorNetheriteMiner <88792142+NetheriteMiner@users.noreply.github.com>2023-08-02 07:52:04 -0400
committerGitHub <noreply@github.com>2023-08-02 13:52:04 +0200
commitf7664fb62342e6b08462da634b19a2b05100c040 (patch)
tree44d1e9d2196f5b803a5880a6f6f229d1ca016f86 /src/main/java/at/hannibal2/skyhanni
parent6ad284e2ea1e0692769cd6a8461cdff285a7b111 (diff)
downloadskyhanni-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')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt1
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/HarpKeybinds.kt49
3 files changed, 55 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index 97ea42e45..3106933b4 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -367,6 +367,7 @@ class SkyHanniMod {
loadModule(RiftHorsezookaHider())
loadModule(GriffinPetWarning())
loadModule(KingTalismanHelper())
+ loadModule(HarpKeybinds())
//
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java
index 83fb12977..14d5624ff 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java
@@ -681,6 +681,11 @@ public class MiscConfig {
public boolean patcherSendCoordWaypoint = false;
@Expose
+ @ConfigOption(name = "Harp Keybinds", desc = "Press harp buttons with your number row on the keyboard instead of clicking.")
+ @ConfigEditorBoolean
+ public boolean harpKeybinds = false;
+
+ @Expose
@ConfigOption(name = "Config Button", desc = "Add a button to the pause menu to configure SkyHanni.")
@ConfigEditorBoolean
public boolean configButtonOnPause = true;
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