From bcbdf74c9563c555c767dc6ef26558152810e645 Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Sun, 7 Jul 2024 11:24:26 +0200 Subject: Fix: Stackoverflow for getPrice (#2199) --- src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt | 10 ++-------- src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt | 15 +++++++++------ 2 files changed, 11 insertions(+), 14 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index 79b57fcf7..b662e10d4 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -423,15 +423,9 @@ object ItemUtils { return neededItems } - fun getRecipePrice(recipe: NeuRecipe): Double = + fun getRecipePrice(recipe: NeuRecipe, pastRecipes: List = emptyList()): Double = neededItems(recipe).map { - // prevents stack overflow errors with ENDERMAN_MONSTER - if (it.key.endsWith("_MONSTER")) { - 0.0 - } else { - it.key.getPrice() * it.value - } + it.key.getPrice(pastRecipes = pastRecipes) * 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 75d394631..3fc54009e 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -160,7 +160,8 @@ object NEUItems { fun getInternalNameOrNull(nbt: NBTTagCompound): NEUInternalName? = ItemResolutionQuery(manager).withItemNBT(nbt).resolveInternalName()?.asInternalName() - fun NEUInternalName.getPrice(useSellPrice: Boolean = false) = getPriceOrNull(useSellPrice) ?: -1.0 + fun NEUInternalName.getPrice(useSellPrice: Boolean = false, pastRecipes: List = emptyList()) = + getPriceOrNull(useSellPrice, pastRecipes) ?: -1.0 fun NEUInternalName.getNpcPrice() = getNpcPriceOrNull() ?: -1.0 @@ -174,7 +175,7 @@ object NEUItems { fun transHypixelNameToInternalName(hypixelId: String): NEUInternalName = manager.auctionManager.transformHypixelBazaarToNEUItemId(hypixelId).asInternalName() - fun NEUInternalName.getPriceOrNull(useSellPrice: Boolean = false): Double? { + fun NEUInternalName.getPriceOrNull(useSellPrice: Boolean = false, pastRecipes: List = emptyList()): Double? { if (this == NEUInternalName.WISP_POTION) { return 20_000.0 } @@ -194,13 +195,15 @@ object NEUItems { return 7.0 // NPC price } - return getNpcPriceOrNull() ?: getRawCraftCostOrNull() + return getNpcPriceOrNull() ?: getRawCraftCostOrNull(pastRecipes) } // 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.getRawCraftCostOrNull(pastRecipes: List = emptyList()): Double? = + manager.auctionManager.getCraftCost(asString())?.craftCost ?: run { + getRecipes(this).filter { it !in pastRecipes } + .map { ItemUtils.getRecipePrice(it, pastRecipes + it) }.minOrNull() + } fun NEUInternalName.getItemStackOrNull(): ItemStack? = ItemResolutionQuery(manager) .withKnownInternalName(asString()) -- cgit