diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-01-06 13:05:23 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-01-06 13:05:23 +0100 |
commit | 39f33e0d60e18afbc94549a7659744cd173b2c8f (patch) | |
tree | 57f32a047cd74ee5ac960b63c652cf40e0c9c0de /src/main/java/at | |
parent | 22538ddfb8c5094ff2b006250c095f9bd1eb05bb (diff) | |
download | skyhanni-39f33e0d60e18afbc94549a7659744cd173b2c8f.tar.gz skyhanni-39f33e0d60e18afbc94549a7659744cd173b2c8f.tar.bz2 skyhanni-39f33e0d60e18afbc94549a7659744cd173b2c8f.zip |
Extract FirstMinionTier logic from bingo minion craft helper for better analyzing the performance problems some users have.
Diffstat (limited to 'src/main/java/at')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/bingo/FirstMinionTier.kt | 71 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt | 23 |
2 files changed, 72 insertions, 22 deletions
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<NEUInternalName, Int>, + minions: MutableMap<String, NEUInternalName>, + tierOneMinions: MutableList<NEUInternalName>, + tierOneMinionsDone: MutableList<String>, + ) { + val help = helpMap(otherItems) + val tierOneMinionsFiltered = getTierOneMinionsFiltered(tierOneMinions, tierOneMinionsDone) + addMinion(tierOneMinionsFiltered, minions, tierOneMinionsDone) + addMoreMinions(tierOneMinionsFiltered, help, minions) + } + + private fun addMoreMinions( + tierOneMinionsFiltered: List<NEUInternalName>, + help: Map<NEUInternalName, Int>, + minions: MutableMap<String, NEUInternalName> + ) { + 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<NEUInternalName, Int>, + minions: MutableMap<String, NEUInternalName>, + 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<NEUInternalName>, + minions: MutableMap<String, NEUInternalName>, + tierOneMinionsDone: MutableList<String> + ) { + 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<NEUInternalName>, + tierOneMinionsDone: MutableList<String> + ) = tierOneMinions.filter { it.asString() !in tierOneMinionsDone } + + private fun helpMap(otherItems: Map<NEUInternalName, Int>) = + 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<NEUInternalName, Int>, minions: MutableMap<String, NEUInternalName>) { - 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, |