diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-02-24 17:28:33 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-03-01 16:07:28 +0100 |
commit | 1779ecd642e5720589442d79f094a19178dc564b (patch) | |
tree | bcf30554fbb6b0125d42c104058106a1b62b65e6 /src/main/java | |
parent | e892f253ef12256dbd1182fc068b9cf0b06ffdb8 (diff) | |
download | skyhanni-1779ecd642e5720589442d79f094a19178dc564b.tar.gz skyhanni-1779ecd642e5720589442d79f094a19178dc564b.tar.bz2 skyhanni-1779ecd642e5720589442d79f094a19178dc564b.zip |
Fixed a bug with the Minion Craft Helper to not calculate the enchanted item size correctly.
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/minion/MinionCraftHelper.kt | 54 |
1 files changed, 30 insertions, 24 deletions
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<String, Int> { - 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<String, Pair<String, Int>>() + + fun getMultiplier(rawId: String): Pair<String, Int> { + if (multiplierCache.contains(rawId)) { + return multiplierCache[rawId]!! + } + for (recipe in NEUItems.manager.getAvailableRecipesFor(rawId)) { + if (recipe is CraftingRecipe) { + val map = mutableMapOf<String, Int>() + 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 } |