aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2024-09-23 15:48:19 +1000
committerGitHub <noreply@github.com>2024-09-23 07:48:19 +0200
commitb0735ffc3ed655838de6d0d0eb6376cde92483d1 (patch)
treeb98308044ce17e6df360bfc4058756fed4594b64 /src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
parent8f7b79a0b4953bb64f342ccc21d962c8aacbc169 (diff)
downloadskyhanni-b0735ffc3ed655838de6d0d0eb6376cde92483d1.tar.gz
skyhanni-b0735ffc3ed655838de6d0d0eb6376cde92483d1.tar.bz2
skyhanni-b0735ffc3ed655838de6d0d0eb6376cde92483d1.zip
Backend: Create and use primitive recipe and ingredient (#2460)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt25
1 files changed, 10 insertions, 15 deletions
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
}