diff options
author | Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> | 2024-07-07 11:24:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-07 11:24:26 +0200 |
commit | bcbdf74c9563c555c767dc6ef26558152810e645 (patch) | |
tree | 1a83cda79db6d55f9905ee74413c7414c0f40ea5 | |
parent | 605d4c676fb126573e3267c6d45d3aee1860ba6d (diff) | |
download | skyhanni-bcbdf74c9563c555c767dc6ef26558152810e645.tar.gz skyhanni-bcbdf74c9563c555c767dc6ef26558152810e645.tar.bz2 skyhanni-bcbdf74c9563c555c767dc6ef26558152810e645.zip |
Fix: Stackoverflow for getPrice (#2199)
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt | 10 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt | 15 |
2 files changed, 11 insertions, 14 deletions
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<NeuRecipe> = 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<NeuRecipe> = 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<NeuRecipe> = 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<NeuRecipe> = 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()) |