From 8d0758ecf3ccffef632a3d6e2c84fd705a0035b7 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Tue, 2 Jul 2024 09:00:36 +0200 Subject: Fix: Gillsplash in Estimated Item Value (#2173) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../java/at/hannibal2/skyhanni/utils/ItemUtils.kt | 21 ++++++++++++++++++++- .../java/at/hannibal2/skyhanni/utils/NEUItems.kt | 5 ++++- 2 files changed, 24 insertions(+), 2 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/utils') diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index 67f2865eb..c094df489 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -2,8 +2,10 @@ package at.hannibal2.skyhanni.utils import at.hannibal2.skyhanni.data.PetAPI import at.hannibal2.skyhanni.test.command.ErrorManager +import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull +import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher import at.hannibal2.skyhanni.utils.RegexUtils.matches @@ -14,6 +16,7 @@ import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.StringUtils.removeResets import com.google.gson.GsonBuilder import com.google.gson.JsonObject +import io.github.moulberry.notenoughupdates.recipes.NeuRecipe import net.minecraft.client.Minecraft import net.minecraft.init.Items import net.minecraft.item.ItemStack @@ -339,7 +342,7 @@ object ItemUtils { "internal name" to pet.getInternalName(), "item name" to name, "rarity id" to rarityId, - "inventory name" to InventoryUtils.openInventoryName() + "inventory name" to InventoryUtils.openInventoryName(), ) } return rarity @@ -409,4 +412,20 @@ object ItemUtils { } return list } + + fun neededItems(recipe: NeuRecipe): Map { + val neededItems = mutableMapOf() + for (ingredient in recipe.ingredients) { + val material = ingredient.internalItemId.asInternalName() + val amount = ingredient.count.toInt() + neededItems.addOrPut(material, amount) + } + return neededItems + } + + fun getRecipePrice(recipe: NeuRecipe): Double = + neededItems(recipe).map { + it.key.getPrice() * it.value + }.sum() + } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index 4b334d027..75d394631 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -197,7 +197,10 @@ object NEUItems { return getNpcPriceOrNull() ?: getRawCraftCostOrNull() } - fun NEUInternalName.getRawCraftCostOrNull(): Double? = manager.auctionManager.getCraftCost(asString())?.craftCost + // If NEU fails to calculate the craft costs, we calculate it ourself. + fun NEUInternalName.getRawCraftCostOrNull(): Double? = manager.auctionManager.getCraftCost(asString())?.craftCost ?: run { + getRecipes(this).map { ItemUtils.getRecipePrice(it) }.minOrNull() + } fun NEUInternalName.getItemStackOrNull(): ItemStack? = ItemResolutionQuery(manager) .withKnownInternalName(asString()) -- cgit