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 --- .../skyhanni/features/misc/HarpFeatures.kt | 69 ++++++++++++++++++++++ .../skyhanni/features/misc/HarpKeybinds.kt | 51 ---------------- 2 files changed, 69 insertions(+), 51 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/main/java/at/hannibal2/skyhanni/features/misc') 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