Skip to content

Commit

Permalink
fix infinite recursive for recipe cost
Browse files Browse the repository at this point in the history
  • Loading branch information
Thunderblade73 committed Jul 6, 2024
1 parent 1ae710a commit ed799d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
10 changes: 2 additions & 8 deletions src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()


}
15 changes: 9 additions & 6 deletions src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
}
Expand All @@ -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())
Expand Down

0 comments on commit ed799d5

Please sign in to comment.