aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-08-11 13:59:52 +0200
committerGitHub <noreply@github.com>2024-08-11 13:59:52 +0200
commit091b939ea277d22da7fe46eba7d2834af71463e0 (patch)
tree48c694f5dc76fdf917a1b063bcb8f840e0b3eb45 /src/main
parent9b462cf711085dd0ac56131ded2e09ff2609bc45 (diff)
downloadskyhanni-091b939ea277d22da7fe46eba7d2834af71463e0.tar.gz
skyhanni-091b939ea277d22da7fe46eba7d2834af71463e0.tar.bz2
skyhanni-091b939ea277d22da7fe46eba7d2834af71463e0.zip
Backend: ItemPriceUtils (#2290)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/inventory/AnitaExtraFarmingFortune.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateShopPrice.kt15
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt68
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt69
7 files changed, 92 insertions, 68 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt
index 9012f0223..12bd69658 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt
@@ -19,10 +19,10 @@ import at.hannibal2.skyhanni.utils.ConfigUtils
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemCategory
import at.hannibal2.skyhanni.utils.ItemCategory.Companion.containsItem
+import at.hannibal2.skyhanni.utils.ItemPriceUtils.getNpcPriceOrNull
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
-import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull
import at.hannibal2.skyhanni.utils.NEUItems.getPriceOrNull
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt
index bea005d76..217da9735 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt
@@ -24,6 +24,7 @@ import at.hannibal2.skyhanni.utils.CollectionUtils.moveEntryToTop
import at.hannibal2.skyhanni.utils.CollectionUtils.sortedDesc
import at.hannibal2.skyhanni.utils.ConfigUtils
import at.hannibal2.skyhanni.utils.InventoryUtils
+import at.hannibal2.skyhanni.utils.ItemPriceUtils.getNpcPrice
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.itemNameWithoutColor
import at.hannibal2.skyhanni.utils.LorenzUtils
@@ -31,7 +32,6 @@ import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.NEUItems.getItemStack
-import at.hannibal2.skyhanni.utils.NEUItems.getNpcPrice
import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull
import at.hannibal2.skyhanni.utils.NEUItems.getPrice
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/AnitaExtraFarmingFortune.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/AnitaExtraFarmingFortune.kt
index afebbda4d..af4e4b31f 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/AnitaExtraFarmingFortune.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/AnitaExtraFarmingFortune.kt
@@ -9,8 +9,8 @@ import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.CollectionUtils.indexOfFirst
import at.hannibal2.skyhanni.utils.InventoryUtils
+import at.hannibal2.skyhanni.utils.ItemPriceUtils.getPrice
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
-import at.hannibal2.skyhanni.utils.NEUItems.getPrice
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.formatDouble
import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateShopPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateShopPrice.kt
index 957685d10..277532aaa 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateShopPrice.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateShopPrice.kt
@@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.DisplayTableEntry
+import at.hannibal2.skyhanni.utils.ItemPriceUtils.getPriceOrNull
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.itemName
@@ -14,7 +15,6 @@ import at.hannibal2.skyhanni.utils.ItemUtils.loreCosts
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getPrice
-import at.hannibal2.skyhanni.utils.NEUItems.getPriceOrNull
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.formatLong
import at.hannibal2.skyhanni.utils.NumberUtil.million
@@ -39,18 +39,19 @@ object ChocolateShopPrice {
private val menuNamePattern by ChocolateFactoryAPI.patternGroup.pattern(
"shop.title",
- "Chocolate Shop"
+ "Chocolate Shop",
)
private val itemBoughtPattern by ChocolateFactoryAPI.patternGroup.pattern(
"shop.bought",
- "§aYou bought §r§.(?<item>[\\w ]+)§r(?:§8 x(?<amount>\\d+)§r)?§a!"
+ "§aYou bought §r§.(?<item>[\\w ]+)§r(?:§8 x(?<amount>\\d+)§r)?§a!",
)
+
/**
* REGEX-TEST: §7Chocolate Spent: §60
*/
private val chocolateSpentPattern by ChocolateFactoryAPI.patternGroup.pattern(
"shop.spent",
- "§7Chocolate Spent: §6(?<amount>[\\d,]+)"
+ "§7Chocolate Spent: §6(?<amount>[\\d,]+)",
)
var inInventory = false
@@ -143,8 +144,8 @@ object ChocolateShopPrice {
factor,
product.item,
hover,
- highlightsOnHoverSlots = product.slot?.let { listOf(it) } ?: emptyList()
- )
+ highlightsOnHoverSlots = product.slot?.let { listOf(it) } ?: emptyList(),
+ ),
)
}
@@ -171,7 +172,7 @@ object ChocolateShopPrice {
config.position.renderRenderables(
display,
extraSpace = 5,
- posLabel = "Chocolate Shop Price"
+ posLabel = "Chocolate Shop Price",
)
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt
index 2a5092f27..3e31faef0 100644
--- a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt
+++ b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt
@@ -26,6 +26,7 @@ import at.hannibal2.skyhanni.utils.BlockUtils.getBlockStateAt
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.CollectionUtils.editCopy
import at.hannibal2.skyhanni.utils.InventoryUtils
+import at.hannibal2.skyhanni.utils.ItemPriceUtils.getRawCraftCostOrNull
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull
import at.hannibal2.skyhanni.utils.ItemUtils.getItemCategoryOrNull
@@ -46,7 +47,6 @@ import at.hannibal2.skyhanni.utils.NEUItems.getItemStack
import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull
import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull
import at.hannibal2.skyhanni.utils.NEUItems.getPriceOrNull
-import at.hannibal2.skyhanni.utils.NEUItems.getRawCraftCostOrNull
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.OSUtils
import at.hannibal2.skyhanni.utils.ReflectionUtils.makeAccessible
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!"),