refactor: essence upgrade recipe as item list agnostic

This commit is contained in:
Linnea Gräf
2025-05-09 21:45:06 +02:00
parent 62bca13bff
commit 3cd70b1b1e
8 changed files with 107 additions and 89 deletions

View File

@@ -20,8 +20,7 @@ import net.minecraft.item.ItemStack
import net.minecraft.text.Text import net.minecraft.text.Text
import net.minecraft.util.ActionResult import net.minecraft.util.ActionResult
import net.minecraft.util.Identifier import net.minecraft.util.Identifier
import moe.nea.firmament.compat.rei.recipes.GenericREIRecipe import moe.nea.firmament.compat.rei.recipes.GenericREIRecipeCategory
import moe.nea.firmament.compat.rei.recipes.SBEssenceUpgradeRecipe
import moe.nea.firmament.compat.rei.recipes.SBKatRecipe import moe.nea.firmament.compat.rei.recipes.SBKatRecipe
import moe.nea.firmament.compat.rei.recipes.SBMobDropRecipe import moe.nea.firmament.compat.rei.recipes.SBMobDropRecipe
import moe.nea.firmament.compat.rei.recipes.SBRecipe 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.RepoManager
import moe.nea.firmament.repo.SBItemStack import moe.nea.firmament.repo.SBItemStack
import moe.nea.firmament.repo.recipes.SBCraftingRecipeRenderer 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.repo.recipes.SBForgeRecipeRenderer
import moe.nea.firmament.util.MC import moe.nea.firmament.util.MC
import moe.nea.firmament.util.SkyblockId import moe.nea.firmament.util.SkyblockId
@@ -82,9 +82,10 @@ class FirmamentReiPlugin : REIClientPlugin {
} }
val generics = listOf<GenericREIRecipe<*>>( // Order matters: The order in here is the order in which they show up in REI val generics = listOf<GenericREIRecipeCategory<*>>( // Order matters: The order in here is the order in which they show up in REI
GenericREIRecipe(SBCraftingRecipeRenderer), GenericREIRecipeCategory(SBCraftingRecipeRenderer),
GenericREIRecipe(SBForgeRecipeRenderer), GenericREIRecipeCategory(SBForgeRecipeRenderer),
GenericREIRecipeCategory(SBEssenceUpgradeRecipeRenderer),
) )
override fun registerCategories(registry: CategoryRegistry) { override fun registerCategories(registry: CategoryRegistry) {
@@ -92,7 +93,6 @@ class FirmamentReiPlugin : REIClientPlugin {
registry.add(SBMobDropRecipe.Category) registry.add(SBMobDropRecipe.Category)
registry.add(SBKatRecipe.Category) registry.add(SBKatRecipe.Category)
registry.add(SBReforgeRecipe.Category) registry.add(SBReforgeRecipe.Category)
registry.add(SBEssenceUpgradeRecipe.Category)
registry.add(SBShopRecipe.Category) registry.add(SBShopRecipe.Category)
} }
@@ -118,10 +118,6 @@ class FirmamentReiPlugin : REIClientPlugin {
registry.registerDisplayGenerator( registry.registerDisplayGenerator(
SBKatRecipe.Category.categoryIdentifier, SBKatRecipe.Category.categoryIdentifier,
SkyblockKatRecipeDynamicGenerator) SkyblockKatRecipeDynamicGenerator)
registry.registerDisplayGenerator(
SBEssenceUpgradeRecipe.Category.categoryIdentifier,
SkyblockEssenceRecipeDynamicGenerator
)
} }
override fun registerCollapsibleEntries(registry: CollapsibleEntryRegistry) { override fun registerCollapsibleEntries(registry: CollapsibleEntryRegistry) {

View File

@@ -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.client.view.ViewSearchBuilder
import me.shedaniel.rei.api.common.display.Display import me.shedaniel.rei.api.common.display.Display
import me.shedaniel.rei.api.common.entry.EntryStack 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.SBKatRecipe
import moe.nea.firmament.compat.rei.recipes.SBMobDropRecipe import moe.nea.firmament.compat.rei.recipes.SBMobDropRecipe
import moe.nea.firmament.compat.rei.recipes.SBShopRecipe import moe.nea.firmament.compat.rei.recipes.SBShopRecipe
@@ -25,10 +24,6 @@ val SkyblockShopRecipeDynamicGenerator =
neuDisplayGenerator<SBShopRecipe, NEUNpcShopRecipe> { SBShopRecipe(it) } neuDisplayGenerator<SBShopRecipe, NEUNpcShopRecipe> { SBShopRecipe(it) }
val SkyblockKatRecipeDynamicGenerator = val SkyblockKatRecipeDynamicGenerator =
neuDisplayGenerator<SBKatRecipe, NEUKatUpgradeRecipe> { SBKatRecipe(it) } neuDisplayGenerator<SBKatRecipe, NEUKatUpgradeRecipe> { SBKatRecipe(it) }
val SkyblockEssenceRecipeDynamicGenerator =
neuDisplayGeneratorWithItem<SBEssenceUpgradeRecipe, EssenceRecipeProvider.EssenceUpgradeRecipe> { item, recipe ->
SBEssenceUpgradeRecipe(recipe, item)
}
inline fun <D : Display, reified T : NEURecipe> neuDisplayGenerator(crossinline mapper: (T) -> D) = inline fun <D : Display, reified T : NEURecipe> neuDisplayGenerator(crossinline mapper: (T) -> D) =
neuDisplayGeneratorWithItem<D, T> { _, it -> mapper(it) } neuDisplayGeneratorWithItem<D, T> { _, it -> mapper(it) }

View File

@@ -1,6 +1,5 @@
package moe.nea.firmament.compat.rei.recipes package moe.nea.firmament.compat.rei.recipes
import io.github.moulberry.repo.data.NEUCraftingRecipe
import io.github.moulberry.repo.data.NEURecipe import io.github.moulberry.repo.data.NEURecipe
import me.shedaniel.math.Rectangle import me.shedaniel.math.Rectangle
import me.shedaniel.rei.api.client.gui.Renderer import me.shedaniel.rei.api.client.gui.Renderer
@@ -13,13 +12,20 @@ import me.shedaniel.rei.api.common.util.EntryStacks
import net.minecraft.text.Text import net.minecraft.text.Text
import moe.nea.firmament.compat.rei.REIRecipeLayouter import moe.nea.firmament.compat.rei.REIRecipeLayouter
import moe.nea.firmament.compat.rei.neuDisplayGeneratorWithItem import moe.nea.firmament.compat.rei.neuDisplayGeneratorWithItem
import moe.nea.firmament.repo.SBItemStack
import moe.nea.firmament.repo.recipes.GenericRecipeRenderer import moe.nea.firmament.repo.recipes.GenericRecipeRenderer
class GenericREIRecipe<T : NEURecipe>( class GenericREIRecipeCategory<T : NEURecipe>(
val renderer: GenericRecipeRenderer<T>, val renderer: GenericRecipeRenderer<T>,
) : DisplayCategory<GenericRecipe<T>> { ) : DisplayCategory<GenericRecipe<T>> {
private val dynamicGenerator = private val dynamicGenerator =
neuDisplayGeneratorWithItem<GenericRecipe<T>, T>(renderer.typ) { _, it -> GenericRecipe(it, categoryIdentifier) } neuDisplayGeneratorWithItem<GenericRecipe<T>, T>(renderer.typ) { item, recipe ->
GenericRecipe(
recipe,
item,
categoryIdentifier
)
}
private val categoryIdentifier = CategoryIdentifier.of<GenericRecipe<T>>(renderer.identifier) private val categoryIdentifier = CategoryIdentifier.of<GenericRecipe<T>>(renderer.identifier)
override fun getCategoryIdentifier(): CategoryIdentifier<GenericRecipe<T>> { override fun getCategoryIdentifier(): CategoryIdentifier<GenericRecipe<T>> {
@@ -41,7 +47,7 @@ class GenericREIRecipe<T : NEURecipe>(
override fun setupDisplay(display: GenericRecipe<T>, bounds: Rectangle): List<Widget> { override fun setupDisplay(display: GenericRecipe<T>, bounds: Rectangle): List<Widget> {
val layouter = REIRecipeLayouter() val layouter = REIRecipeLayouter()
layouter.container.add(Widgets.createRecipeBase(bounds)) layouter.container.add(Widgets.createRecipeBase(bounds))
renderer.render(display.neuRecipe, bounds, layouter) renderer.render(display.neuRecipe, bounds, layouter, display.sourceItem)
return layouter.container return layouter.container
} }
@@ -52,6 +58,7 @@ class GenericREIRecipe<T : NEURecipe>(
class GenericRecipe<T : NEURecipe>( class GenericRecipe<T : NEURecipe>(
override val neuRecipe: T, override val neuRecipe: T,
val sourceItem: SBItemStack?,
val id: CategoryIdentifier<GenericRecipe<T>> val id: CategoryIdentifier<GenericRecipe<T>>
) : SBRecipe() { ) : SBRecipe() {
override fun getCategoryIdentifier(): CategoryIdentifier<*>? { override fun getCategoryIdentifier(): CategoryIdentifier<*>? {

View File

@@ -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<SBEssenceUpgradeRecipe> {
override fun getCategoryIdentifier(): CategoryIdentifier<SBEssenceUpgradeRecipe> =
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<Widget> {
val recipe = display.neuRecipe
val list = mutableListOf<Widget>()
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
}
}

View File

@@ -9,7 +9,7 @@ import net.minecraft.util.Identifier
import moe.nea.firmament.repo.SBItemStack import moe.nea.firmament.repo.SBItemStack
interface GenericRecipeRenderer<T : NEURecipe> { interface GenericRecipeRenderer<T : NEURecipe> {
fun render(recipe: T, bounds: Rectangle, layouter: RecipeLayouter) fun render(recipe: T, bounds: Rectangle, layouter: RecipeLayouter, mainItem: SBItemStack?)
fun getInputs(recipe: T): Collection<SBItemStack> fun getInputs(recipe: T): Collection<SBItemStack>
fun getOutputs(recipe: T): Collection<SBItemStack> fun getOutputs(recipe: T): Collection<SBItemStack>
val icon: ItemStack val icon: ItemStack

View File

@@ -13,16 +13,23 @@ import moe.nea.firmament.repo.SBItemStack
import moe.nea.firmament.util.tr import moe.nea.firmament.util.tr
object SBCraftingRecipeRenderer : GenericRecipeRenderer<NEUCraftingRecipe> { object SBCraftingRecipeRenderer : GenericRecipeRenderer<NEUCraftingRecipe> {
override fun render(recipe: NEUCraftingRecipe, bounds: Rectangle, layouter: RecipeLayouter) { override fun render(
recipe: NEUCraftingRecipe,
bounds: Rectangle,
layouter: RecipeLayouter,
mainItem: SBItemStack?,
) {
val point = Point(bounds.centerX - 58, bounds.centerY - 27) val point = Point(bounds.centerX - 58, bounds.centerY - 27)
layouter.createArrow(point.x + 60, point.y + 18) layouter.createArrow(point.x + 60, point.y + 18)
for (i in 0 until 3) { for (i in 0 until 3) {
for (j in 0 until 3) { for (j in 0 until 3) {
val item = recipe.inputs[i + j * 3] val item = recipe.inputs[i + j * 3]
layouter.createItemSlot(point.x + 1 + i * 18, layouter.createItemSlot(
point.y + 1 + j * 18, point.x + 1 + i * 18,
SBItemStack(item), point.y + 1 + j * 18,
RecipeLayouter.SlotKind.SMALL_INPUT) SBItemStack(item),
RecipeLayouter.SlotKind.SMALL_INPUT
)
} }
} }
layouter.createItemSlot( layouter.createItemSlot(
@@ -48,6 +55,6 @@ object SBCraftingRecipeRenderer : GenericRecipeRenderer<NEUCraftingRecipe> {
} }
override val icon: ItemStack = ItemStack(Blocks.CRAFTING_TABLE) override val icon: ItemStack = ItemStack(Blocks.CRAFTING_TABLE)
override val title: Text = tr("firmament.category.crafting", "SkyBlock Crafting") // TODO: fix tr not being included in jars override val title: Text = tr("firmament.category.crafting", "SkyBlock Crafting")
override val identifier: Identifier = Firmament.identifier("crafting_recipe") override val identifier: Identifier = Firmament.identifier("crafting_recipe")
} }

View File

@@ -0,0 +1,74 @@
package moe.nea.firmament.repo.recipes
import io.github.moulberry.repo.NEURepository
import io.github.moulberry.repo.data.NEUForgeRecipe
import me.shedaniel.math.Point
import me.shedaniel.math.Rectangle
import net.minecraft.item.ItemStack
import net.minecraft.text.Text
import net.minecraft.util.Identifier
import moe.nea.firmament.Firmament
import moe.nea.firmament.repo.EssenceRecipeProvider
import moe.nea.firmament.repo.RepoManager
import moe.nea.firmament.repo.SBItemStack
import moe.nea.firmament.util.SkyblockId
import moe.nea.firmament.util.tr
object SBEssenceUpgradeRecipeRenderer : GenericRecipeRenderer<EssenceRecipeProvider.EssenceUpgradeRecipe> {
override fun render(
recipe: EssenceRecipeProvider.EssenceUpgradeRecipe,
bounds: Rectangle,
layouter: RecipeLayouter,
mainItem: SBItemStack?
) {
val sourceItem = mainItem ?: SBItemStack(recipe.itemId)
layouter.createItemSlot(
bounds.minX + 12,
bounds.centerY - 8 - 18 / 2,
sourceItem.copy(stars = recipe.starCountAfter - 1),
RecipeLayouter.SlotKind.SMALL_INPUT
)
layouter.createItemSlot(
bounds.minX + 12, bounds.centerY - 8 + 18 / 2,
SBItemStack(recipe.essenceIngredient),
RecipeLayouter.SlotKind.SMALL_INPUT
)
layouter.createItemSlot(
bounds.maxX - 12 - 16, bounds.centerY - 8,
sourceItem.copy(stars = recipe.starCountAfter),
RecipeLayouter.SlotKind.SMALL_OUTPUT
)
val extraItems = recipe.extraItems
layouter.createArrow(
bounds.centerX - 24 / 2,
if (extraItems.isEmpty()) bounds.centerY - 17 / 2
else bounds.centerY + 18 / 2
)
for ((index, item) in extraItems.withIndex()) {
layouter.createItemSlot(
bounds.centerX - extraItems.size * 16 / 2 - 2 / 2 + index * 18,
bounds.centerY - 18 / 2,
SBItemStack(item),
RecipeLayouter.SlotKind.SMALL_INPUT,
)
}
}
override fun getInputs(recipe: EssenceRecipeProvider.EssenceUpgradeRecipe): Collection<SBItemStack> {
return recipe.allInputs.mapNotNull { SBItemStack(it) }
}
override fun getOutputs(recipe: EssenceRecipeProvider.EssenceUpgradeRecipe): Collection<SBItemStack> {
return listOfNotNull(SBItemStack(recipe.itemId))
}
override val icon: ItemStack get() = SBItemStack(SkyblockId("ESSENCE_WITHER")).asImmutableItemStack()
override val title: Text = tr("firmament.category.essence", "Essence Upgrades")
override val identifier: Identifier = Firmament.identifier("essence_upgrade")
override fun findAllRecipes(neuRepository: NEURepository): Iterable<EssenceRecipeProvider.EssenceUpgradeRecipe> {
return RepoManager.essenceRecipeProvider.recipes
}
override val typ: Class<EssenceRecipeProvider.EssenceUpgradeRecipe>
get() = EssenceRecipeProvider.EssenceUpgradeRecipe::class.java
}

View File

@@ -20,7 +20,8 @@ object SBForgeRecipeRenderer : GenericRecipeRenderer<NEUForgeRecipe> {
override fun render( override fun render(
recipe: NEUForgeRecipe, recipe: NEUForgeRecipe,
bounds: Rectangle, bounds: Rectangle,
layouter: RecipeLayouter layouter: RecipeLayouter,
mainItem: SBItemStack?,
) { ) {
val arrow = layouter.createArrow(bounds.minX + 90, bounds.minY + 54 - 18 / 2) val arrow = layouter.createArrow(bounds.minX + 90, bounds.minY + 54 - 18 / 2)
layouter.createTooltip( layouter.createTooltip(