aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ10a1n15 <45315647+j10a1n15@users.noreply.github.com>2024-10-20 23:41:36 +0200
committerGitHub <noreply@github.com>2024-10-20 23:41:36 +0200
commit8bee426a943409fcd90182791d46ca807c23264a (patch)
tree282a770fc803977bd0f807bac2b3ec8e1efe9c8b
parent8076557ac5448d132c825e680813634c6fd866b0 (diff)
downloadSkyHanni-8bee426a943409fcd90182791d46ca807c23264a.tar.gz
SkyHanni-8bee426a943409fcd90182791d46ca807c23264a.tar.bz2
SkyHanni-8bee426a943409fcd90182791d46ca807c23264a.zip
Feature: Snake Game Keybinds (#1968)
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/SnakeGame.kt74
2 files changed, 80 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java
index 71ab7c792..c0a51a979 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java
@@ -305,6 +305,12 @@ public class InventoryConfig {
public boolean hexAsColorInLore = true;
@Expose
+ @ConfigOption(name = "Snake Game Keybinds", desc = "Use WASD-Keys to move around in the Abiphone snake game.")
+ @ConfigEditorBoolean
+ @FeatureToggle
+ public boolean snakeGameKeybinds = true;
+
+ @Expose
@ConfigOption(name = "Highlight Active Beacon Effect", desc = "Highlights the currently selected beacon effect in the beacon inventory.")
@ConfigEditorBoolean
@FeatureToggle
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/SnakeGame.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/SnakeGame.kt
new file mode 100644
index 000000000..0b71e0042
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/SnakeGame.kt
@@ -0,0 +1,74 @@
+package at.hannibal2.skyhanni.features.inventory
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.events.GuiKeyPressEvent
+import at.hannibal2.skyhanni.events.InventoryCloseEvent
+import at.hannibal2.skyhanni.events.InventoryOpenEvent
+import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
+import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.RegexUtils.matches
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
+import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
+import net.minecraft.client.Minecraft
+import net.minecraft.client.gui.inventory.GuiChest
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration.Companion.milliseconds
+
+@SkyHanniModule
+object SnakeGame {
+
+ private val pattern by RepoPattern.pattern("abiphone.snake.name", "Snake")
+ private val config get() = SkyHanniMod.feature.inventory
+ private var lastClick = SimpleTimeMark.farPast()
+
+ private var inInventory = false
+
+ private val keys
+ get() = with(Minecraft.getMinecraft().gameSettings) {
+ mapOf(
+ keyBindLeft?.keyCode to 50,
+ keyBindForward?.keyCode to 51,
+ keyBindRight?.keyCode to 52,
+ keyBindBack?.keyCode to 53,
+ )
+ }
+
+ @SubscribeEvent
+ fun onGui(event: GuiKeyPressEvent) {
+ if (!isEnabled()) return
+ if (!inInventory) return
+
+ val chest = event.guiContainer as? GuiChest ?: return
+
+ if (lastClick.passedSince() < 100.milliseconds) return
+
+ for ((key, slot) in keys) {
+ if (key?.isKeyHeld() == false) continue
+ event.cancel()
+
+ Minecraft.getMinecraft().playerController.windowClick(
+ chest.inventorySlots.windowId,
+ slot,
+ 2,
+ 3,
+ Minecraft.getMinecraft().thePlayer,
+ )
+
+ lastClick = SimpleTimeMark.now()
+ break
+ }
+ }
+
+ @SubscribeEvent
+ fun onInventoryOpen(event: InventoryOpenEvent) {
+ inInventory = pattern.matches(event.inventoryName)
+ }
+
+ @SubscribeEvent
+ fun onInventoryClose(event: InventoryCloseEvent) {
+ inInventory = false
+ }
+
+ private fun isEnabled() = LorenzUtils.inSkyBlock && config.snakeGameKeybinds
+}