From 1779ecd642e5720589442d79f094a19178dc564b Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Fri, 24 Feb 2023 17:28:33 +0100 Subject: Fixed a bug with the Minion Craft Helper to not calculate the enchanted item size correctly. --- .../skyhanni/features/minion/MinionCraftHelper.kt | 54 ++++++++++++---------- 1 file changed, 30 insertions(+), 24 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCraftHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCraftHelper.kt index f84a21649..8a6a052a4 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCraftHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCraftHelper.kt @@ -94,7 +94,6 @@ class MinionCraftHelper { } } for ((rawId, need) in map) { -// println("need rawId: $rawId") val (itemId, multiplier) = getMultiplier(rawId) val needAmount = need * multiplier val have = otherItems.getOrDefault(itemId, 0) @@ -131,28 +130,35 @@ private fun String.addOneToId(): String { return replace(lastText, "" + next) } -private fun getMultiplier(rawId: String): Pair { - if (rawId == "MELON_BLOCK") { - return Pair("MELON", 9) - } - if (rawId == "HAY_BLOCK") { - return Pair("WHEAT", 9) - } - if (rawId == "ENCHANTED_HAY_BLOCK") { - return Pair("WHEAT", 9 * 16 * 9) - } - if (rawId == "PACKED_ICE") { - return Pair("ICE", 9) - } - if (rawId == "ENCHANTED_MITHRIL") { - return Pair("MITHRIL_ORE", 160) - } - if (rawId == "ENCHANTED_GOLD") { - return Pair("GOLD_INGOT", 160) - } - return if (rawId.startsWith("ENCHANTED_")) { - Pair(rawId.substring(10), 160) - } else { - Pair(rawId, 1) +var multiplierCache = mutableMapOf>() + + fun getMultiplier(rawId: String): Pair { + if (multiplierCache.contains(rawId)) { + return multiplierCache[rawId]!! + } + for (recipe in NEUItems.manager.getAvailableRecipesFor(rawId)) { + if (recipe is CraftingRecipe) { + val map = mutableMapOf() + for (ingredient in recipe.ingredients) { + val count = ingredient.count.toInt() + val internalItemId = ingredient.internalItemId + val old = map.getOrDefault(internalItemId, 0) + map[internalItemId] = old + count + } + if (map.size == 1) { + val pair = map.iterator().next().toPair() + val id = pair.first + val amount = pair.second + + val multiplier = getMultiplier(id) + val result = Pair(multiplier.first, multiplier.second * amount) + multiplierCache[rawId] = result + return result + } + } } + + val result = Pair(rawId, 1) + multiplierCache[rawId] = result + return result } -- cgit