aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt68
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt69
2 files changed, 80 insertions, 57 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt
index e604c29ff..b03b47168 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt
@@ -1,18 +1,78 @@
package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarApi.getBazaarData
+import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarDataHolder
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.itemName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull
-import at.hannibal2.skyhanni.utils.NEUItems.getLowestBinOrNull
-import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull
-import at.hannibal2.skyhanni.utils.NEUItems.getPrice
-import at.hannibal2.skyhanni.utils.NEUItems.getRawCraftCostOrNull
+import at.hannibal2.skyhanni.utils.NEUItems.getRecipes
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
+import io.github.moulberry.notenoughupdates.recipes.NeuRecipe
object ItemPriceUtils {
+ fun NEUInternalName.getPrice(
+ priceSource: ItemPriceSource = ItemPriceSource.BAZAAR_INSTANT_BUY,
+ pastRecipes: List<NeuRecipe> = emptyList(),
+ ) = getPriceOrNull(priceSource, pastRecipes) ?: -1.0
+
+ fun NEUInternalName.getPriceOrNull(
+ priceSource: ItemPriceSource = ItemPriceSource.BAZAAR_INSTANT_BUY,
+ pastRecipes: List<NeuRecipe> = emptyList(),
+ ): Double? {
+ when (this) {
+ NEUInternalName.JASPER_CRYSTAL -> return 0.0
+ NEUInternalName.RUBY_CRYSTAL -> return 0.0
+ NEUInternalName.SKYBLOCK_COIN -> return 1.0
+ NEUInternalName.WISP_POTION -> return 20_000.0
+ }
+
+ if (priceSource != ItemPriceSource.NPC_SELL) {
+ getBazaarData()?.let {
+ return if (priceSource == ItemPriceSource.BAZAAR_INSTANT_BUY) it.sellOfferPrice else it.instantBuyPrice
+ }
+
+ getLowestBinOrNull()?.let {
+ return it
+ }
+
+ if (equals("JACK_O_LANTERN")) {
+ return "PUMPKIN".asInternalName().getPrice(priceSource) + 1
+ }
+ }
+ if (equals("GOLDEN_CARROT")) {
+ // 6.8 for some players
+ return 7.0 // NPC price
+ }
+
+ return getNpcPriceOrNull() ?: getRawCraftCostOrNull(pastRecipes)
+ }
+
+ private fun NEUInternalName.getLowestBinOrNull(): Double? {
+ val result = NEUItems.manager.auctionManager.getLowestBin(asString())
+ if (result == -1L) return null
+ return result.toDouble()
+ }
+
+ // If NEU fails to calculate the craft costs, we calculate it ourself.
+ fun NEUInternalName.getRawCraftCostOrNull(pastRecipes: List<NeuRecipe> = emptyList()): Double? =
+ NEUItems.manager.auctionManager.getCraftCost(asString())?.craftCost ?: run {
+ getRecipes(this).filter { it !in pastRecipes }
+ .map { ItemUtils.getRecipePrice(it, pastRecipes + it) }
+ .filter { it >= 0 }
+ .minOrNull()
+ }
+
+ fun NEUInternalName.getNpcPrice(): Double = getNpcPriceOrNull() ?: -1.0
+
+ fun NEUInternalName.getNpcPriceOrNull(): Double? {
+ if (this == NEUInternalName.WISP_POTION) {
+ return 20_000.0
+ }
+ return BazaarDataHolder.getNpcPrice(this)
+ }
+
fun debugItemPrice(args: Array<String>) {
val internalName = getItemOrFromHand(args)
if (internalName == null) {
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
index f3657d10e..ae3863410 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
@@ -7,8 +7,6 @@ import at.hannibal2.skyhanni.data.jsonobjects.repo.MultiFilterJson
import at.hannibal2.skyhanni.events.NeuProfileDataLoadedEvent
import at.hannibal2.skyhanni.events.NeuRepositoryReloadEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
-import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarApi.getBazaarData
-import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarDataHolder
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.ItemBlink.checkBlinkItem
@@ -47,6 +45,11 @@ import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import org.lwjgl.opengl.GL11
+import at.hannibal2.skyhanni.utils.ItemPriceUtils.getNpcPrice as getNpcPriceNew
+import at.hannibal2.skyhanni.utils.ItemPriceUtils.getNpcPriceOrNull as getNpcPriceOrNullNew
+import at.hannibal2.skyhanni.utils.ItemPriceUtils.getPrice as getPriceNew
+import at.hannibal2.skyhanni.utils.ItemPriceUtils.getPriceOrNull as getPriceOrNullNew
+import at.hannibal2.skyhanni.utils.ItemPriceUtils.getRawCraftCostOrNull as getRawCraftCostOrNullNew
@SkyHanniModule
object NEUItems {
@@ -160,69 +163,29 @@ object NEUItems {
fun getInternalNameOrNull(nbt: NBTTagCompound): NEUInternalName? =
ItemResolutionQuery(manager).withItemNBT(nbt).resolveInternalName()?.asInternalName()
+ @Deprecated("Moved to ItemPriceUtils", ReplaceWith(""))
fun NEUInternalName.getPrice(
priceSource: ItemPriceSource = ItemPriceSource.BAZAAR_INSTANT_BUY,
pastRecipes: List<NeuRecipe> = emptyList(),
- ) = getPriceOrNull(priceSource, pastRecipes) ?: -1.0
+ ): Double = getPriceNew(priceSource, pastRecipes)
- fun NEUInternalName.getNpcPrice() = getNpcPriceOrNull() ?: -1.0
+ @Deprecated("Moved to ItemPriceUtils", ReplaceWith(""))
+ fun NEUInternalName.getNpcPrice(): Double = getNpcPriceNew()
- fun NEUInternalName.getNpcPriceOrNull(): Double? {
- if (this == NEUInternalName.WISP_POTION) {
- return 20_000.0
- }
- return BazaarDataHolder.getNpcPrice(this)
- }
+ @Deprecated("Moved to ItemPriceUtils", ReplaceWith(""))
+ fun NEUInternalName.getNpcPriceOrNull(): Double? = getNpcPriceOrNullNew()
fun transHypixelNameToInternalName(hypixelId: String): NEUInternalName =
manager.auctionManager.transformHypixelBazaarToNEUItemId(hypixelId).asInternalName()
+ @Deprecated("Moved to ItemPriceUtils", ReplaceWith(""))
fun NEUInternalName.getPriceOrNull(
priceSource: ItemPriceSource = ItemPriceSource.BAZAAR_INSTANT_BUY,
pastRecipes: List<NeuRecipe> = emptyList(),
- ): Double? {
- when (this) {
- NEUInternalName.JASPER_CRYSTAL -> return 0.0
- NEUInternalName.RUBY_CRYSTAL -> return 0.0
- NEUInternalName.SKYBLOCK_COIN -> return 1.0
- NEUInternalName.WISP_POTION -> return 20_000.0
- }
-
- if (priceSource != ItemPriceSource.NPC_SELL) {
- getBazaarData()?.let {
- return if (priceSource == ItemPriceSource.BAZAAR_INSTANT_BUY) it.sellOfferPrice else it.instantBuyPrice
- }
-
- getLowestBinOrNull()?.let {
- return it
- }
-
- if (equals("JACK_O_LANTERN")) {
- return "PUMPKIN".asInternalName().getPrice(priceSource) + 1
- }
- }
- if (equals("GOLDEN_CARROT")) {
- // 6.8 for some players
- return 7.0 // NPC price
- }
-
- return getNpcPriceOrNull() ?: getRawCraftCostOrNull(pastRecipes)
- }
-
- fun NEUInternalName.getLowestBinOrNull(): Double? {
- val result = manager.auctionManager.getLowestBin(asString())
- if (result == -1L) return null
- return result.toDouble()
- }
+ ): Double? = this.getPriceOrNullNew(priceSource, pastRecipes)
- // If NEU fails to calculate the craft costs, we calculate it ourself.
- 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) }
- .filter { it >= 0 }
- .minOrNull()
- }
+ @Deprecated("Moved to ItemPriceUtils", ReplaceWith(""))
+ fun NEUInternalName.getRawCraftCostOrNull(pastRecipes: List<NeuRecipe> = emptyList()): Double? = getRawCraftCostOrNullNew(pastRecipes)
fun NEUInternalName.getItemStackOrNull(): ItemStack? = ItemResolutionQuery(manager)
.withKnownInternalName(asString())
@@ -232,7 +195,7 @@ object NEUItems {
fun NEUInternalName.getItemStack(): ItemStack =
getItemStackOrNull() ?: run {
- getPriceOrNull() ?: return@run fallbackItem
+ getPriceOrNullNew() ?: return@run fallbackItem
if (ignoreItemsFilter.match(this.asString())) return@run fallbackItem
ErrorManager.logErrorWithData(
IllegalStateException("Something went wrong!"),