From 39f33e0d60e18afbc94549a7659744cd173b2c8f Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 6 Jan 2024 13:05:23 +0100 Subject: Extract FirstMinionTier logic from bingo minion craft helper for better analyzing the performance problems some users have. --- .../skyhanni/features/bingo/FirstMinionTier.kt | 71 ++++++++++++++++++++++ .../skyhanni/features/bingo/MinionCraftHelper.kt | 23 +------ 2 files changed, 72 insertions(+), 22 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/bingo/FirstMinionTier.kt (limited to 'src/main/java/at/hannibal2/skyhanni') diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/FirstMinionTier.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/FirstMinionTier.kt new file mode 100644 index 000000000..b76861818 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/FirstMinionTier.kt @@ -0,0 +1,71 @@ +package at.hannibal2.skyhanni.features.bingo + +import at.hannibal2.skyhanni.utils.ItemUtils.name +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.StringUtils.removeColor +import io.github.moulberry.notenoughupdates.recipes.CraftingRecipe + +object FirstMinionTier { + + fun firstMinionTier( + otherItems: Map, + minions: MutableMap, + tierOneMinions: MutableList, + tierOneMinionsDone: MutableList, + ) { + val help = helpMap(otherItems) + val tierOneMinionsFiltered = getTierOneMinionsFiltered(tierOneMinions, tierOneMinionsDone) + addMinion(tierOneMinionsFiltered, minions, tierOneMinionsDone) + addMoreMinions(tierOneMinionsFiltered, help, minions) + } + + private fun addMoreMinions( + tierOneMinionsFiltered: List, + help: Map, + minions: MutableMap + ) { + for (minionId in tierOneMinionsFiltered) { + for (recipe in NEUItems.getRecipes(minionId)) { + if (recipe !is CraftingRecipe) continue + checkOne(recipe, help, minions, minionId) + } + } + } + + private fun checkOne( + recipe: CraftingRecipe, + help: Map, + minions: MutableMap, + minionId: NEUInternalName + ) { + 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") + } + } + + private fun addMinion( + tierOneMinionsFiltered: List, + minions: MutableMap, + tierOneMinionsDone: MutableList + ) { + for (minionId in tierOneMinionsFiltered) { + val prefix = minionId.asString().dropLast(1) + if (minions.any { it.value.startsWith(prefix) }) { + tierOneMinionsDone.add(minionId.toString()) + } + } + } + + private fun getTierOneMinionsFiltered( + tierOneMinions: MutableList, + tierOneMinionsDone: MutableList + ) = tierOneMinions.filter { it.asString() !in tierOneMinionsDone } + + private fun helpMap(otherItems: Map) = + otherItems.filter { !it.key.startsWith("WOOD_") } +} 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 671b42848..227c4fd58 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt @@ -117,7 +117,7 @@ class MinionCraftHelper { } } - firstMinionTier(otherItems, minions) + FirstMinionTier.firstMinionTier(otherItems, minions, tierOneMinions, tierOneMinionsDone) return Pair(minions, otherItems) } @@ -170,27 +170,6 @@ class MinionCraftHelper { } } - private fun firstMinionTier(otherItems: Map, minions: MutableMap) { - val help = otherItems.filter { !it.key.startsWith("WOOD_") } - val tierOneMinionsFiltered = tierOneMinions.filter { it.asString() !in tierOneMinionsDone } - for (minionId in tierOneMinionsFiltered) { - val prefix = minionId.asString().dropLast(1) - if (minions.any { it.value.startsWith(prefix) }) { - 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.asInternalName()) }) { - val name = recipe.output.itemStack.name!!.removeColor() - val abc = name.replace(" I", " 0") - minions[abc] = minionId.replace("_1", "_0") - } - } - } - } - private fun addMinion( name: String, minionTier: Int, -- cgit