diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-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()) |