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.kt7
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt10
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt25
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/PrimitiveIngredient.kt26
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/PrimitiveRecipe.kt53
5 files changed, 96 insertions, 25 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt
index b12f3640e..66775b2d6 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt
@@ -9,18 +9,17 @@ import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull
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(),
+ pastRecipes: List<PrimitiveRecipe> = emptyList(),
) = getPriceOrNull(priceSource, pastRecipes) ?: 0.0
fun NEUInternalName.getPriceOrNull(
priceSource: ItemPriceSource = ItemPriceSource.BAZAAR_INSTANT_BUY,
- pastRecipes: List<NeuRecipe> = emptyList(),
+ pastRecipes: List<PrimitiveRecipe> = emptyList(),
): Double? {
when (this) {
NEUInternalName.JASPER_CRYSTAL -> return 0.0
@@ -60,7 +59,7 @@ object ItemPriceUtils {
// NEUItems.manager.auctionManager.getCraftCost(asString())?.craftCost
fun NEUInternalName.getRawCraftCostOrNull(
priceSource: ItemPriceSource = ItemPriceSource.BAZAAR_INSTANT_BUY,
- pastRecipes: List<NeuRecipe> = emptyList(),
+ pastRecipes: List<PrimitiveRecipe> = emptyList(),
): Double? = getRecipes(this).filter { it !in pastRecipes }
.map { it.getRecipePrice(priceSource, pastRecipes + it) }
.filter { it >= 0 }
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
index cc1a4362b..ac35c0741 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
@@ -7,7 +7,6 @@ import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut
import at.hannibal2.skyhanni.utils.ItemPriceUtils.getPrice
-import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull
import at.hannibal2.skyhanni.utils.NumberUtil.formatInt
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
@@ -20,7 +19,6 @@ import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.StringUtils.removeResets
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import com.google.common.collect.Lists
-import io.github.moulberry.notenoughupdates.recipes.NeuRecipe
import io.github.moulberry.notenoughupdates.util.NotificationHandler
import net.minecraft.client.Minecraft
import net.minecraft.init.Items
@@ -463,19 +461,19 @@ object ItemUtils {
return list
}
- fun neededItems(recipe: NeuRecipe): Map<NEUInternalName, Int> {
+ fun neededItems(recipe: PrimitiveRecipe): Map<NEUInternalName, Int> {
val neededItems = mutableMapOf<NEUInternalName, Int>()
for (ingredient in recipe.ingredients) {
- val material = ingredient.internalItemId.asInternalName()
+ val material = ingredient.internalName
val amount = ingredient.count.toInt()
neededItems.addOrPut(material, amount)
}
return neededItems
}
- fun NeuRecipe.getRecipePrice(
+ fun PrimitiveRecipe.getRecipePrice(
priceSource: ItemPriceSource = ItemPriceSource.BAZAAR_INSTANT_BUY,
- pastRecipes: List<NeuRecipe> = emptyList(),
+ pastRecipes: List<PrimitiveRecipe> = emptyList(),
): Double = neededItems(this).map {
it.key.getPrice(priceSource, 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 81eb2968c..34d491cee 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
@@ -30,9 +30,6 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates
import io.github.moulberry.notenoughupdates.events.ProfileDataLoadedEvent
import io.github.moulberry.notenoughupdates.overlays.AuctionSearchOverlay
import io.github.moulberry.notenoughupdates.overlays.BazaarSearchOverlay
-import io.github.moulberry.notenoughupdates.recipes.CraftingRecipe
-import io.github.moulberry.notenoughupdates.recipes.Ingredient
-import io.github.moulberry.notenoughupdates.recipes.NeuRecipe
import io.github.moulberry.notenoughupdates.util.ItemResolutionQuery
import io.github.moulberry.notenoughupdates.util.Utils
import net.minecraft.client.Minecraft
@@ -57,8 +54,8 @@ object NEUItems {
val manager: NEUManager get() = NotEnoughUpdates.INSTANCE.manager
private val multiplierCache = mutableMapOf<NEUInternalName, PrimitiveItemStack>()
- private val recipesCache = mutableMapOf<NEUInternalName, Set<NeuRecipe>>()
- private val ingredientsCache = mutableMapOf<NeuRecipe, Set<Ingredient>>()
+ private val recipesCache = mutableMapOf<NEUInternalName, Set<PrimitiveRecipe>>()
+ private val ingredientsCache = mutableMapOf<PrimitiveRecipe, Set<PrimitiveIngredient>>()
private val itemIdCache = mutableMapOf<Item, List<NEUInternalName>>()
private val hypixelApiGson by lazy {
@@ -183,7 +180,7 @@ object NEUItems {
@Deprecated("Moved to ItemPriceUtils", ReplaceWith(""))
fun NEUInternalName.getPrice(
priceSource: ItemPriceSource = ItemPriceSource.BAZAAR_INSTANT_BUY,
- pastRecipes: List<NeuRecipe> = emptyList(),
+ pastRecipes: List<PrimitiveRecipe> = emptyList(),
): Double = getPriceNew(priceSource, pastRecipes)
@Deprecated("Moved to ItemPriceUtils", ReplaceWith(""))
@@ -198,11 +195,11 @@ object NEUItems {
@Deprecated("Moved to ItemPriceUtils", ReplaceWith(""))
fun NEUInternalName.getPriceOrNull(
priceSource: ItemPriceSource = ItemPriceSource.BAZAAR_INSTANT_BUY,
- pastRecipes: List<NeuRecipe> = emptyList(),
+ pastRecipes: List<PrimitiveRecipe> = emptyList(),
): Double? = this.getPriceOrNullNew(priceSource, pastRecipes)
@Deprecated("Moved to ItemPriceUtils", ReplaceWith(""))
- fun NEUInternalName.getRawCraftCostOrNull(pastRecipes: List<NeuRecipe> = emptyList()): Double? =
+ fun NEUInternalName.getRawCraftCostOrNull(pastRecipes: List<PrimitiveRecipe> = emptyList()): Double? =
getRawCraftCostOrNullNew(ItemPriceSource.BAZAAR_INSTANT_BUY, pastRecipes)
fun NEUInternalName.getItemStackOrNull(): ItemStack? = ItemResolutionQuery(manager)
@@ -309,12 +306,12 @@ object NEUItems {
return internalName.makePrimitiveStack()
}
for (recipe in getRecipes(internalName)) {
- if (recipe !is CraftingRecipe) continue
+ if (!recipe.isCraftingRecipe()) continue
val map = mutableMapOf<NEUInternalName, Int>()
for (ingredient in recipe.getCachedIngredients()) {
val count = ingredient.count.toInt()
- var internalItemId = ingredient.internalItemId.asInternalName()
+ var internalItemId = ingredient.internalName
// ignore cactus green
if (internalName == "ENCHANTED_CACTUS_GREEN".asInternalName() && internalItemId == "INK_SACK-2".asInternalName()) {
internalItemId = "CACTUS".asInternalName()
@@ -356,13 +353,13 @@ object NEUItems {
return result
}
- fun getRecipes(internalName: NEUInternalName): Set<NeuRecipe> {
+ fun getRecipes(internalName: NEUInternalName): Set<PrimitiveRecipe> {
return recipesCache.getOrPut(internalName) {
- manager.getRecipesFor(internalName.asString())
+ PrimitiveRecipe.convertMultiple(manager.getRecipesFor(internalName.asString())).toSet()
}
}
- fun NeuRecipe.getCachedIngredients() = ingredientsCache.getOrPut(this) { allIngredients() }
+ fun PrimitiveRecipe.getCachedIngredients() = ingredientsCache.getOrPut(this) { ingredients }
fun neuHasFocus(): Boolean {
if (AuctionSearchOverlay.shouldReplace()) return true
@@ -391,6 +388,4 @@ object NEUItems {
val jsonObject = ConfigManager.gson.fromJson(jsonString, JsonObject::class.java)
return manager.jsonToStack(jsonObject, false)
}
-
- fun NeuRecipe.allIngredients(): Set<Ingredient> = ingredients
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/PrimitiveIngredient.kt b/src/main/java/at/hannibal2/skyhanni/utils/PrimitiveIngredient.kt
new file mode 100644
index 000000000..e8d1edefc
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/utils/PrimitiveIngredient.kt
@@ -0,0 +1,26 @@
+package at.hannibal2.skyhanni.utils
+
+import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.SKYBLOCK_COIN
+import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
+import io.github.moulberry.notenoughupdates.recipes.Ingredient
+
+class PrimitiveIngredient(val internalName: NEUInternalName, val count: Double = 1.0) {
+
+ constructor(internalName: NEUInternalName, count: Int) : this(internalName, count.toDouble())
+
+ constructor(ingredientIdentifier: String) : this(
+ ingredientIdentifier.substringBefore(':').asInternalName(),
+ ingredientIdentifier.substringAfter(':').toDoubleOrNull() ?: 1.0,
+ )
+
+ companion object {
+ fun coinIngredient(count: Double = 1.0) = PrimitiveIngredient(SKYBLOCK_COIN, count)
+
+ fun fromNeuIngredient(neuIngredient: Ingredient) = PrimitiveIngredient(neuIngredient.internalItemId.asInternalName(), neuIngredient.count)
+ }
+
+ fun isCoin() = internalName == SKYBLOCK_COIN
+
+
+ override fun toString() = "$internalName x$count"
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/PrimitiveRecipe.kt b/src/main/java/at/hannibal2/skyhanni/utils/PrimitiveRecipe.kt
new file mode 100644
index 000000000..f064183ba
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/utils/PrimitiveRecipe.kt
@@ -0,0 +1,53 @@
+package at.hannibal2.skyhanni.utils
+
+import at.hannibal2.skyhanni.utils.RecipeType.CRAFTING
+import io.github.moulberry.notenoughupdates.recipes.EssenceUpgrades
+import io.github.moulberry.notenoughupdates.recipes.ForgeRecipe
+import io.github.moulberry.notenoughupdates.recipes.ItemShopRecipe
+import io.github.moulberry.notenoughupdates.recipes.KatRecipe
+import io.github.moulberry.notenoughupdates.recipes.MobLootRecipe
+import io.github.moulberry.notenoughupdates.recipes.NeuRecipe
+import io.github.moulberry.notenoughupdates.recipes.VillagerTradeRecipe
+
+data class PrimitiveRecipe(
+ val ingredients: Set<PrimitiveIngredient>,
+ val outputs: Set<PrimitiveIngredient>,
+ val recipeType: RecipeType,
+) {
+
+ val output by lazy { outputs.firstOrNull() }
+
+ companion object {
+ fun fromNeuRecipe(neuRecipe: NeuRecipe): PrimitiveRecipe {
+ val ingredients = neuRecipe.ingredients.map { PrimitiveIngredient.fromNeuIngredient(it) }.toSet()
+ val outputs = neuRecipe.outputs.map { PrimitiveIngredient.fromNeuIngredient(it) }.toSet()
+
+ val recipeType = when (neuRecipe::class.java) {
+ ForgeRecipe::class.java -> RecipeType.FORGE
+ VillagerTradeRecipe::class.java -> RecipeType.TRADE
+ EssenceUpgrades::class.java -> RecipeType.ESSENCE
+ MobLootRecipe::class.java -> RecipeType.MOB_DROP
+ ItemShopRecipe::class.java -> RecipeType.NPC_SHOP
+ KatRecipe::class.java -> RecipeType.KAT_UPGRADE
+ else -> CRAFTING
+ }
+
+ return PrimitiveRecipe(ingredients, outputs, recipeType)
+ }
+
+ fun convertMultiple(neuRecipes: Collection<NeuRecipe>) = neuRecipes.map { fromNeuRecipe(it) }
+ }
+
+ fun isCraftingRecipe() = this.recipeType == CRAFTING
+}
+
+enum class RecipeType {
+ FORGE,
+ TRADE,
+ MOB_DROP,
+ NPC_SHOP,
+ KAT_UPGRADE,
+ ESSENCE,
+ CRAFTING,
+ ;
+}