From bf5bcbf09faf75ab7c5a797a2426275677562cf2 Mon Sep 17 00:00:00 2001 From: Thunderblade73 Date: Thu, 30 Nov 2023 17:07:59 +0100 Subject: [PATCH 01/10] Backend: DelayedRun sync --- .../at/hannibal2/skyhanni/utils/DelayedRun.kt | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt b/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt index f90237588b7b..0b9353e0db22 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt @@ -1,34 +1,24 @@ package at.hannibal2.skyhanni.utils -import at.hannibal2.skyhanni.utils.LorenzUtils.editCopy +import java.util.concurrent.LinkedBlockingQueue import kotlin.time.Duration -// TODO find better sync bug fix than creating a new map for each use object DelayedRun { - var map = mapOf<() -> Any, SimpleTimeMark>() + val map = mutableListOf Any, SimpleTimeMark>>() + private val inMap = LinkedBlockingQueue Any, SimpleTimeMark>>() fun runDelayed(duration: Duration, run: () -> Unit) { - map = map.editCopy { - this[run] = SimpleTimeMark.now() + duration - } + inMap.put(Pair(run, SimpleTimeMark.now() + duration)) } fun runNextTick(run: () -> Unit) { - map = map.editCopy { - this[run] = SimpleTimeMark.now() - } + inMap.put(Pair(run, SimpleTimeMark.farPast())) } fun checkRuns() { - if (map.isEmpty()) return - map = map.editCopy { - entries.removeIf { (runnable, time) -> - val inPast = time.isInPast() - if (inPast) { - runnable() - } - inPast - } + inMap.drainTo(map) + map.removeIf { (runnable, time) -> + time.isInPast().also { if (it) runnable() } } } } From be98283e102215c5a3efcb57fbbb92586a415dfa Mon Sep 17 00:00:00 2001 From: Thunderblade73 Date: Thu, 30 Nov 2023 23:45:28 +0100 Subject: [PATCH 02/10] Implemented suggestion from nea --- .../at/hannibal2/skyhanni/utils/DelayedRun.kt | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt b/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt index 0b9353e0db22..d87007090fc9 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt @@ -1,24 +1,29 @@ package at.hannibal2.skyhanni.utils -import java.util.concurrent.LinkedBlockingQueue +import java.util.concurrent.ConcurrentLinkedQueue import kotlin.time.Duration object DelayedRun { - val map = mutableListOf Any, SimpleTimeMark>>() - private val inMap = LinkedBlockingQueue Any, SimpleTimeMark>>() + private val tasks = mutableListOf Any, SimpleTimeMark>>() + private val futureTasks = ConcurrentLinkedQueue Any, SimpleTimeMark>>() fun runDelayed(duration: Duration, run: () -> Unit) { - inMap.put(Pair(run, SimpleTimeMark.now() + duration)) + futureTasks.add(Pair(run, SimpleTimeMark.now() + duration)) } fun runNextTick(run: () -> Unit) { - inMap.put(Pair(run, SimpleTimeMark.farPast())) + futureTasks.add(Pair(run, SimpleTimeMark.farPast())) } fun checkRuns() { - inMap.drainTo(map) - map.removeIf { (runnable, time) -> - time.isInPast().also { if (it) runnable() } + tasks.removeIf { (runnable, time) -> + val inPast = time.isInPast() + if (inPast) { + runnable() + } + inPast } + while (true) + tasks.add(futureTasks.poll() ?: break) } } From 2baba8a5792d6b6b45807e9ac3ba85836b551da4 Mon Sep 17 00:00:00 2001 From: Thunderblade73 Date: Fri, 8 Dec 2023 16:45:33 +0100 Subject: [PATCH 03/10] added drainTo method --- .../java/at/hannibal2/skyhanni/utils/DelayedRun.kt | 4 ++-- .../java/at/hannibal2/skyhanni/utils/LorenzUtils.kt | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt b/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt index d87007090fc9..d8b6bcc3e5ee 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.utils +import at.hannibal2.skyhanni.utils.LorenzUtils.drainTo import java.util.concurrent.ConcurrentLinkedQueue import kotlin.time.Duration @@ -23,7 +24,6 @@ object DelayedRun { } inPast } - while (true) - tasks.add(futureTasks.poll() ?: break) + futureTasks.drainTo(tasks) } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 8ed5de686be1..c85b45fec375 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -34,6 +34,7 @@ import java.text.SimpleDateFormat import java.util.Collections import java.util.Timer import java.util.TimerTask +import java.util.concurrent.ConcurrentLinkedQueue import kotlin.properties.ReadWriteProperty import kotlin.reflect.KMutableProperty1 import kotlin.reflect.KProperty @@ -329,7 +330,7 @@ object LorenzUtils { hover: List, command: String? = null, prefix: Boolean = true, - prefixColor: String = "§e" + prefixColor: String = "§e", ) { val msgPrefix = if (prefix) prefixColor + CHAT_PREFIX else "" val text = ChatComponentText(msgPrefix + message) @@ -419,7 +420,7 @@ object LorenzUtils { prefix: String, getName: (T) -> String, isCurrent: (T) -> Boolean, - crossinline onChange: (T) -> Unit + crossinline onChange: (T) -> Unit, ) = buildList { add(prefix) for (entry in enumValues()) { @@ -490,7 +491,7 @@ object LorenzUtils { } } - fun List.nextAfter(after: String, skip: Int = 1) = nextAfter({ it == after}, skip) + fun List.nextAfter(after: String, skip: Int = 1) = nextAfter({ it == after }, skip) fun List.nextAfter(after: (String) -> Boolean, skip: Int = 1): String? { var missing = -1 @@ -628,4 +629,9 @@ object LorenzUtils { ?: kotlin.error("Unknown enum constant for ${enumValues().first().name.javaClass.simpleName}: '$name'") fun isInDevEnviromen() = Launch.blackboard.get("fml.deobfuscatedEnvironment") as Boolean + + fun ConcurrentLinkedQueue.drainTo(list: MutableCollection) { + while (true) + list.add(this.poll() ?: break) + } } From 21b3c5e10f9a1d4cc5fb8813df0c9f3fff2490d6 Mon Sep 17 00:00:00 2001 From: Thunderblade73 Date: Wed, 29 Nov 2023 23:56:55 +0100 Subject: [PATCH 04/10] Added Harp AutoScale and Quick Restart --- .../inventory/helper/HelperConfig.java | 10 ++ .../features/inventory/HarpFeatures.kt | 106 ++++++++++++++++-- 2 files changed, 104 insertions(+), 12 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java index 02c06f39a18e..022590cd66ec 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java @@ -13,6 +13,16 @@ public class HelperConfig { public HarpConfig harp = new HarpConfig(); public static class HarpConfig { + @Expose + @ConfigOption(name = "GUI Scale", desc = "Automatically sets the GUI scale to \"AUTO\" when entering the Harp") + @ConfigEditorBoolean + @FeatureToggle + public boolean guiScale = false; + @Expose + @ConfigOption(name = "Quick Restart", desc = "When pressing the close Button in the Harp Menu shortly after opening the Harp the selected song will be started") + @ConfigEditorBoolean + @FeatureToggle + public boolean quickRestart = false; @Expose @ConfigOption(name = "Use Keybinds", desc = "In the Harp, press buttons with your number row on the keyboard instead of clicking.") @ConfigEditorBoolean diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt index 8f0c6be6aaad..35311eb20a8a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt @@ -8,8 +8,6 @@ import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.SimpleTimeMark -import at.hannibal2.skyhanni.utils.StringUtils.matches -import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.item.Item @@ -37,6 +35,19 @@ object HarpFeatures { private fun isHarpGui() = inventoryTitleRegex.matches(openInventoryName()) + fun getKey(index: Int) = when (index) { + 0 -> config.harpKeybinds.key1 + 1 -> config.harpKeybinds.key2 + 2 -> config.harpKeybinds.key3 + 3 -> config.harpKeybinds.key4 + 4 -> config.harpKeybinds.key5 + 5 -> config.harpKeybinds.key6 + 6 -> config.harpKeybinds.key7 + + else -> null + } + + @SubscribeEvent fun onGui(event: GuiScreenEvent) { if (!LorenzUtils.inSkyBlock) return @@ -60,18 +71,89 @@ object HarpFeatures { } } - fun getKey(index: Int) = when (index) { - 0 -> config.harpKeybinds.key1 - 1 -> config.harpKeybinds.key2 - 2 -> config.harpKeybinds.key3 - 3 -> config.harpKeybinds.key4 - 4 -> config.harpKeybinds.key5 - 5 -> config.harpKeybinds.key6 - 6 -> config.harpKeybinds.key7 + private var openTime: SimpleTimeMark = SimpleTimeMark.farPast() - else -> null + @SubscribeEvent + fun onInventoryFullyOpenedEvent(event: InventoryFullyOpenedEvent) { + if (!LorenzUtils.inSkyBlock) return + if (!config.guiScale) return + when { + event.inventoryName.startsWith("Melody") -> { + setGUI() + openTime = SimpleTimeMark.now() + } + + event.inventoryName.startsWith("Harp") -> { + setGUI() + } + } + } + + fun updateScale() { + if (Minecraft.getMinecraft().currentScreen == null) { + DelayedRun.runDelayed(100.milliseconds) { + updateScale() + } + return + } + // Copied from Minecraft Code to update the scale + val minecraft = Minecraft.getMinecraft() + val scaledresolution = ScaledResolution(minecraft) + val i = scaledresolution.scaledWidth + val j = scaledresolution.scaledHeight + minecraft.currentScreen.setWorldAndResolution(minecraft, i, j) + } + + @SubscribeEvent + fun onInventoryCloseEvent(event: InventoryCloseEvent) { + if (!LorenzUtils.inSkyBlock) return + if (!config.guiScale) return + unSetGUI() + } + + @SubscribeEvent + fun onLeave(event: FMLNetworkEvent.ClientDisconnectionFromServerEvent) { + if (!config.guiScale) return + unSetGUI() + } + + private var guiSetting: Int = 0 + private var isGUIScaled = false + + private fun setGUI() { + val gameSettings = Minecraft.getMinecraft().gameSettings ?: return + guiSetting = gameSettings.guiScale + gameSettings.guiScale = 0 + isGUIScaled = true + updateScale() + } + + private fun unSetGUI() { + if (!isGUIScaled) return + Minecraft.getMinecraft().gameSettings.guiScale = guiSetting + isGUIScaled = false + } + + @SubscribeEvent + fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { + if (!LorenzUtils.inSkyBlock) return + if (!config.quickRestart) return + if (!InventoryUtils.openInventoryName().startsWith("Melody")) return + if (event.slot?.slotNumber != 40) return + if (openTime.passedSince() > 2.seconds) return + event.container.inventory.indexOfFirst { it.getLore().contains("§aSong is selected!") }.takeIf { it != -1 }?.let { + event.isCanceled = true + Minecraft.getMinecraft().playerController.windowClick( + event.container.windowId, + it, + event.clickedButton, + event.clickType, + Minecraft.getMinecraft().thePlayer + ) + } } + @SubscribeEvent fun onRenderItemTip(event: RenderItemTipEvent) { if (!LorenzUtils.inSkyBlock) return @@ -84,7 +166,7 @@ object HarpFeatures { if (index == -1) return // this should never happen unless there's an update val keyCode = getKey(index) ?: return - event.stackTip = KeyboardManager.getKeyName(keyCode) + event.stackTip = KeyboardManager.getKeyName(keyCode).take(3) } @SubscribeEvent From 3f670c11132fc76b9c9d9e2cac59a7dbe84dff11 Mon Sep 17 00:00:00 2001 From: Thunderblade73 Date: Fri, 8 Dec 2023 17:10:55 +0100 Subject: [PATCH 05/10] updated to match beta --- .../features/inventory/HarpFeatures.kt | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt index 35311eb20a8a..ea9905d6242a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt @@ -2,18 +2,28 @@ package at.hannibal2.skyhanni.features.inventory import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator +import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.InventoryCloseEvent +import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.RenderItemTipEvent -import at.hannibal2.skyhanni.utils.InventoryUtils.openInventoryName +import at.hannibal2.skyhanni.utils.DelayedRun +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.StringUtils.matches +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.client.Minecraft +import net.minecraft.client.gui.ScaledResolution 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 net.minecraftforge.fml.common.network.FMLNetworkEvent import kotlin.time.Duration.Companion.milliseconds +import kotlin.time.Duration.Companion.seconds // Delaying key presses by 300ms comes from NotEnoughUpdates object HarpFeatures { @@ -32,8 +42,10 @@ object HarpFeatures { private val buttonColors = listOf('d', 'e', 'a', '2', '5', '9', 'b') private val inventoryTitleRegex by RepoPattern.pattern("harp.inventory", "^Harp.*") + private val menuTitleRegex by RepoPattern.pattern("harp.menu", "^Melody.*") - private fun isHarpGui() = inventoryTitleRegex.matches(openInventoryName()) + private fun isHarpGui() = inventoryTitleRegex.matches(InventoryUtils.openInventoryName()) + private fun isMenuGui() = menuTitleRegex.matches(InventoryUtils.openInventoryName()) fun getKey(index: Int) = when (index) { 0 -> config.harpKeybinds.key1 @@ -78,12 +90,12 @@ object HarpFeatures { if (!LorenzUtils.inSkyBlock) return if (!config.guiScale) return when { - event.inventoryName.startsWith("Melody") -> { + isMenuGui() -> { setGUI() openTime = SimpleTimeMark.now() } - event.inventoryName.startsWith("Harp") -> { + isHarpGui() -> { setGUI() } } @@ -138,7 +150,7 @@ object HarpFeatures { fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { if (!LorenzUtils.inSkyBlock) return if (!config.quickRestart) return - if (!InventoryUtils.openInventoryName().startsWith("Melody")) return + if (!isMenuGui()) return if (event.slot?.slotNumber != 40) return if (openTime.passedSince() > 2.seconds) return event.container.inventory.indexOfFirst { it.getLore().contains("§aSong is selected!") }.takeIf { it != -1 }?.let { From 758f97c5a59ee43aa97182b19918c38f94eec5c0 Mon Sep 17 00:00:00 2001 From: Thunderblade73 Date: Sun, 14 Jan 2024 21:29:09 +0100 Subject: [PATCH 06/10] idk --- .../config/features/inventory/helper/HelperConfig.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java index 022590cd66ec..add29c557c3f 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java @@ -16,13 +16,14 @@ public static class HarpConfig { @Expose @ConfigOption(name = "GUI Scale", desc = "Automatically sets the GUI scale to \"AUTO\" when entering the Harp") @ConfigEditorBoolean - @FeatureToggle public boolean guiScale = false; + @Expose @ConfigOption(name = "Quick Restart", desc = "When pressing the close Button in the Harp Menu shortly after opening the Harp the selected song will be started") @ConfigEditorBoolean @FeatureToggle public boolean quickRestart = false; + @Expose @ConfigOption(name = "Use Keybinds", desc = "In the Harp, press buttons with your number row on the keyboard instead of clicking.") @ConfigEditorBoolean From 5f5067952eee81045c60382dc682d796d7089a85 Mon Sep 17 00:00:00 2001 From: Thunderblade73 Date: Sun, 21 Jan 2024 00:01:35 +0100 Subject: [PATCH 07/10] extracted Constants --- .../skyhanni/features/inventory/HarpFeatures.kt | 14 ++++++++++---- .../at/hannibal2/skyhanni/utils/StringUtils.kt | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt index 05adf51c7463..d2beeecf3792 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt @@ -13,6 +13,7 @@ import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.StringUtils.anyMatches import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.client.Minecraft @@ -27,10 +28,14 @@ import kotlin.time.Duration.Companion.seconds // Delaying key presses by 300ms comes from NotEnoughUpdates object HarpFeatures { + private val config get() = SkyHanniMod.feature.inventory.helper.harp private var lastClick = SimpleTimeMark.farPast() + private const val closeButtonSlot = 40 + private object KeyIterable : Iterable { + override fun iterator() = object : Iterator { private var currentIndex = 0 @@ -43,11 +48,11 @@ object HarpFeatures { private val buttonColors = listOf('d', 'e', 'a', '2', '5', '9', 'b') private val inventoryTitlePattern by RepoPattern.pattern("harp.inventory", "^Harp.*") private val menuTitlePattern by RepoPattern.pattern("harp.menu", "^Melody.*") + private val songSelectedPattern by RepoPattern.pattern("harp.song.selected", "§aSong is selected!") private fun isHarpGui() = inventoryTitlePattern.matches(InventoryUtils.openInventoryName()) private fun isMenuGui() = menuTitlePattern.matches(InventoryUtils.openInventoryName()) - @SubscribeEvent fun onGui(event: GuiScreenEvent) { if (!LorenzUtils.inSkyBlock) return @@ -151,9 +156,11 @@ object HarpFeatures { if (!LorenzUtils.inSkyBlock) return if (!config.quickRestart) return if (!isMenuGui()) return - if (event.slot?.slotNumber != 40) return + if (event.slot?.slotNumber != closeButtonSlot) return if (openTime.passedSince() > 2.seconds) return - event.container.inventory.indexOfFirst { it.getLore().contains("§aSong is selected!") }.takeIf { it != -1 }?.let { + event.container.inventory.indexOfFirst { + songSelectedPattern.anyMatches(it.getLore()) + }.takeIf { it != -1 }?.let { event.isCanceled = true Minecraft.getMinecraft().playerController.windowClick( event.container.windowId, @@ -165,7 +172,6 @@ object HarpFeatures { } } - @SubscribeEvent fun onRenderItemTip(event: RenderItemTipEvent) { if (!LorenzUtils.inSkyBlock) return diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index b25c47aaee9a..11b843b64f46 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -282,6 +282,7 @@ object StringUtils { fun String.convertToFormatted(): String = this.replace("&&", "§") fun Pattern.matches(string: String?) = string?.let { matcher(it).matches() } ?: false + fun Pattern.anyMatches(list: List?) = list?.any { this.matches(it) } ?: false fun Pattern.find(string: String?) = string?.let { matcher(it).find() } ?: false From fcf2f9a686c5736c709dd091a321ef550be97cbe Mon Sep 17 00:00:00 2001 From: Thunderblade73 Date: Sun, 21 Jan 2024 00:03:40 +0100 Subject: [PATCH 08/10] cleanup --- .../features/inventory/HarpFeatures.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt index d2beeecf3792..c2b0cd6b5420 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt @@ -46,8 +46,8 @@ object HarpFeatures { } private val buttonColors = listOf('d', 'e', 'a', '2', '5', '9', 'b') - private val inventoryTitlePattern by RepoPattern.pattern("harp.inventory", "^Harp.*") - private val menuTitlePattern by RepoPattern.pattern("harp.menu", "^Melody.*") + private val inventoryTitlePattern by RepoPattern.pattern("harp.inventory", "Harp.*") + private val menuTitlePattern by RepoPattern.pattern("harp.menu", "Melody.*") private val songSelectedPattern by RepoPattern.pattern("harp.song.selected", "§aSong is selected!") private fun isHarpGui() = inventoryTitlePattern.matches(InventoryUtils.openInventoryName()) @@ -91,22 +91,22 @@ object HarpFeatures { private var openTime: SimpleTimeMark = SimpleTimeMark.farPast() @SubscribeEvent - fun onInventoryFullyOpenedEvent(event: InventoryFullyOpenedEvent) { + fun onInventoryOpen(event: InventoryFullyOpenedEvent) { if (!LorenzUtils.inSkyBlock) return if (!config.guiScale) return when { isMenuGui() -> { - setGUI() + setGUIScale() openTime = SimpleTimeMark.now() } isHarpGui() -> { - setGUI() + setGUIScale() } } } - fun updateScale() { + private fun updateScale() { if (Minecraft.getMinecraft().currentScreen == null) { DelayedRun.runDelayed(100.milliseconds) { updateScale() @@ -125,19 +125,19 @@ object HarpFeatures { fun onInventoryCloseEvent(event: InventoryCloseEvent) { if (!LorenzUtils.inSkyBlock) return if (!config.guiScale) return - unSetGUI() + unSetGUIScale() } @SubscribeEvent fun onLeave(event: FMLNetworkEvent.ClientDisconnectionFromServerEvent) { if (!config.guiScale) return - unSetGUI() + unSetGUIScale() } private var guiSetting: Int = 0 private var isGUIScaled = false - private fun setGUI() { + private fun setGUIScale() { val gameSettings = Minecraft.getMinecraft().gameSettings ?: return guiSetting = gameSettings.guiScale gameSettings.guiScale = 0 @@ -145,7 +145,7 @@ object HarpFeatures { updateScale() } - private fun unSetGUI() { + private fun unSetGUIScale() { if (!isGUIScaled) return Minecraft.getMinecraft().gameSettings.guiScale = guiSetting isGUIScaled = false From 19bbac73eafff96bc399423886179a28e532004c Mon Sep 17 00:00:00 2001 From: Thunderblade73 Date: Sun, 21 Jan 2024 00:23:40 +0100 Subject: [PATCH 09/10] fix of bug --- .../skyhanni/features/inventory/HarpFeatures.kt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt index c2b0cd6b5420..5e6656b3bc67 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt @@ -50,14 +50,14 @@ object HarpFeatures { private val menuTitlePattern by RepoPattern.pattern("harp.menu", "Melody.*") private val songSelectedPattern by RepoPattern.pattern("harp.song.selected", "§aSong is selected!") - private fun isHarpGui() = inventoryTitlePattern.matches(InventoryUtils.openInventoryName()) - private fun isMenuGui() = menuTitlePattern.matches(InventoryUtils.openInventoryName()) + private fun isHarpGui(chestName: String) = inventoryTitlePattern.matches(chestName) + private fun isMenuGui(chestName: String) = menuTitlePattern.matches(chestName) @SubscribeEvent fun onGui(event: GuiScreenEvent) { if (!LorenzUtils.inSkyBlock) return if (!config.keybinds) return - if (!isHarpGui()) return + if (!isHarpGui(InventoryUtils.openInventoryName())) return val chest = event.gui as? GuiChest ?: return for ((index, key) in KeyIterable.withIndex()) { @@ -95,12 +95,12 @@ object HarpFeatures { if (!LorenzUtils.inSkyBlock) return if (!config.guiScale) return when { - isMenuGui() -> { + isMenuGui(event.inventoryName) -> { setGUIScale() openTime = SimpleTimeMark.now() } - isHarpGui() -> { + isHarpGui(event.inventoryName) -> { setGUIScale() } } @@ -108,7 +108,7 @@ object HarpFeatures { private fun updateScale() { if (Minecraft.getMinecraft().currentScreen == null) { - DelayedRun.runDelayed(100.milliseconds) { + DelayedRun.runNextTick() { updateScale() } return @@ -155,7 +155,7 @@ object HarpFeatures { fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { if (!LorenzUtils.inSkyBlock) return if (!config.quickRestart) return - if (!isMenuGui()) return + if (!isMenuGui(InventoryUtils.openInventoryName())) return if (event.slot?.slotNumber != closeButtonSlot) return if (openTime.passedSince() > 2.seconds) return event.container.inventory.indexOfFirst { @@ -176,7 +176,7 @@ object HarpFeatures { fun onRenderItemTip(event: RenderItemTipEvent) { if (!LorenzUtils.inSkyBlock) return if (!config.showNumbers) return - if (!isHarpGui()) return + if (!isHarpGui(InventoryUtils.openInventoryName())) return if (Item.getIdFromItem(event.stack.item) != 159) return // Stained hardened clay item id = 159 // Example: §9| §7Click! will select the 9 From 16e0078d43ea10a6e2f42a99b720be3dcf8e4db2 Mon Sep 17 00:00:00 2001 From: Thunderblade73 Date: Sun, 21 Jan 2024 00:34:27 +0100 Subject: [PATCH 10/10] description fix --- .../config/features/inventory/helper/HelperConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java index add29c557c3f..936aaf59bd15 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java @@ -14,12 +14,12 @@ public class HelperConfig { public static class HarpConfig { @Expose - @ConfigOption(name = "GUI Scale", desc = "Automatically sets the GUI scale to \"AUTO\" when entering the Harp") + @ConfigOption(name = "GUI Scale", desc = "Automatically sets the GUI scale to \"AUTO\" when entering the Harp.") @ConfigEditorBoolean public boolean guiScale = false; @Expose - @ConfigOption(name = "Quick Restart", desc = "When pressing the close Button in the Harp Menu shortly after opening the Harp the selected song will be started") + @ConfigOption(name = "Quick Restart", desc = "Once you've launched the Harp, quickly hit the close button in the Harp Menu to initiate the selected song.") @ConfigEditorBoolean @FeatureToggle public boolean quickRestart = false;