diff options
author | nea <nea@nea.moe> | 2023-05-04 18:31:30 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-05-04 18:31:30 +0200 |
commit | 44154b569e406c7be39b71c87a441830f3fffc93 (patch) | |
tree | 3b7572349e685c55d7bad47196880364f603320a /src/main/kotlin | |
parent | 508b8352cfbc066b025943cf1cbf8be5e5edb88a (diff) | |
download | firmament-44154b569e406c7be39b71c87a441830f3fffc93.tar.gz firmament-44154b569e406c7be39b71c87a441830f3fffc93.tar.bz2 firmament-44154b569e406c7be39b71c87a441830f3fffc93.zip |
Move recipe generator to own class
Diffstat (limited to 'src/main/kotlin')
-rw-r--r-- | src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt | 33 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/notenoughupdates/rei/SkyblockRecipeDynamicGenerator.kt | 38 |
2 files changed, 40 insertions, 31 deletions
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt b/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt index 2bf3a5b..647862e 100644 --- a/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt +++ b/src/main/kotlin/moe/nea/notenoughupdates/rei/NEUReiPlugin.kt @@ -1,16 +1,12 @@ package moe.nea.notenoughupdates.rei -import io.github.moulberry.repo.data.NEUCraftingRecipe import io.github.moulberry.repo.data.NEUItem -import java.util.* import me.shedaniel.rei.api.client.plugins.REIClientPlugin import me.shedaniel.rei.api.client.registry.category.CategoryRegistry import me.shedaniel.rei.api.client.registry.display.DisplayRegistry -import me.shedaniel.rei.api.client.registry.display.DynamicDisplayGenerator import me.shedaniel.rei.api.client.registry.entry.CollapsibleEntryRegistry import me.shedaniel.rei.api.client.registry.entry.EntryRegistry import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry -import me.shedaniel.rei.api.client.view.ViewSearchBuilder import me.shedaniel.rei.api.common.entry.EntryStack import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes @@ -21,7 +17,6 @@ import moe.nea.notenoughupdates.recipes.SBCraftingRecipe import moe.nea.notenoughupdates.repo.ItemCache.asItemStack import moe.nea.notenoughupdates.repo.RepoManager import moe.nea.notenoughupdates.util.SkyblockId -import moe.nea.notenoughupdates.util.skyblockId class NEUReiPlugin : REIClientPlugin { @@ -41,33 +36,9 @@ class NEUReiPlugin : REIClientPlugin { override fun registerCategories(registry: CategoryRegistry) { registry.add(SBCraftingRecipe.Category) } - override fun registerDisplays(registry: DisplayRegistry) { - registry.registerGlobalDisplayGenerator(object : 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) }) - - } - }) + override fun registerDisplays(registry: DisplayRegistry) { + registry.registerDisplayGenerator(SBCraftingRecipe.Category.catIdentifier, SkyblockRecipeDynamicGenerator) } override fun registerCollapsibleEntries(registry: CollapsibleEntryRegistry) { diff --git a/src/main/kotlin/moe/nea/notenoughupdates/rei/SkyblockRecipeDynamicGenerator.kt b/src/main/kotlin/moe/nea/notenoughupdates/rei/SkyblockRecipeDynamicGenerator.kt new file mode 100644 index 0000000..931e45c --- /dev/null +++ b/src/main/kotlin/moe/nea/notenoughupdates/rei/SkyblockRecipeDynamicGenerator.kt @@ -0,0 +1,38 @@ +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) }) + + } +} |