From dc4866fe01abf7b33829bbfcd9d266c381c6c6af Mon Sep 17 00:00:00 2001 From: nea Date: Fri, 5 May 2023 00:02:13 +0200 Subject: Add very bad forge recipes --- .../notenoughupdates/recipes/SBCraftingRecipe.kt | 27 ++--------- .../nea/notenoughupdates/recipes/SBForgeRecipe.kt | 52 ++++++++++++++++++++++ .../moe/nea/notenoughupdates/recipes/SBRecipe.kt | 24 ++++++++++ .../moe/nea/notenoughupdates/rei/NEUReiPlugin.kt | 13 +++++- .../notenoughupdates/rei/SBItemEntryDefinition.kt | 15 +++++-- .../rei/SkyblockCraftingRecipeDynamicGenerator.kt | 52 ++++++++++++++++++++++ .../rei/SkyblockRecipeDynamicGenerator.kt | 38 ---------------- 7 files changed, 153 insertions(+), 68 deletions(-) create mode 100644 src/main/kotlin/moe/nea/notenoughupdates/recipes/SBForgeRecipe.kt create mode 100644 src/main/kotlin/moe/nea/notenoughupdates/recipes/SBRecipe.kt create mode 100644 src/main/kotlin/moe/nea/notenoughupdates/rei/SkyblockCraftingRecipeDynamicGenerator.kt delete mode 100644 src/main/kotlin/moe/nea/notenoughupdates/rei/SkyblockRecipeDynamicGenerator.kt (limited to 'src/main/kotlin/moe/nea/notenoughupdates') diff --git a/src/main/kotlin/moe/nea/notenoughupdates/recipes/SBCraftingRecipe.kt b/src/main/kotlin/moe/nea/notenoughupdates/recipes/SBCraftingRecipe.kt index 12bc1d3..9d7e9cc 100644 --- a/src/main/kotlin/moe/nea/notenoughupdates/recipes/SBCraftingRecipe.kt +++ b/src/main/kotlin/moe/nea/notenoughupdates/recipes/SBCraftingRecipe.kt @@ -2,7 +2,6 @@ package moe.nea.notenoughupdates.recipes import io.github.moulberry.repo.data.NEUCraftingRecipe import io.github.moulberry.repo.data.NEUIngredient -import io.github.moulberry.repo.data.NEURecipe import me.shedaniel.math.Point import me.shedaniel.math.Rectangle import me.shedaniel.rei.api.client.gui.Renderer @@ -10,31 +9,11 @@ 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 me.shedaniel.rei.api.common.display.Display -import me.shedaniel.rei.api.common.entry.EntryIngredient import me.shedaniel.rei.api.common.util.EntryStacks import net.minecraft.block.Blocks import net.minecraft.text.Text import moe.nea.notenoughupdates.NotEnoughUpdates import moe.nea.notenoughupdates.rei.SBItemEntryDefinition -import moe.nea.notenoughupdates.util.SkyblockId - -abstract class SBRecipe() : Display { - abstract val neuRecipe: NEURecipe - override fun getInputEntries(): List { - return neuRecipe.allInputs.map { - val entryStack = SBItemEntryDefinition.getEntry(SkyblockId(it.itemId)) - EntryIngredient.of(entryStack) - } - } - - override fun getOutputEntries(): List { - return neuRecipe.allOutputs.map { - val entryStack = SBItemEntryDefinition.getEntry(SkyblockId(it.itemId)) - EntryIngredient.of(entryStack) - } - } -} class SBCraftingRecipe(override val neuRecipe: NEUCraftingRecipe) : SBRecipe() { override fun getCategoryIdentifier(): CategoryIdentifier<*> = Category.catIdentifier @@ -57,13 +36,13 @@ class SBCraftingRecipe(override val neuRecipe: NEUCraftingRecipe) : SBRecipe() { val slot = Widgets.createSlot(Point(point.x + 1 + i * 18, point.y + 1 + j * 18)).markInput() add(slot) val item = display.neuRecipe.inputs[i + j * 3] - if (item == null || item == NEUIngredient.SENTINEL_EMPTY) continue - slot.entry(SBItemEntryDefinition.getEntry(SkyblockId(item.itemId))) // TODO: make use of stackable item entries + if (item == NEUIngredient.SENTINEL_EMPTY) continue + slot.entry(SBItemEntryDefinition.getEntry(item)) // TODO: make use of stackable item entries } } add( Widgets.createSlot(Point(point.x + 95, point.y + 19)) - .entry(SBItemEntryDefinition.getEntry(SkyblockId(display.neuRecipe.output.itemId))) + .entry(SBItemEntryDefinition.getEntry(display.neuRecipe.output)) .disableBackground().markOutput() ) } diff --git a/src/main/kotlin/moe/nea/notenoughupdates/recipes/SBForgeRecipe.kt b/src/main/kotlin/moe/nea/notenoughupdates/recipes/SBForgeRecipe.kt new file mode 100644 index 0000000..0a81214 --- /dev/null +++ b/src/main/kotlin/moe/nea/notenoughupdates/recipes/SBForgeRecipe.kt @@ -0,0 +1,52 @@ +package moe.nea.notenoughupdates.recipes + +import io.github.moulberry.repo.data.NEUForgeRecipe +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 me.shedaniel.rei.api.common.util.EntryStacks +import net.minecraft.block.Blocks +import net.minecraft.text.Text +import moe.nea.notenoughupdates.NotEnoughUpdates +import moe.nea.notenoughupdates.rei.SBItemEntryDefinition + +class SBForgeRecipe(override val neuRecipe: NEUForgeRecipe) : SBRecipe() { + override fun getCategoryIdentifier(): CategoryIdentifier<*> = Category.categoryIdentifier + + object Category : DisplayCategory { + override fun getCategoryIdentifier(): CategoryIdentifier = + CategoryIdentifier.of(NotEnoughUpdates.MOD_ID, "forge_recipe") + + override fun getTitle(): Text = Text.literal("Forge Recipes") + override fun getDisplayHeight(): Int { + return super.getDisplayHeight() + } + + override fun getIcon(): Renderer = EntryStacks.of(Blocks.ANVIL) + override fun setupDisplay(display: SBForgeRecipe, bounds: Rectangle): List { + return buildList { + add(Widgets.createRecipeBase(bounds)) + val resultSlot = Point(bounds.centerX - 18 / 2, bounds.centerY + 5) + add(Widgets.createResultSlotBackground(resultSlot)) + val ingredientsCenter = Point(bounds.centerX, bounds.centerY - 20) + val count = display.neuRecipe.inputs.size + display.neuRecipe.inputs.forEachIndexed { idx, ingredient -> + add( + Widgets.createSlot( + Point(ingredientsCenter.x - 18 / 2 - count / 2 * 24 + idx * 24, ingredientsCenter.y) + ).markInput().entry(SBItemEntryDefinition.getEntry(ingredient)) + ) + } + add( + Widgets.createSlot(resultSlot).markOutput().disableBackground() + .entry(SBItemEntryDefinition.getEntry(display.neuRecipe.outputStack)) + ) + } + } + } + +} diff --git a/src/main/kotlin/moe/nea/notenoughupdates/recipes/SBRecipe.kt b/src/main/kotlin/moe/nea/notenoughupdates/recipes/SBRecipe.kt new file mode 100644 index 0000000..2e39d7e --- /dev/null +++ b/src/main/kotlin/moe/nea/notenoughupdates/recipes/SBRecipe.kt @@ -0,0 +1,24 @@ +package moe.nea.notenoughupdates.recipes + +import io.github.moulberry.repo.data.NEURecipe +import me.shedaniel.rei.api.common.display.Display +import me.shedaniel.rei.api.common.entry.EntryIngredient +import moe.nea.notenoughupdates.rei.SBItemEntryDefinition +import moe.nea.notenoughupdates.util.SkyblockId + +abstract class SBRecipe() : Display { + abstract val neuRecipe: NEURecipe + override fun getInputEntries(): List { + return neuRecipe.allInputs.map { + val entryStack = SBItemEntryDefinition.getEntry(SkyblockId(it.itemId)) + EntryIngredient.of(entryStack) + } + } + + override fun getOutputEntries(): List { + return neuRecipe.allOutputs.map { + val entryStack = SBItemEntryDefinition.getEntry(SkyblockId(it.itemId)) + EntryIngredient.of(entryStack) + } + } +} diff --git a/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt b/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt index 647862e..34d98fa 100644 --- a/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt +++ b/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt @@ -14,6 +14,7 @@ import net.minecraft.item.ItemStack import net.minecraft.text.Text import net.minecraft.util.Identifier import moe.nea.notenoughupdates.recipes.SBCraftingRecipe +import moe.nea.notenoughupdates.recipes.SBForgeRecipe import moe.nea.notenoughupdates.repo.ItemCache.asItemStack import moe.nea.notenoughupdates.repo.RepoManager import moe.nea.notenoughupdates.util.SkyblockId @@ -23,7 +24,7 @@ class NEUReiPlugin : REIClientPlugin { companion object { fun EntryStack.asItemEntry(): EntryStack { - return EntryStack.of(VanillaEntryTypes.ITEM, value?.asItemStack()) + return EntryStack.of(VanillaEntryTypes.ITEM, value.asItemStack()) } val SKYBLOCK_ITEM_TYPE_ID = Identifier("notenoughupdates", "skyblockitems") @@ -35,10 +36,18 @@ class NEUReiPlugin : REIClientPlugin { override fun registerCategories(registry: CategoryRegistry) { registry.add(SBCraftingRecipe.Category) + registry.add(SBForgeRecipe.Category) } override fun registerDisplays(registry: DisplayRegistry) { - registry.registerDisplayGenerator(SBCraftingRecipe.Category.catIdentifier, SkyblockRecipeDynamicGenerator) + registry.registerDisplayGenerator( + SBCraftingRecipe.Category.catIdentifier, + SkyblockCraftingRecipeDynamicGenerator + ) + registry.registerDisplayGenerator( + SBForgeRecipe.Category.categoryIdentifier, + SkyblockForgeRecipeDynamicGenerator + ) } override fun registerCollapsibleEntries(registry: CollapsibleEntryRegistry) { diff --git a/src/main/kotlin/moe/nea/notenoughupdates/rei/SBItemEntryDefinition.kt b/src/main/kotlin/moe/nea/notenoughupdates/rei/SBItemEntryDefinition.kt index b449848..0b43407 100644 --- a/src/main/kotlin/moe/nea/notenoughupdates/rei/SBItemEntryDefinition.kt +++ b/src/main/kotlin/moe/nea/notenoughupdates/rei/SBItemEntryDefinition.kt @@ -1,5 +1,6 @@ package moe.nea.notenoughupdates.rei +import io.github.moulberry.repo.data.NEUIngredient import io.github.moulberry.repo.data.NEUItem import java.util.stream.Stream import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer @@ -25,8 +26,8 @@ object SBItemEntryDefinition : EntryDefinition { return o1 === o2 } - override fun cheatsAs(entry: EntryStack?, value: NEUItem?): ItemStack? { - return value?.asItemStack() + override fun cheatsAs(entry: EntryStack?, value: NEUItem?): ItemStack { + return value.asItemStack() } override fun getValueType(): Class = NEUItem::class.java @@ -71,8 +72,14 @@ object SBItemEntryDefinition : EntryDefinition { return value?.getIdentifier() ?: Identifier.of("skyblockitem", "null")!! } - fun getEntry(neuItem: NEUItem?) = EntryStack.of(this, neuItem) - fun getEntry(skyblockId: SkyblockId?) = EntryStack.of(this, skyblockId?.let { RepoManager.getNEUItem(it) }) + fun getEntry(neuItem: NEUItem?): EntryStack = + EntryStack.of(this, neuItem) + + fun getEntry(skyblockId: SkyblockId?): EntryStack = + EntryStack.of(this, skyblockId?.let { RepoManager.getNEUItem(it) }) + + fun getEntry(ingredient: NEUIngredient?): EntryStack = + getEntry(ingredient?.itemId?.let { SkyblockId(it) }) } diff --git a/src/main/kotlin/moe/nea/notenoughupdates/rei/SkyblockCraftingRecipeDynamicGenerator.kt b/src/main/kotlin/moe/nea/notenoughupdates/rei/SkyblockCraftingRecipeDynamicGenerator.kt new file mode 100644 index 0000000..cc31427 --- /dev/null +++ b/src/main/kotlin/moe/nea/notenoughupdates/rei/SkyblockCraftingRecipeDynamicGenerator.kt @@ -0,0 +1,52 @@ +package moe.nea.notenoughupdates.rei + +import io.github.moulberry.repo.data.NEUCraftingRecipe +import io.github.moulberry.repo.data.NEUForgeRecipe +import io.github.moulberry.repo.data.NEUItem +import io.github.moulberry.repo.data.NEURecipe +import java.util.* +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.notenoughupdates.recipes.SBCraftingRecipe +import moe.nea.notenoughupdates.recipes.SBForgeRecipe +import moe.nea.notenoughupdates.repo.RepoManager +import moe.nea.notenoughupdates.util.skyblockId + + +val SkyblockCraftingRecipeDynamicGenerator = neuDisplayGenerator { + SBCraftingRecipe(it) +} + +val SkyblockForgeRecipeDynamicGenerator = neuDisplayGenerator { + SBForgeRecipe(it) +} + +inline fun neuDisplayGenerator(noinline 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) + .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)) + + } + } diff --git a/src/main/kotlin/moe/nea/notenoughupdates/rei/SkyblockRecipeDynamicGenerator.kt b/src/main/kotlin/moe/nea/notenoughupdates/rei/SkyblockRecipeDynamicGenerator.kt deleted file mode 100644 index 931e45c..0000000 --- a/src/main/kotlin/moe/nea/notenoughupdates/rei/SkyblockRecipeDynamicGenerator.kt +++ /dev/null @@ -1,38 +0,0 @@ -package moe.nea.notenoughupdates.rei - -import io.github.moulberry.repo.data.NEUCraftingRecipe -import io.github.moulberry.repo.data.NEUItem -import me.shedaniel.rei.api.client.registry.display.DynamicDisplayGenerator -import me.shedaniel.rei.api.client.view.ViewSearchBuilder -import me.shedaniel.rei.api.common.entry.EntryStack -import moe.nea.notenoughupdates.recipes.SBCraftingRecipe -import moe.nea.notenoughupdates.repo.RepoManager -import moe.nea.notenoughupdates.util.skyblockId -import java.util.* - -object SkyblockRecipeDynamicGenerator: 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 { SBCraftingRecipe(it) }) - } - - override fun generate(builder: ViewSearchBuilder): Optional> { - if (SBCraftingRecipe.Category.catIdentifier !in builder.categories) return Optional.empty() - return Optional.of( - RepoManager.getAllRecipes().filterIsInstance().map { SBCraftingRecipe(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 { SBCraftingRecipe(it) }) - - } -} -- cgit