From d524a9979b1de74c07a90d806703e518b2b184a1 Mon Sep 17 00:00:00 2001 From: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Date: Tue, 27 Feb 2024 02:25:12 +1100 Subject: = Fixed HighlightMissingRepoItems. #1062 --- .../at/hannibal2/skyhanni/test/HighlightMissingRepoItems.kt | 11 ++--------- src/main/java/at/hannibal2/skyhanni/utils/ItemNameResolver.kt | 1 + src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt | 9 +++++++++ 3 files changed, 12 insertions(+), 9 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni') diff --git a/src/main/java/at/hannibal2/skyhanni/test/HighlightMissingRepoItems.kt b/src/main/java/at/hannibal2/skyhanni/test/HighlightMissingRepoItems.kt index 62bb84b94..6eea21007 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/HighlightMissingRepoItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/HighlightMissingRepoItems.kt @@ -3,12 +3,10 @@ package at.hannibal2.skyhanni.test import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.events.GuiContainerEvent -import at.hannibal2.skyhanni.events.NeuRepositoryReloadEvent import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUItems -import at.hannibal2.skyhanni.utils.NEUItems.allItemsCache import at.hannibal2.skyhanni.utils.RenderUtils.highlight import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiChest @@ -35,21 +33,16 @@ class HighlightMissingRepoItems { } private fun highlightItems(slots: Iterable) { - if (allItemsCache.isEmpty()) return + if (NEUItems.allInternalNames.isEmpty()) return for (slot in slots) { val internalName = slot.stack?.getInternalNameOrNull() ?: continue - if (allItemsCache.containsValue(internalName)) continue + if (NEUItems.allInternalNames.contains(internalName)) continue if (NEUItems.ignoreItemsFilter.match(internalName.asString())) continue slot highlight LorenzColor.RED } } - @SubscribeEvent - fun onNeuRepoReload(event: NeuRepositoryReloadEvent) { - NEUItems.allItemsCache = NEUItems.readAllNeuItems() - } - @SubscribeEvent fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { event.move(3, "dev.highlightMissingRepo", "dev.debug.highlightMissingRepo") diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemNameResolver.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemNameResolver.kt index d17f579ed..baf9ee8ea 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemNameResolver.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemNameResolver.kt @@ -74,6 +74,7 @@ object ItemNameResolver { if (NEUItems.allItemsCache.isEmpty()) { NEUItems.allItemsCache = NEUItems.readAllNeuItems() } + NEUItems.allItemsCache[lowercase]?.let { itemNameCache[lowercase] = it return it diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index 69f1e4fc3..1ca6e2a70 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.utils import at.hannibal2.skyhanni.config.ConfigManager import at.hannibal2.skyhanni.data.jsonobjects.repo.MultiFilterJson +import at.hannibal2.skyhanni.events.NeuRepositoryReloadEvent import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.features.bazaar.BazaarDataHolder import at.hannibal2.skyhanni.test.command.ErrorManager @@ -40,6 +41,7 @@ object NEUItems { private val ingredientsCache = mutableMapOf>() var allItemsCache = mapOf() // item name -> internal name + val allInternalNames = mutableListOf() val ignoreItemsFilter = MultiFilter() private val fallbackItem by lazy { @@ -56,15 +58,22 @@ object NEUItems { ignoreItemsFilter.load(ignoredItems) } + @SubscribeEvent + fun onNeuRepoReload(event: NeuRepositoryReloadEvent) { + allItemsCache = readAllNeuItems() + } + @Deprecated("Use NEUInternalName rather than String", ReplaceWith("getInternalNameFromItemName()")) fun getRawInternalName(itemName: String): String = NEUInternalName.fromItemName(itemName).asString() fun readAllNeuItems(): Map { + allInternalNames.clear() val map = mutableMapOf() for (rawInternalName in allNeuRepoItems().keys) { val name = manager.createItem(rawInternalName).displayName.removeColor().lowercase() val internalName = rawInternalName.asInternalName() map[name] = internalName + allInternalNames.add(internalName) } return map } -- cgit