diff options
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java | 6 | ||||
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/inventory/SnakeGame.kt | 74 |
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 +} |
