From af7f09284caa16d7ba70c97a2c28c6a8fc1f83e6 Mon Sep 17 00:00:00 2001 From: Walker Selby Date: Sat, 9 Dec 2023 13:36:05 -0800 Subject: Internal Change: Minion craft helper NEUInternalName (#619) Changed MinionCraftHelper to use NeuInternalName. #619 --- .../skyhanni/features/bingo/MinionCraftHelper.kt | 75 +++++++++++----------- .../java/at/hannibal2/skyhanni/utils/NEUItems.kt | 39 +++++------ 2 files changed, 59 insertions(+), 55 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt index 902d325eb..9dab12e79 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt @@ -5,10 +5,13 @@ import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent -import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName_old +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.ItemUtils.getItemName import at.hannibal2.skyhanni.utils.ItemUtils.hasEnchantments import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUInternalName +import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NEUItems.getCachedIngredients import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary @@ -30,9 +33,9 @@ class MinionCraftHelper { private var display = emptyList() private var hasMinionInInventory = false private var hasItemsForMinion = false - private val tierOneMinions = mutableListOf() + private val tierOneMinions = mutableListOf() private val tierOneMinionsDone get() = BingoAPI.bingoStorage.tierOneMinionsDone - private val allIngredients = mutableListOf() + private val allIngredients = mutableListOf() private val alreadyNotified = mutableListOf() @SubscribeEvent @@ -70,8 +73,8 @@ class MinionCraftHelper { } private fun drawDisplay( - minions: MutableMap, - otherItems: MutableMap, + minions: MutableMap, + otherItems: MutableMap, ): MutableList { val newDisplay = mutableListOf() for ((minionName, minionId) in minions) { @@ -84,15 +87,15 @@ class MinionCraftHelper { return newDisplay } - private fun loadFromInventory(mainInventory: Array): Pair, MutableMap> { + private fun loadFromInventory(mainInventory: Array): Pair, MutableMap> { init() - val minions = mutableMapOf() - val otherItems = mutableMapOf() + val minions = mutableMapOf() + val otherItems = mutableMapOf() for (item in mainInventory) { val name = item?.name?.removeColor() ?: continue - val rawId = item.getInternalName_old() + val rawId = item.getInternalName() if (isMinionName(name)) { minions[name] = rawId } @@ -104,7 +107,7 @@ class MinionCraftHelper { for (item in mainInventory) { val name = item?.name?.removeColor() ?: continue if (item.hasEnchantments()) continue - val rawId = item.getInternalName_old() + val rawId = item.getInternalName() if (!isMinionName(name)) { if (!allIngredients.contains(rawId)) continue if (!isAllowed(allMinions, rawId)) continue @@ -119,14 +122,14 @@ class MinionCraftHelper { return Pair(minions, otherItems) } - private fun isAllowed(allMinions: List, internalName: String): Boolean { + private fun isAllowed(allMinions: List, internalName: NEUInternalName): Boolean { val a = NEUItems.getMultiplier(internalName) for (minion in allMinions) { val recipes = NEUItems.getRecipes(minion) for (recipe in recipes) { for (ingredient in recipe.getCachedIngredients()) { - val ingredientInternalName = ingredient.internalItemId + val ingredientInternalName = ingredient.internalItemId.asInternalName() if (ingredientInternalName == internalName) return true val b = NEUItems.getMultiplier(ingredientInternalName) @@ -143,21 +146,22 @@ class MinionCraftHelper { allIngredients.clear() for (internalId in NotEnoughUpdates.INSTANCE.manager.itemInformation.keys) { - if (internalId.endsWith("_GENERATOR_1")) { - if (internalId == "REVENANT_GENERATOR_1") continue - if (internalId == "TARANTULA_GENERATOR_1") continue - if (internalId == "VOIDLING_GENERATOR_1") continue - if (internalId == "INFERNO_GENERATOR_1") continue - if (internalId == "VAMPIRE_GENERATOR_1") continue - tierOneMinions.add(internalId) + val internalName = internalId.asInternalName() + if (internalName.endsWith("_GENERATOR_1")) { + if (internalName == "REVENANT_GENERATOR_1".asInternalName() || + internalName == "TARANTULA_GENERATOR_1".asInternalName() || + internalName == "VOIDLING_GENERATOR_1".asInternalName() || + internalName == "INFERNO_GENERATOR_1".asInternalName() || + internalName == "VAMPIRE_GENERATOR_1".asInternalName()) continue + tierOneMinions.add(internalName) } - if (internalId.contains("_GENERATOR_")) { - for (recipe in NEUItems.getRecipes(internalId)) { + if (internalName.contains("_GENERATOR_")) { + for (recipe in NEUItems.getRecipes(internalName)) { if (recipe !is CraftingRecipe) continue for (ingredient in recipe.getCachedIngredients()) { - val id = ingredient.internalItemId + val id = ingredient.internalItemId.asInternalName() if (!id.contains("_GENERATOR_") && !allIngredients.contains(id)) { allIngredients.add(id) } @@ -167,19 +171,19 @@ class MinionCraftHelper { } } - private fun firstMinionTier(otherItems: Map, minions: MutableMap) { + private fun firstMinionTier(otherItems: Map, minions: MutableMap) { val help = otherItems.filter { !it.key.startsWith("WOOD_") } - val tierOneMinionsFiltered = tierOneMinions.filter { it !in tierOneMinionsDone } + val tierOneMinionsFiltered = tierOneMinions.filter { it.asString() !in tierOneMinionsDone } for (minionId in tierOneMinionsFiltered) { - val prefix = minionId.dropLast(1) + val prefix = minionId.asString().dropLast(1) if (minions.any { it.value.startsWith(prefix) }) { - tierOneMinionsDone.add(minionId) + tierOneMinionsDone.add(minionId.toString()) } } for (minionId in tierOneMinionsFiltered) { for (recipe in NEUItems.getRecipes(minionId)) { if (recipe !is CraftingRecipe) continue - if (recipe.getCachedIngredients().any { help.contains(it.internalItemId) }) { + if (recipe.getCachedIngredients().any { help.contains(it.internalItemId.asInternalName()) }) { val name = recipe.output.itemStack.name!!.removeColor() val abc = name.replace(" I", " 0") minions[abc] = minionId.replace("_1", "_0") @@ -191,8 +195,8 @@ class MinionCraftHelper { private fun addMinion( name: String, minionTier: Int, - minionId: String, - otherItems: MutableMap, + minionId: NEUInternalName, + otherItems: MutableMap, newDisplay: MutableList, ) { val nextTier = minionTier + 1 @@ -202,11 +206,11 @@ class MinionCraftHelper { for (recipe in NEUItems.getRecipes(nextMinionId)) { if (recipe !is CraftingRecipe) continue val output = recipe.output - val internalItemId = output.internalItemId + val internalItemId = output.internalItemId.asInternalName() if (!internalItemId.contains("_GENERATOR_")) continue - val map = mutableMapOf() + val map = mutableMapOf() for (input in recipe.inputs) { - val itemId = input.internalItemId + val itemId = input.internalItemId.asInternalName() if (minionId != itemId) { val count = input.count.toInt() val old = map.getOrDefault(itemId, 0) @@ -219,7 +223,7 @@ class MinionCraftHelper { val needAmount = need * multiplier val have = otherItems.getOrDefault(itemId, 0) val percentage = have.toDouble() / needAmount - val itemName = NEUItems.getItemStack(rawId).name ?: "§cName??§f" + val itemName = rawId.getItemName() val isTool = itemId.startsWith("WOOD_") if (percentage >= 1) { val color = if (isTool) "§7" else "§a" @@ -260,8 +264,8 @@ class MinionCraftHelper { alreadyNotified.add(minionName) } - private fun String.addOneToId(): String { - val lastText = split("_").last() + private fun NEUInternalName.addOneToId(): NEUInternalName { + val lastText = asString().split("_").last() val next = lastText.toInt() + 1 return replace(lastText, "" + next) } @@ -276,7 +280,6 @@ class MinionCraftHelper { for ((_, b) in event.inventoryItems) { val name = b.name ?: continue if (!name.startsWith("§e")) continue - val internalName = NEUItems.getRawInternalName("$name I") .replace("MINION", "GENERATOR").replace(";", "_").replace("CAVE_SPIDER", "CAVESPIDER") if (!tierOneMinionsDone.contains(internalName)) { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index 02c8dff54..dff8a77e9 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -33,8 +33,8 @@ import java.util.regex.Pattern object NEUItems { val manager: NEUManager get() = NotEnoughUpdates.INSTANCE.manager private val itemNameCache = mutableMapOf() // item name -> internal name - private val multiplierCache = mutableMapOf>() - private val recipesCache = mutableMapOf>() + private val multiplierCache = mutableMapOf>() + private val recipesCache = mutableMapOf>() private val ingredientsCache = mutableMapOf>() private val enchantmentNamePattern = Pattern.compile("^(?(?:§.)+)(?[^§]+) (?[IVXL]+)$") var allItemsCache = mapOf() // item name -> internal name @@ -231,11 +231,6 @@ object NEUItems { } fun getMultiplier(internalName: NEUInternalName, tryCount: Int = 0): Pair { - val pair = getMultiplier(internalName.asString(), tryCount) - return Pair(pair.first.asInternalName(), pair.second) - } - - fun getMultiplier(internalName: String, tryCount: Int = 0): Pair { if (multiplierCache.contains(internalName)) { return multiplierCache[internalName]!! } @@ -250,27 +245,27 @@ object NEUItems { for (recipe in getRecipes(internalName)) { if (recipe !is CraftingRecipe) continue - val map = mutableMapOf() + val map = mutableMapOf() for (ingredient in recipe.getCachedIngredients()) { val count = ingredient.count.toInt() - var internalItemId = ingredient.internalItemId + var internalItemId = ingredient.internalItemId.asInternalName() // ignore cactus green - if (internalName == "ENCHANTED_CACTUS_GREEN" && internalItemId == "INK_SACK-2") { - internalItemId = "CACTUS" + if (internalName == "ENCHANTED_CACTUS_GREEN".asInternalName() && internalItemId == "INK_SACK-2".asInternalName()) { + internalItemId = "CACTUS".asInternalName() } // ignore wheat in enchanted cookie - if (internalName == "ENCHANTED_COOKIE" && internalItemId == "WHEAT") { + if (internalName == "ENCHANTED_COOKIE".asInternalName() && internalItemId == "WHEAT".asInternalName()) { continue } // ignore golden carrot in enchanted golden carrot - if (internalName == "ENCHANTED_GOLDEN_CARROT" && internalItemId == "GOLDEN_CARROT") { + if (internalName == "ENCHANTED_GOLDEN_CARROT".asInternalName() && internalItemId == "GOLDEN_CARROT".asInternalName()) { continue } // ignore rabbit hide in leather - if (internalName == "LEATHER" && internalItemId == "RABBIT_HIDE") { + if (internalName == "LEATHER".asInternalName() && internalItemId == "RABBIT_HIDE".asInternalName()) { continue } @@ -293,14 +288,20 @@ object NEUItems { val result = Pair(internalName, 1) multiplierCache[internalName] = result return result + + } + + fun getMultiplier(internalName: String, tryCount: Int = 0): Pair { + val pair = getMultiplier(internalName.asInternalName(), tryCount) + return Pair(pair.first.asString(), pair.second) } - fun getRecipes(minionId: String): Set { - if (recipesCache.contains(minionId)) { - return recipesCache[minionId]!! + fun getRecipes(internalName: NEUInternalName): Set { + if (recipesCache.contains(internalName)) { + return recipesCache[internalName]!! } - val recipes = manager.getRecipesFor(minionId) - recipesCache[minionId] = recipes + val recipes = manager.getRecipesFor(internalName.asString()) + recipesCache[internalName] = recipes return recipes } -- cgit