From f4f5e3713d1f084cf26aa8abf3df4d3647f7b0ef Mon Sep 17 00:00:00 2001 From: NetheriteMiner <88792142+NetheriteMiner@users.noreply.github.com> Date: Thu, 10 Aug 2023 12:10:57 -0400 Subject: Merge pull request #372 * Add Harp Numbers --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 2 +- .../skyhanni/config/features/MiscConfig.java | 7 ++- .../skyhanni/features/misc/HarpFeatures.kt | 69 ++++++++++++++++++++++ .../skyhanni/features/misc/HarpKeybinds.kt | 51 ---------------- 4 files changed, 76 insertions(+), 53 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/HarpFeatures.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/HarpKeybinds.kt (limited to 'src') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 6ef789465..946f41282 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -374,7 +374,7 @@ class SkyHanniMod { loadModule(GriffinPetWarning()) loadModule(BestiaryData) loadModule(KingTalismanHelper()) - loadModule(HarpKeybinds()) + loadModule(HarpFeatures()) loadModule(EnderNodeTracker()) loadModule(CompactBestiaryChatMessage()) loadModule(WatchdogHider()) 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 a97fe1afe..353d99b59 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java @@ -799,10 +799,15 @@ public class MiscConfig { public boolean patcherSendCoordWaypoint = false; @Expose - @ConfigOption(name = "Harp Keybinds", desc = "In Melodys Harp, press buttons with your number row on the keyboard instead of clicking.") + @ConfigOption(name = "Harp Keybinds", desc = "In Melody's Harp, press buttons with your number row on the keyboard instead of clicking.") @ConfigEditorBoolean public boolean harpKeybinds = false; + @Expose + @ConfigOption(name = "Harp Numbers", desc = "In Melody's Harp, show buttons as stack size (intended to be used with Harp Keybinds).") + @ConfigEditorBoolean + public boolean harpNumbers = false; + @Expose @ConfigOption(name = "Config Button", desc = "Add a button to the pause menu to configure SkyHanni.") @ConfigEditorBoolean diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/HarpFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/HarpFeatures.kt new file mode 100644 index 000000000..749fb8a64 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/HarpFeatures.kt @@ -0,0 +1,69 @@ +package at.hannibal2.skyhanni.features.misc + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.RenderItemTipEvent +import at.hannibal2.skyhanni.utils.InventoryUtils.openInventoryName +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.inventory.GuiChest +import net.minecraft.item.Item +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 HarpFeatures { + 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 + ) + + private val buttonColors = listOf('d', 'e', 'a', '2', '5', '9', 'b') + + @SubscribeEvent + fun onGui(event: GuiScreenEvent) { + if (!LorenzUtils.inSkyBlock) return + 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 + } + } + } + + @SubscribeEvent + fun onRenderItemTip(event: RenderItemTipEvent) { + if (!LorenzUtils.inSkyBlock) return + if (!SkyHanniMod.feature.misc.harpNumbers) return + if (!openInventoryName().startsWith("Harp")) return + if (Item.getIdFromItem(event.stack.item) != 159) return // Stained hardened clay item id = 159 + + val index = + buttonColors.indexOfFirst { it == event.stack.displayName[1] } // Example: §9| §7Click! will select the 9 + if (index == -1) return // this should never happen unless there's an update + + event.stackTip = (index + 1).toString() + } +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/HarpKeybinds.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/HarpKeybinds.kt deleted file mode 100644 index 5ca0e6239..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/HarpKeybinds.kt +++ /dev/null @@ -1,51 +0,0 @@ -package at.hannibal2.skyhanni.features.misc - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.utils.InventoryUtils.openInventoryName -import at.hannibal2.skyhanni.utils.LorenzUtils -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 (!LorenzUtils.inSkyBlock) return - 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