From 5f0b9a40500dffb9da6c6244a704656e61e20798 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Fri, 17 Jan 2025 19:31:38 +0100 Subject: feat: Keep reforge stats in essence upgrade recipes --- .../rei/SkyblockCraftingRecipeDynamicGenerator.kt | 64 +++++++++++----------- .../compat/rei/recipes/SBEssenceUpgradeRecipe.kt | 7 ++- 2 files changed, 35 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/compat/rei/java/moe/nea/firmament/compat/rei/SkyblockCraftingRecipeDynamicGenerator.kt b/src/compat/rei/java/moe/nea/firmament/compat/rei/SkyblockCraftingRecipeDynamicGenerator.kt index f52f418..72bd28c 100644 --- a/src/compat/rei/java/moe/nea/firmament/compat/rei/SkyblockCraftingRecipeDynamicGenerator.kt +++ b/src/compat/rei/java/moe/nea/firmament/compat/rei/SkyblockCraftingRecipeDynamicGenerator.kt @@ -1,5 +1,3 @@ - - package moe.nea.firmament.compat.rei import io.github.moulberry.repo.data.NEUCraftingRecipe @@ -23,43 +21,43 @@ import moe.nea.firmament.repo.SBItemStack val SkyblockCraftingRecipeDynamicGenerator = - neuDisplayGenerator { SBCraftingRecipe(it) } + neuDisplayGenerator { SBCraftingRecipe(it) } val SkyblockForgeRecipeDynamicGenerator = - neuDisplayGenerator { SBForgeRecipe(it) } + neuDisplayGenerator { SBForgeRecipe(it) } val SkyblockMobDropRecipeDynamicGenerator = - neuDisplayGenerator { SBMobDropRecipe(it) } + neuDisplayGenerator { SBMobDropRecipe(it) } val SkyblockKatRecipeDynamicGenerator = - neuDisplayGenerator { SBKatRecipe(it) } + neuDisplayGenerator { SBKatRecipe(it) } val SkyblockEssenceRecipeDynamicGenerator = - neuDisplayGenerator { SBEssenceUpgradeRecipe(it) } + neuDisplayGeneratorWithItem { item, recipe -> + SBEssenceUpgradeRecipe(recipe, item) + } inline fun neuDisplayGenerator(crossinline mapper: (T) -> D) = - object : DynamicDisplayGenerator { - override fun getRecipeFor(entry: EntryStack<*>): Optional> { - if (entry.type != SBItemEntryDefinition.type) return Optional.empty() - val item = entry.castValue() - val recipes = RepoManager.getRecipesFor(item.skyblockId) - val craftingRecipes = recipes.filterIsInstance() - return Optional.of(craftingRecipes.map(mapper)) - } - - override fun generate(builder: ViewSearchBuilder): Optional> { - if (SBCraftingRecipe.Category.catIdentifier !in builder.categories) return Optional.empty() - return Optional.of( - RepoManager.getAllRecipes().filterIsInstance().map { mapper(it) } - .toList() - ) - } - - override fun getUsageFor(entry: EntryStack<*>): Optional> { - if (entry.type != SBItemEntryDefinition.type) return Optional.empty() - val item = entry.castValue() - val recipes = RepoManager.getUsagesFor(item.skyblockId) - val craftingRecipes = recipes.filterIsInstance() - return Optional.of(craftingRecipes.map(mapper)) - - } - } + neuDisplayGeneratorWithItem { _, it -> mapper(it) } + +inline fun neuDisplayGeneratorWithItem(crossinline mapper: (SBItemStack, T) -> D) = + object : DynamicDisplayGenerator { + override fun getRecipeFor(entry: EntryStack<*>): Optional> { + if (entry.type != SBItemEntryDefinition.type) return Optional.empty() + val item = entry.castValue() + val recipes = RepoManager.getRecipesFor(item.skyblockId) + val craftingRecipes = recipes.filterIsInstance() + return Optional.of(craftingRecipes.map { mapper(item, it) }) + } + + override fun generate(builder: ViewSearchBuilder): Optional> { + return Optional.empty() // TODO: allows searching without blocking getRecipeFor + } + + override fun getUsageFor(entry: EntryStack<*>): Optional> { + if (entry.type != SBItemEntryDefinition.type) return Optional.empty() + val item = entry.castValue() + val recipes = RepoManager.getUsagesFor(item.skyblockId) + val craftingRecipes = recipes.filterIsInstance() + return Optional.of(craftingRecipes.map { mapper(item, it) }) + } + } diff --git a/src/compat/rei/java/moe/nea/firmament/compat/rei/recipes/SBEssenceUpgradeRecipe.kt b/src/compat/rei/java/moe/nea/firmament/compat/rei/recipes/SBEssenceUpgradeRecipe.kt index ec71ec8..e0a3784 100644 --- a/src/compat/rei/java/moe/nea/firmament/compat/rei/recipes/SBEssenceUpgradeRecipe.kt +++ b/src/compat/rei/java/moe/nea/firmament/compat/rei/recipes/SBEssenceUpgradeRecipe.kt @@ -14,7 +14,8 @@ import moe.nea.firmament.repo.EssenceRecipeProvider import moe.nea.firmament.repo.SBItemStack import moe.nea.firmament.util.SkyblockId -class SBEssenceUpgradeRecipe(override val neuRecipe: EssenceRecipeProvider.EssenceUpgradeRecipe) : SBRecipe() { +class SBEssenceUpgradeRecipe(override val neuRecipe: EssenceRecipeProvider.EssenceUpgradeRecipe, + val sourceItem: SBItemStack) : SBRecipe() { object Category : DisplayCategory { override fun getCategoryIdentifier(): CategoryIdentifier = CategoryIdentifier.of(Firmament.MOD_ID, "essence_upgrade") @@ -33,13 +34,13 @@ class SBEssenceUpgradeRecipe(override val neuRecipe: EssenceRecipeProvider.Essen list.add(Widgets.createRecipeBase(bounds)) list.add(Widgets.createSlot(Point(bounds.minX + 12, bounds.centerY - 8 - 18 / 2)) .markInput() - .entry(SBItemEntryDefinition.getEntry(SBItemStack(recipe.itemId).copy(stars = recipe.starCountAfter - 1)))) + .entry(SBItemEntryDefinition.getEntry(display.sourceItem.copy(stars = recipe.starCountAfter - 1)))) list.add(Widgets.createSlot(Point(bounds.minX + 12, bounds.centerY - 8 + 18 / 2)) .markInput() .entry(SBItemEntryDefinition.getEntry(recipe.essenceIngredient))) list.add(Widgets.createSlot(Point(bounds.maxX - 12 - 16, bounds.centerY - 8)) .markOutput() - .entry(SBItemEntryDefinition.getEntry(SBItemStack(recipe.itemId).copy(stars = recipe.starCountAfter)))) + .entry(SBItemEntryDefinition.getEntry(display.sourceItem.copy(stars = recipe.starCountAfter)))) val extraItems = recipe.extraItems list.add(Widgets.createArrow(Point(bounds.centerX - 24 / 2, if (extraItems.isEmpty()) bounds.centerY - 17 / 2 -- cgit