diff options
| author | Linnea Gräf <nea@nea.moe> | 2025-10-16 17:27:41 +0200 |
|---|---|---|
| committer | Linnea Gräf <nea@nea.moe> | 2025-10-16 17:27:41 +0200 |
| commit | 9d6f60bc75e07df6c679351e4aceb5134cae5e01 (patch) | |
| tree | 46c0b967c5832a3ee7bf9ffe12c09350f9c3236e /src/main | |
| parent | e583a2ca378a3d9b4d8fa35246ef46504866318a (diff) | |
| download | Firmament-9d6f60bc75e07df6c679351e4aceb5134cae5e01.tar.gz Firmament-9d6f60bc75e07df6c679351e4aceb5134cae5e01.tar.bz2 Firmament-9d6f60bc75e07df6c679351e4aceb5134cae5e01.zip | |
feat: increase performance of screen type checks3.10.1+mc1.21.7
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/kotlin/util/SkyblockId.kt | 12 | ||||
| -rw-r--r-- | src/main/kotlin/util/skyblock/ScreenIdentification.kt | 61 |
2 files changed, 43 insertions, 30 deletions
diff --git a/src/main/kotlin/util/SkyblockId.kt b/src/main/kotlin/util/SkyblockId.kt index c9163e5..7fb6542 100644 --- a/src/main/kotlin/util/SkyblockId.kt +++ b/src/main/kotlin/util/SkyblockId.kt @@ -36,11 +36,8 @@ import moe.nea.firmament.util.collections.WeakCache import moe.nea.firmament.util.json.DashlessUUIDSerializer import moe.nea.firmament.util.mc.displayNameAccordingToNbt import moe.nea.firmament.util.mc.loreAccordingToNbt -import moe.nea.firmament.util.skyblock.isBazaarUi -import moe.nea.firmament.util.skyblock.isDyeCompendium -import moe.nea.firmament.util.skyblock.isEnchantmentGuide -import moe.nea.firmament.util.skyblock.isExperimentationRngMeter -import moe.nea.firmament.util.skyblock.isSuperPairs +import moe.nea.firmament.util.skyblock.ScreenIdentification +import moe.nea.firmament.util.skyblock.ScreenType /** * A SkyBlock item id, as used by the NEU repo. @@ -235,7 +232,8 @@ val ItemStack.rawSkyBlockId: String? get() = extraAttributes.getString("id").get fun ItemStack.guessContextualSkyBlockId(): SkyblockId? { val screen = MC.screen - if (screen?.isBazaarUi() == true || screen?.isDyeCompendium() == true) { + val screenType = ScreenIdentification.getType(screen) + if (screenType == ScreenType.BAZAAR_ANY || screenType == ScreenType.DYE_COMPENDIUM) { val name = displayNameAccordingToNbt.unformattedString .replaceFirst("SELL ", "") .replaceFirst("BUY ", "") @@ -244,7 +242,7 @@ fun ItemStack.guessContextualSkyBlockId(): SkyblockId? { } return ItemNameLookup.guessItemByName(name, false) } - if (screen != null && (screen.isExperimentationRngMeter() || screen.isSuperPairs() || screen.isEnchantmentGuide())) { + if (screen != null && (screenType == ScreenType.EXPERIMENTATION_RNG_METER || screenType == ScreenType.SUPER_PAIRS || screenType == ScreenType.ENCHANTMENT_GUIDE)) { val name = displayNameAccordingToNbt.unformattedString return RepoManager.enchantedBookCache.byName[name] ?: ItemNameLookup.guessItemByName(name, false) diff --git a/src/main/kotlin/util/skyblock/ScreenIdentification.kt b/src/main/kotlin/util/skyblock/ScreenIdentification.kt index 4fea3df..0e7797c 100644 --- a/src/main/kotlin/util/skyblock/ScreenIdentification.kt +++ b/src/main/kotlin/util/skyblock/ScreenIdentification.kt @@ -7,31 +7,46 @@ import moe.nea.firmament.util.mc.loreAccordingToNbt import moe.nea.firmament.util.unformattedString -fun Screen.isBazaarUi(): Boolean { - if (this !is GenericContainerScreen) return false - return ( - this.screenHandler.stacks[this.screenHandler.rows * 9 - 4] - .displayNameAccordingToNbt - .unformattedString == "Manage Orders" - || this.screenHandler.stacks[this.screenHandler.rows * 9 - 5] - .loreAccordingToNbt - .any { - it.unformattedString == "To Bazaar" - }) -} - -fun Screen.isEnchantmentGuide(): Boolean { - return title.unformattedString.endsWith("Enchantments Guide") -} +object ScreenIdentification { + private var lastScreen: Screen? = null + private var lastScreenType: ScreenType? = null -fun Screen.isSuperPairs(): Boolean { - return title.unformattedString.startsWith("Superpairs") + fun getType(screen: Screen?): ScreenType? { + if (screen == null) return null + if (screen !== lastScreen) { + lastScreenType = ScreenType.entries + .find { it.detector(screen) } + lastScreen = screen + } + return lastScreenType + } } -fun Screen.isExperimentationRngMeter(): Boolean { - return this.title.unformattedString.contains("Experimentation Table RNG") +enum class ScreenType(val detector: (Screen) -> Boolean) { + BAZAAR_ANY({ + it is GenericContainerScreen && ( + it.screenHandler.getSlot(it.screenHandler.rows * 9 - 4) + .stack + .displayNameAccordingToNbt + .unformattedString == "Manage Orders" + || it.screenHandler.getSlot(it.screenHandler.rows * 9 - 5) + .stack + .loreAccordingToNbt + .any { + it.unformattedString == "To Bazaar" + }) + }), + ENCHANTMENT_GUIDE({ + it.title.unformattedString.endsWith("Enchantments Guide") + }), + SUPER_PAIRS({ + it.title.unformattedString.startsWith("Superpairs") + }), + EXPERIMENTATION_RNG_METER({ + it.title.unformattedString.contains("Experimentation Table RNG") + }), + DYE_COMPENDIUM({ + it.title.unformattedString.contains("Dye Compendium") + }) } -fun Screen.isDyeCompendium(): Boolean { - return this.title.unformattedString.contains("Dye Compendium") -} |
