From 3cd70b1b1e262af80f48cc56c56b666d9c30a565 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Fri, 9 May 2025 21:45:06 +0200 Subject: refactor: essence upgrade recipe as item list agnostic --- .../nea/firmament/compat/rei/FirmamentReiPlugin.kt | 16 ++---- .../rei/SkyblockCraftingRecipeDynamicGenerator.kt | 5 -- .../compat/rei/recipes/GenericREIRecipe.kt | 60 ------------------- .../compat/rei/recipes/GenericREIRecipeCategory.kt | 67 ++++++++++++++++++++++ .../compat/rei/recipes/SBEssenceUpgradeRecipe.kt | 62 -------------------- 5 files changed, 73 insertions(+), 137 deletions(-) delete mode 100644 src/compat/rei/java/moe/nea/firmament/compat/rei/recipes/GenericREIRecipe.kt create mode 100644 src/compat/rei/java/moe/nea/firmament/compat/rei/recipes/GenericREIRecipeCategory.kt delete mode 100644 src/compat/rei/java/moe/nea/firmament/compat/rei/recipes/SBEssenceUpgradeRecipe.kt (limited to 'src/compat/rei/java') diff --git a/src/compat/rei/java/moe/nea/firmament/compat/rei/FirmamentReiPlugin.kt b/src/compat/rei/java/moe/nea/firmament/compat/rei/FirmamentReiPlugin.kt index a3c3730..b5c9a6d 100644 --- a/src/compat/rei/java/moe/nea/firmament/compat/rei/FirmamentReiPlugin.kt +++ b/src/compat/rei/java/moe/nea/firmament/compat/rei/FirmamentReiPlugin.kt @@ -20,8 +20,7 @@ import net.minecraft.item.ItemStack import net.minecraft.text.Text import net.minecraft.util.ActionResult import net.minecraft.util.Identifier -import moe.nea.firmament.compat.rei.recipes.GenericREIRecipe -import moe.nea.firmament.compat.rei.recipes.SBEssenceUpgradeRecipe +import moe.nea.firmament.compat.rei.recipes.GenericREIRecipeCategory import moe.nea.firmament.compat.rei.recipes.SBKatRecipe import moe.nea.firmament.compat.rei.recipes.SBMobDropRecipe import moe.nea.firmament.compat.rei.recipes.SBRecipe @@ -33,6 +32,7 @@ import moe.nea.firmament.features.inventory.storageoverlay.StorageOverlayScreen import moe.nea.firmament.repo.RepoManager import moe.nea.firmament.repo.SBItemStack import moe.nea.firmament.repo.recipes.SBCraftingRecipeRenderer +import moe.nea.firmament.repo.recipes.SBEssenceUpgradeRecipeRenderer import moe.nea.firmament.repo.recipes.SBForgeRecipeRenderer import moe.nea.firmament.util.MC import moe.nea.firmament.util.SkyblockId @@ -82,9 +82,10 @@ class FirmamentReiPlugin : REIClientPlugin { } - val generics = listOf>( // Order matters: The order in here is the order in which they show up in REI - GenericREIRecipe(SBCraftingRecipeRenderer), - GenericREIRecipe(SBForgeRecipeRenderer), + val generics = listOf>( // Order matters: The order in here is the order in which they show up in REI + GenericREIRecipeCategory(SBCraftingRecipeRenderer), + GenericREIRecipeCategory(SBForgeRecipeRenderer), + GenericREIRecipeCategory(SBEssenceUpgradeRecipeRenderer), ) override fun registerCategories(registry: CategoryRegistry) { @@ -92,7 +93,6 @@ class FirmamentReiPlugin : REIClientPlugin { registry.add(SBMobDropRecipe.Category) registry.add(SBKatRecipe.Category) registry.add(SBReforgeRecipe.Category) - registry.add(SBEssenceUpgradeRecipe.Category) registry.add(SBShopRecipe.Category) } @@ -118,10 +118,6 @@ class FirmamentReiPlugin : REIClientPlugin { registry.registerDisplayGenerator( SBKatRecipe.Category.categoryIdentifier, SkyblockKatRecipeDynamicGenerator) - registry.registerDisplayGenerator( - SBEssenceUpgradeRecipe.Category.categoryIdentifier, - SkyblockEssenceRecipeDynamicGenerator - ) } override fun registerCollapsibleEntries(registry: CollapsibleEntryRegistry) { 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 eded5e6..900ebab 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 @@ -10,7 +10,6 @@ import me.shedaniel.rei.api.client.registry.display.DynamicDisplayGenerator import me.shedaniel.rei.api.client.view.ViewSearchBuilder import me.shedaniel.rei.api.common.display.Display import me.shedaniel.rei.api.common.entry.EntryStack -import moe.nea.firmament.compat.rei.recipes.SBEssenceUpgradeRecipe import moe.nea.firmament.compat.rei.recipes.SBKatRecipe import moe.nea.firmament.compat.rei.recipes.SBMobDropRecipe import moe.nea.firmament.compat.rei.recipes.SBShopRecipe @@ -25,10 +24,6 @@ val SkyblockShopRecipeDynamicGenerator = neuDisplayGenerator { SBShopRecipe(it) } val SkyblockKatRecipeDynamicGenerator = neuDisplayGenerator { SBKatRecipe(it) } -val SkyblockEssenceRecipeDynamicGenerator = - neuDisplayGeneratorWithItem { item, recipe -> - SBEssenceUpgradeRecipe(recipe, item) - } inline fun neuDisplayGenerator(crossinline mapper: (T) -> D) = neuDisplayGeneratorWithItem { _, it -> mapper(it) } diff --git a/src/compat/rei/java/moe/nea/firmament/compat/rei/recipes/GenericREIRecipe.kt b/src/compat/rei/java/moe/nea/firmament/compat/rei/recipes/GenericREIRecipe.kt deleted file mode 100644 index 630ac0e..0000000 --- a/src/compat/rei/java/moe/nea/firmament/compat/rei/recipes/GenericREIRecipe.kt +++ /dev/null @@ -1,60 +0,0 @@ -package moe.nea.firmament.compat.rei.recipes - -import io.github.moulberry.repo.data.NEUCraftingRecipe -import io.github.moulberry.repo.data.NEURecipe -import me.shedaniel.math.Rectangle -import me.shedaniel.rei.api.client.gui.Renderer -import me.shedaniel.rei.api.client.gui.widgets.Widget -import me.shedaniel.rei.api.client.gui.widgets.Widgets -import me.shedaniel.rei.api.client.registry.display.DisplayCategory -import me.shedaniel.rei.api.client.registry.display.DisplayRegistry -import me.shedaniel.rei.api.common.category.CategoryIdentifier -import me.shedaniel.rei.api.common.util.EntryStacks -import net.minecraft.text.Text -import moe.nea.firmament.compat.rei.REIRecipeLayouter -import moe.nea.firmament.compat.rei.neuDisplayGeneratorWithItem -import moe.nea.firmament.repo.recipes.GenericRecipeRenderer - -class GenericREIRecipe( - val renderer: GenericRecipeRenderer, -) : DisplayCategory> { - private val dynamicGenerator = - neuDisplayGeneratorWithItem, T>(renderer.typ) { _, it -> GenericRecipe(it, categoryIdentifier) } - - private val categoryIdentifier = CategoryIdentifier.of>(renderer.identifier) - override fun getCategoryIdentifier(): CategoryIdentifier> { - return categoryIdentifier - } - - override fun getDisplayHeight(): Int { - return renderer.displayHeight - } - - override fun getTitle(): Text? { - return renderer.title - } - - override fun getIcon(): Renderer? { - return EntryStacks.of(renderer.icon) - } - - override fun setupDisplay(display: GenericRecipe, bounds: Rectangle): List { - val layouter = REIRecipeLayouter() - layouter.container.add(Widgets.createRecipeBase(bounds)) - renderer.render(display.neuRecipe, bounds, layouter) - return layouter.container - } - - fun registerDynamicGenerator(registry: DisplayRegistry) { - registry.registerDisplayGenerator(categoryIdentifier, dynamicGenerator) - } -} - -class GenericRecipe( - override val neuRecipe: T, - val id: CategoryIdentifier> -) : SBRecipe() { - override fun getCategoryIdentifier(): CategoryIdentifier<*>? { - return id - } -} diff --git a/src/compat/rei/java/moe/nea/firmament/compat/rei/recipes/GenericREIRecipeCategory.kt b/src/compat/rei/java/moe/nea/firmament/compat/rei/recipes/GenericREIRecipeCategory.kt new file mode 100644 index 0000000..15cb818 --- /dev/null +++ b/src/compat/rei/java/moe/nea/firmament/compat/rei/recipes/GenericREIRecipeCategory.kt @@ -0,0 +1,67 @@ +package moe.nea.firmament.compat.rei.recipes + +import io.github.moulberry.repo.data.NEURecipe +import me.shedaniel.math.Rectangle +import me.shedaniel.rei.api.client.gui.Renderer +import me.shedaniel.rei.api.client.gui.widgets.Widget +import me.shedaniel.rei.api.client.gui.widgets.Widgets +import me.shedaniel.rei.api.client.registry.display.DisplayCategory +import me.shedaniel.rei.api.client.registry.display.DisplayRegistry +import me.shedaniel.rei.api.common.category.CategoryIdentifier +import me.shedaniel.rei.api.common.util.EntryStacks +import net.minecraft.text.Text +import moe.nea.firmament.compat.rei.REIRecipeLayouter +import moe.nea.firmament.compat.rei.neuDisplayGeneratorWithItem +import moe.nea.firmament.repo.SBItemStack +import moe.nea.firmament.repo.recipes.GenericRecipeRenderer + +class GenericREIRecipeCategory( + val renderer: GenericRecipeRenderer, +) : DisplayCategory> { + private val dynamicGenerator = + neuDisplayGeneratorWithItem, T>(renderer.typ) { item, recipe -> + GenericRecipe( + recipe, + item, + categoryIdentifier + ) + } + + private val categoryIdentifier = CategoryIdentifier.of>(renderer.identifier) + override fun getCategoryIdentifier(): CategoryIdentifier> { + return categoryIdentifier + } + + override fun getDisplayHeight(): Int { + return renderer.displayHeight + } + + override fun getTitle(): Text? { + return renderer.title + } + + override fun getIcon(): Renderer? { + return EntryStacks.of(renderer.icon) + } + + override fun setupDisplay(display: GenericRecipe, bounds: Rectangle): List { + val layouter = REIRecipeLayouter() + layouter.container.add(Widgets.createRecipeBase(bounds)) + renderer.render(display.neuRecipe, bounds, layouter, display.sourceItem) + return layouter.container + } + + fun registerDynamicGenerator(registry: DisplayRegistry) { + registry.registerDisplayGenerator(categoryIdentifier, dynamicGenerator) + } +} + +class GenericRecipe( + override val neuRecipe: T, + val sourceItem: SBItemStack?, + val id: CategoryIdentifier> +) : SBRecipe() { + override fun getCategoryIdentifier(): CategoryIdentifier<*>? { + return id + } +} 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 deleted file mode 100644 index e0a3784..0000000 --- a/src/compat/rei/java/moe/nea/firmament/compat/rei/recipes/SBEssenceUpgradeRecipe.kt +++ /dev/null @@ -1,62 +0,0 @@ -package moe.nea.firmament.compat.rei.recipes - -import me.shedaniel.math.Point -import me.shedaniel.math.Rectangle -import me.shedaniel.rei.api.client.gui.Renderer -import me.shedaniel.rei.api.client.gui.widgets.Widget -import me.shedaniel.rei.api.client.gui.widgets.Widgets -import me.shedaniel.rei.api.client.registry.display.DisplayCategory -import me.shedaniel.rei.api.common.category.CategoryIdentifier -import net.minecraft.text.Text -import moe.nea.firmament.Firmament -import moe.nea.firmament.compat.rei.SBItemEntryDefinition -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, - val sourceItem: SBItemStack) : SBRecipe() { - object Category : DisplayCategory { - override fun getCategoryIdentifier(): CategoryIdentifier = - CategoryIdentifier.of(Firmament.MOD_ID, "essence_upgrade") - - override fun getTitle(): Text { - return Text.literal("Essence Upgrades") - } - - override fun getIcon(): Renderer { - return SBItemEntryDefinition.getEntry(SkyblockId("ESSENCE_WITHER")) - } - - override fun setupDisplay(display: SBEssenceUpgradeRecipe, bounds: Rectangle): List { - val recipe = display.neuRecipe - val list = mutableListOf() - list.add(Widgets.createRecipeBase(bounds)) - list.add(Widgets.createSlot(Point(bounds.minX + 12, bounds.centerY - 8 - 18 / 2)) - .markInput() - .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(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 - else bounds.centerY + 18 / 2))) - for ((index, item) in extraItems.withIndex()) { - list.add(Widgets.createSlot( - Point(bounds.centerX - extraItems.size * 16 / 2 - 2 / 2 + index * 18, - bounds.centerY - 18 / 2)) - .markInput() - .entry(SBItemEntryDefinition.getEntry(item))) - } - return list - } - } - - override fun getCategoryIdentifier(): CategoryIdentifier<*> { - return Category.categoryIdentifier - } -} -- cgit