diff options
Diffstat (limited to 'src/main/kotlin/moe/nea')
7 files changed, 153 insertions, 68 deletions
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<EntryIngredient> { - return neuRecipe.allInputs.map { - val entryStack = SBItemEntryDefinition.getEntry(SkyblockId(it.itemId)) - EntryIngredient.of(entryStack) - } - } - - override fun getOutputEntries(): List<EntryIngredient> { - 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<SBForgeRecipe> { + override fun getCategoryIdentifier(): CategoryIdentifier<SBForgeRecipe> = + 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<Widget> { + 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<EntryIngredient> { + return neuRecipe.allInputs.map { + val entryStack = SBItemEntryDefinition.getEntry(SkyblockId(it.itemId)) + EntryIngredient.of(entryStack) + } + } + + override fun getOutputEntries(): List<EntryIngredient> { + 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<NEUItem>.asItemEntry(): EntryStack<ItemStack> { - 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<NEUItem> { return o1 === o2 } - override fun cheatsAs(entry: EntryStack<NEUItem>?, value: NEUItem?): ItemStack? { - return value?.asItemStack() + override fun cheatsAs(entry: EntryStack<NEUItem>?, value: NEUItem?): ItemStack { + return value.asItemStack() } override fun getValueType(): Class<NEUItem> = NEUItem::class.java @@ -71,8 +72,14 @@ object SBItemEntryDefinition : EntryDefinition<NEUItem> { 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<NEUItem> = + EntryStack.of(this, neuItem) + + fun getEntry(skyblockId: SkyblockId?): EntryStack<NEUItem> = + EntryStack.of(this, skyblockId?.let { RepoManager.getNEUItem(it) }) + + fun getEntry(ingredient: NEUIngredient?): EntryStack<NEUItem> = + 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, NEUCraftingRecipe> { + SBCraftingRecipe(it) +} + +val SkyblockForgeRecipeDynamicGenerator = neuDisplayGenerator<SBForgeRecipe, NEUForgeRecipe> { + SBForgeRecipe(it) +} + +inline fun <D : Display, reified T : NEURecipe> neuDisplayGenerator(noinline mapper: (T) -> D) = + object : DynamicDisplayGenerator<D> { + override fun getRecipeFor(entry: EntryStack<*>): Optional<List<D>> { + if (entry.type != SBItemEntryDefinition.type) return Optional.empty() + val item = entry.castValue<NEUItem>() + val recipes = RepoManager.getRecipesFor(item.skyblockId) + val craftingRecipes = recipes.filterIsInstance<T>() + return Optional.of(craftingRecipes.map(mapper)) + } + + override fun generate(builder: ViewSearchBuilder): Optional<List<D>> { + if (SBCraftingRecipe.Category.catIdentifier !in builder.categories) return Optional.empty() + return Optional.of( + RepoManager.getAllRecipes().filterIsInstance<T>().map(mapper) + .toList() + ) + } + + override fun getUsageFor(entry: EntryStack<*>): Optional<List<D>> { + if (entry.type != SBItemEntryDefinition.type) return Optional.empty() + val item = entry.castValue<NEUItem>() + val recipes = RepoManager.getUsagesFor(item.skyblockId) + val craftingRecipes = recipes.filterIsInstance<T>() + 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<SBCraftingRecipe> { - override fun getRecipeFor(entry: EntryStack<*>): Optional<List<SBCraftingRecipe>> { - if (entry.type != SBItemEntryDefinition.type) return Optional.empty() - val item = entry.castValue<NEUItem>() - val recipes = RepoManager.getRecipesFor(item.skyblockId) - val craftingRecipes = recipes.filterIsInstance<NEUCraftingRecipe>() - return Optional.of(craftingRecipes.map { SBCraftingRecipe(it) }) - } - - override fun generate(builder: ViewSearchBuilder): Optional<List<SBCraftingRecipe>> { - if (SBCraftingRecipe.Category.catIdentifier !in builder.categories) return Optional.empty() - return Optional.of( - RepoManager.getAllRecipes().filterIsInstance<NEUCraftingRecipe>().map { SBCraftingRecipe(it) } - .toList() - ) - } - - override fun getUsageFor(entry: EntryStack<*>): Optional<List<SBCraftingRecipe>> { - if (entry.type != SBItemEntryDefinition.type) return Optional.empty() - val item = entry.castValue<NEUItem>() - val recipes = RepoManager.getUsagesFor(item.skyblockId) - val craftingRecipes = recipes.filterIsInstance<NEUCraftingRecipe>() - return Optional.of(craftingRecipes.map { SBCraftingRecipe(it) }) - - } -} |