From 1e9764d1d1209177d4a939a9b812931a7d49a926 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Tue, 24 Sep 2024 10:27:50 +0200 Subject: Backend: PrimitiveIngredient changes and code cleanup (#2576) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Co-authored-by: Cal --- .../hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt | 9 ++++----- .../features/garden/visitor/GardenVisitorFeatures.kt | 13 ++++++------- .../features/garden/visitor/GardenVisitorSupercraft.kt | 14 +++++++------- 3 files changed, 17 insertions(+), 19 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features') 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 dbec4ea57..6f7a062f8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.hasEnchantments import at.hannibal2.skyhanni.utils.ItemUtils.itemName @@ -18,6 +19,7 @@ import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NEUItems.getCachedIngredients import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary +import at.hannibal2.skyhanni.utils.PrimitiveIngredient.Companion.toPrimitiveItemStacks import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -197,12 +199,9 @@ object MinionCraftHelper { val output = recipe.output ?: continue if (!output.internalName.contains("_GENERATOR_")) continue val map = mutableMapOf() - for (input in recipe.ingredients) { - val itemId = input.internalName + for ((itemId, count) in recipe.ingredients.toPrimitiveItemStacks()) { if (minionId != itemId) { - val count = input.count.toInt() - val old = map.getOrDefault(itemId, 0) - map[itemId] = old + count + map.addOrPut(itemId, count) } } var allDone = true diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt index 2e8d78966..70392bb46 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt @@ -29,6 +29,7 @@ import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList +import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut import at.hannibal2.skyhanni.utils.ConfigUtils import at.hannibal2.skyhanni.utils.EntityUtils import at.hannibal2.skyhanni.utils.HypixelCommands @@ -51,6 +52,7 @@ import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat +import at.hannibal2.skyhanni.utils.PrimitiveIngredient.Companion.toPrimitiveItemStacks import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher import at.hannibal2.skyhanni.utils.RenderUtils.drawString import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems @@ -253,16 +255,13 @@ object GardenVisitorFeatures { ?.ingredients ?: emptySet() if (ingredients.isEmpty()) return - // TODO change key to NEUInternalName - val requiredIngredients = mutableMapOf() - for (ingredient in ingredients) { - val key = ingredient.internalName.asString() - requiredIngredients[key] = - requiredIngredients.getOrDefault(key, 0) + ingredient.count.toInt() + val requiredIngredients = mutableMapOf() + for ((key, count) in ingredients.toPrimitiveItemStacks()) { + requiredIngredients.addOrPut(key, count) } var hasIngredients = true for ((key, value) in requiredIngredients) { - val sackItem = key.asInternalName().getAmountInSacks() + val sackItem = key.getAmountInSacks() if (sackItem < value * (amount - amountInSacks)) { hasIngredients = false break diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt index f2e4f80fb..9b14483dc 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt @@ -7,12 +7,14 @@ import at.hannibal2.skyhanni.events.garden.visitor.VisitorOpenEvent import at.hannibal2.skyhanni.events.render.gui.ReplaceItemEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.test.command.ErrorManager +import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut import at.hannibal2.skyhanni.utils.HypixelCommands import at.hannibal2.skyhanni.utils.ItemUtils 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.getItemStack +import at.hannibal2.skyhanni.utils.PrimitiveIngredient.Companion.toPrimitiveItemStacks import at.hannibal2.skyhanni.utils.SimpleTimeMark import net.minecraft.entity.player.InventoryPlayer import net.minecraftforge.fml.common.eventhandler.EventPriority @@ -73,15 +75,13 @@ object GardenVisitorSupercraft { // TODO describe what this line does .firstOrNull { !it.ingredients.first().internalName.contains("PEST") } ?.ingredients ?: return - // TODO change key to NEUInternalName - val ingredientReqs = mutableMapOf() - for (ingredient in ingredients) { - val key = ingredient.internalName.asString() - ingredientReqs[key] = ingredientReqs.getOrDefault(key, 0) + ingredient.count.toInt() + val requiredIngredients = mutableMapOf() + for ((key, count) in ingredients.toPrimitiveItemStacks()) { + requiredIngredients.addOrPut(key, count) } hasIngredients = true - for ((key, value) in ingredientReqs) { - val sackItem = key.asInternalName().getAmountInSacks() + for ((key, value) in requiredIngredients) { + val sackItem = key.getAmountInSacks() lastSuperCraftMaterial = internalName.asString() if (sackItem < value * amount) { hasIngredients = false -- cgit