From 1be2115ab1ee9f3a6776cff908bfa0818142e0b8 Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Tue, 1 Oct 2024 12:46:09 +0300 Subject: [PATCH] Split AdornRecipes into recipe type/serializer classes --- .../adorn/block/entity/BrewerBlockEntity.java | 4 +-- .../adorn/compat/emi/AdornEmiPlugin.java | 4 +-- .../adorn/compat/jei/AdornJeiPlugin.java | 4 +-- .../compat/rei/client/AdornReiClient.java | 6 ++--- ...cipes.java => AdornRecipeSerializers.java} | 23 +++------------- .../juuxel/adorn/recipe/AdornRecipeTypes.java | 27 +++++++++++++++++++ .../juuxel/adorn/recipe/BrewingRecipe.java | 2 +- .../recipe/FertilizerRefillingRecipe.java | 2 +- .../adorn/recipe/FluidBrewingRecipe.java | 2 +- .../adorn/recipe/ItemBrewingRecipe.java | 2 +- fabric/src/main/java/juuxel/adorn/Adorn.java | 6 +++-- .../juuxel/adorn/platform/forge/Adorn.java | 10 ++++--- 12 files changed, 54 insertions(+), 38 deletions(-) rename common/src/main/java/juuxel/adorn/recipe/{AdornRecipes.java => AdornRecipeSerializers.java} (55%) create mode 100644 common/src/main/java/juuxel/adorn/recipe/AdornRecipeTypes.java diff --git a/common/src/main/java/juuxel/adorn/block/entity/BrewerBlockEntity.java b/common/src/main/java/juuxel/adorn/block/entity/BrewerBlockEntity.java index 392312176..6e74ecaaf 100644 --- a/common/src/main/java/juuxel/adorn/block/entity/BrewerBlockEntity.java +++ b/common/src/main/java/juuxel/adorn/block/entity/BrewerBlockEntity.java @@ -6,7 +6,7 @@ import juuxel.adorn.item.AdornItems; import juuxel.adorn.menu.BrewerMenu; import juuxel.adorn.platform.ItemBridge; -import juuxel.adorn.recipe.AdornRecipes; +import juuxel.adorn.recipe.AdornRecipeTypes; import juuxel.adorn.recipe.BrewerInput; import juuxel.adorn.recipe.FluidBrewingRecipe; import juuxel.adorn.recipe.InventoryWrappingRecipeInput; @@ -167,7 +167,7 @@ public static void tick(World world, BlockPos pos, BlockState state, BrewerBlock } var input = new RecipeInputImpl(brewer); - var recipe = world.getRecipeManager().getFirstMatch(AdornRecipes.BREWING_TYPE.get(), input, world).map(RecipeEntry::value).orElse(null); + var recipe = world.getRecipeManager().getFirstMatch(AdornRecipeTypes.BREWING.get(), input, world).map(RecipeEntry::value).orElse(null); if (recipe != null && brewer.getStack(INPUT_SLOT).isOf(AdornItems.MUG.get())) { if (brewer.progress++ >= MAX_PROGRESS) { diff --git a/common/src/main/java/juuxel/adorn/compat/emi/AdornEmiPlugin.java b/common/src/main/java/juuxel/adorn/compat/emi/AdornEmiPlugin.java index cf1fab9fa..8f74422c2 100644 --- a/common/src/main/java/juuxel/adorn/compat/emi/AdornEmiPlugin.java +++ b/common/src/main/java/juuxel/adorn/compat/emi/AdornEmiPlugin.java @@ -9,7 +9,7 @@ import juuxel.adorn.AdornCommon; import juuxel.adorn.block.AdornBlocks; import juuxel.adorn.client.gui.screen.TradingStationScreen; -import juuxel.adorn.recipe.AdornRecipes; +import juuxel.adorn.recipe.AdornRecipeTypes; import juuxel.adorn.recipe.FluidBrewingRecipe; import juuxel.adorn.recipe.ItemBrewingRecipe; @@ -28,7 +28,7 @@ public void register(EmiRegistry registry) { var recipeManager = registry.getRecipeManager(); - for (var entry : recipeManager.listAllOfType(AdornRecipes.BREWING_TYPE.get())) { + for (var entry : recipeManager.listAllOfType(AdornRecipeTypes.BREWING.get())) { BrewingEmiRecipe emiRecipe = switch (entry.value()) { case ItemBrewingRecipe recipe -> new BrewingEmiRecipe(entry.id(), recipe); case FluidBrewingRecipe recipe -> new BrewingEmiRecipe(entry.id(), recipe); diff --git a/common/src/main/java/juuxel/adorn/compat/jei/AdornJeiPlugin.java b/common/src/main/java/juuxel/adorn/compat/jei/AdornJeiPlugin.java index 8593da788..e603f61af 100644 --- a/common/src/main/java/juuxel/adorn/compat/jei/AdornJeiPlugin.java +++ b/common/src/main/java/juuxel/adorn/compat/jei/AdornJeiPlugin.java @@ -4,7 +4,7 @@ import juuxel.adorn.AdornCommon; import juuxel.adorn.block.AdornBlocks; import juuxel.adorn.client.gui.screen.TradingStationScreen; -import juuxel.adorn.recipe.AdornRecipes; +import juuxel.adorn.recipe.AdornRecipeTypes; import me.shedaniel.rei.plugincompatibilities.api.REIPluginCompatIgnore; import mezz.jei.api.IModPlugin; import mezz.jei.api.JeiPlugin; @@ -37,7 +37,7 @@ public void registerCategories(IRecipeCategoryRegistration registration) { @Override public void registerRecipes(IRecipeRegistration registration) { - registerRecipes(registration, AdornRecipes.BREWING_TYPE.get(), JeiRecipeTypes.BREWER); + registerRecipes(registration, AdornRecipeTypes.BREWING.get(), JeiRecipeTypes.BREWER); } private > void registerRecipes( diff --git a/common/src/main/java/juuxel/adorn/compat/rei/client/AdornReiClient.java b/common/src/main/java/juuxel/adorn/compat/rei/client/AdornReiClient.java index c10439dcf..0396a4822 100644 --- a/common/src/main/java/juuxel/adorn/compat/rei/client/AdornReiClient.java +++ b/common/src/main/java/juuxel/adorn/compat/rei/client/AdornReiClient.java @@ -4,7 +4,7 @@ import juuxel.adorn.compat.rei.AdornReiServer; import juuxel.adorn.compat.rei.BrewerDisplay; import juuxel.adorn.lib.AdornTags; -import juuxel.adorn.recipe.AdornRecipes; +import juuxel.adorn.recipe.AdornRecipeTypes; import juuxel.adorn.recipe.FluidBrewingRecipe; import juuxel.adorn.recipe.ItemBrewingRecipe; import me.shedaniel.rei.api.client.plugins.REIClientPlugin; @@ -28,8 +28,8 @@ public void registerCategories(CategoryRegistry registry) { @Override public void registerDisplays(DisplayRegistry registry) { - registry.registerRecipeFiller(ItemBrewingRecipe.class, AdornRecipes.BREWING_TYPE.get(), entry -> new BrewerDisplay(entry.value())); - registry.registerRecipeFiller(FluidBrewingRecipe.class, AdornRecipes.BREWING_TYPE.get(), entry -> new BrewerDisplay(entry.value())); + registry.registerRecipeFiller(ItemBrewingRecipe.class, AdornRecipeTypes.BREWING.get(), entry -> new BrewerDisplay(entry.value())); + registry.registerRecipeFiller(FluidBrewingRecipe.class, AdornRecipeTypes.BREWING.get(), entry -> new BrewerDisplay(entry.value())); } @Override diff --git a/common/src/main/java/juuxel/adorn/recipe/AdornRecipes.java b/common/src/main/java/juuxel/adorn/recipe/AdornRecipeSerializers.java similarity index 55% rename from common/src/main/java/juuxel/adorn/recipe/AdornRecipes.java rename to common/src/main/java/juuxel/adorn/recipe/AdornRecipeSerializers.java index 4df13215c..bcf010d37 100644 --- a/common/src/main/java/juuxel/adorn/recipe/AdornRecipes.java +++ b/common/src/main/java/juuxel/adorn/recipe/AdornRecipeSerializers.java @@ -1,37 +1,22 @@ package juuxel.adorn.recipe; -import juuxel.adorn.AdornCommon; import juuxel.adorn.lib.registry.Registered; import juuxel.adorn.lib.registry.Registrar; import juuxel.adorn.lib.registry.RegistrarFactory; -import net.minecraft.recipe.Recipe; import net.minecraft.recipe.RecipeSerializer; -import net.minecraft.recipe.RecipeType; import net.minecraft.recipe.SpecialRecipeSerializer; import net.minecraft.registry.RegistryKeys; -public final class AdornRecipes { +public final class AdornRecipeSerializers { public static final Registrar> RECIPE_SERIALIZERS = RegistrarFactory.get().create(RegistryKeys.RECIPE_SERIALIZER); - public static final Registrar> RECIPE_TYPES = RegistrarFactory.get().create(RegistryKeys.RECIPE_TYPE); - public static final Registered> BREWING_TYPE = registerRecipeType("brewing"); - public static final Registered> BREWING_SERIALIZER = + public static final Registered> BREWING = RECIPE_SERIALIZERS.register("brewing", ItemBrewingRecipe.Serializer::new); - public static final Registered> BREWING_FROM_FLUID_SERIALIZER = + public static final Registered> BREWING_FROM_FLUID = RECIPE_SERIALIZERS.register("brewing_from_fluid", FluidBrewingRecipe.Serializer::new); - - public static final Registered> FERTILIZER_REFILLING_SERIALIZER = + public static final Registered> FERTILIZER_REFILLING = RECIPE_SERIALIZERS.register("fertilizer_refilling", () -> new SpecialRecipeSerializer<>(FertilizerRefillingRecipe::new)); - private static > Registered> registerRecipeType(String id) { - return RECIPE_TYPES.register(id, () -> new RecipeType<>() { - @Override - public String toString() { - return AdornCommon.NAMESPACE + ':' + id; - } - }); - } - public static void init() { } } diff --git a/common/src/main/java/juuxel/adorn/recipe/AdornRecipeTypes.java b/common/src/main/java/juuxel/adorn/recipe/AdornRecipeTypes.java new file mode 100644 index 000000000..5ee3b6036 --- /dev/null +++ b/common/src/main/java/juuxel/adorn/recipe/AdornRecipeTypes.java @@ -0,0 +1,27 @@ +package juuxel.adorn.recipe; + +import juuxel.adorn.AdornCommon; +import juuxel.adorn.lib.registry.Registered; +import juuxel.adorn.lib.registry.Registrar; +import juuxel.adorn.lib.registry.RegistrarFactory; +import net.minecraft.recipe.Recipe; +import net.minecraft.recipe.RecipeType; +import net.minecraft.registry.RegistryKeys; + +public final class AdornRecipeTypes { + public static final Registrar> RECIPE_TYPES = RegistrarFactory.get().create(RegistryKeys.RECIPE_TYPE); + + public static final Registered> BREWING = registerRecipeType("brewing"); + + private static > Registered> registerRecipeType(String id) { + return RECIPE_TYPES.register(id, () -> new RecipeType<>() { + @Override + public String toString() { + return AdornCommon.NAMESPACE + ':' + id; + } + }); + } + + public static void init() { + } +} diff --git a/common/src/main/java/juuxel/adorn/recipe/BrewingRecipe.java b/common/src/main/java/juuxel/adorn/recipe/BrewingRecipe.java index 5b9a2da10..52f39abce 100644 --- a/common/src/main/java/juuxel/adorn/recipe/BrewingRecipe.java +++ b/common/src/main/java/juuxel/adorn/recipe/BrewingRecipe.java @@ -6,6 +6,6 @@ public sealed interface BrewingRecipe extends Recipe permits FluidBrewingRecipe, ItemBrewingRecipe { @Override default RecipeType getType() { - return AdornRecipes.BREWING_TYPE.get(); + return AdornRecipeTypes.BREWING.get(); } } diff --git a/common/src/main/java/juuxel/adorn/recipe/FertilizerRefillingRecipe.java b/common/src/main/java/juuxel/adorn/recipe/FertilizerRefillingRecipe.java index 1be477429..964ed8d2a 100644 --- a/common/src/main/java/juuxel/adorn/recipe/FertilizerRefillingRecipe.java +++ b/common/src/main/java/juuxel/adorn/recipe/FertilizerRefillingRecipe.java @@ -72,7 +72,7 @@ public boolean fits(int width, int height) { @Override public RecipeSerializer getSerializer() { - return AdornRecipes.FERTILIZER_REFILLING_SERIALIZER.get(); + return AdornRecipeSerializers.FERTILIZER_REFILLING.get(); } private record MatchResult(ItemStack wateringCan, int fertilizers) { diff --git a/common/src/main/java/juuxel/adorn/recipe/FluidBrewingRecipe.java b/common/src/main/java/juuxel/adorn/recipe/FluidBrewingRecipe.java index 812bf14fc..63913b442 100644 --- a/common/src/main/java/juuxel/adorn/recipe/FluidBrewingRecipe.java +++ b/common/src/main/java/juuxel/adorn/recipe/FluidBrewingRecipe.java @@ -50,7 +50,7 @@ public ItemStack getResult(RegistryWrapper.WrapperLookup registries) { @Override public RecipeSerializer getSerializer() { - return AdornRecipes.BREWING_FROM_FLUID_SERIALIZER.get(); + return AdornRecipeSerializers.BREWING_FROM_FLUID.get(); } public static final class Serializer implements RecipeSerializer { diff --git a/common/src/main/java/juuxel/adorn/recipe/ItemBrewingRecipe.java b/common/src/main/java/juuxel/adorn/recipe/ItemBrewingRecipe.java index 2083e7da0..a30749237 100644 --- a/common/src/main/java/juuxel/adorn/recipe/ItemBrewingRecipe.java +++ b/common/src/main/java/juuxel/adorn/recipe/ItemBrewingRecipe.java @@ -47,7 +47,7 @@ public ItemStack getResult(RegistryWrapper.WrapperLookup registries) { @Override public RecipeSerializer getSerializer() { - return AdornRecipes.BREWING_SERIALIZER.get(); + return AdornRecipeSerializers.BREWING.get(); } public static final class Serializer implements RecipeSerializer { diff --git a/fabric/src/main/java/juuxel/adorn/Adorn.java b/fabric/src/main/java/juuxel/adorn/Adorn.java index 84403702c..e40f3b404 100644 --- a/fabric/src/main/java/juuxel/adorn/Adorn.java +++ b/fabric/src/main/java/juuxel/adorn/Adorn.java @@ -27,7 +27,8 @@ import juuxel.adorn.loot.AdornLootConditionTypes; import juuxel.adorn.loot.AdornLootFunctionTypes; import juuxel.adorn.menu.AdornMenus; -import juuxel.adorn.recipe.AdornRecipes; +import juuxel.adorn.recipe.AdornRecipeSerializers; +import juuxel.adorn.recipe.AdornRecipeTypes; import juuxel.adorn.resources.AdornResources; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -53,7 +54,8 @@ public static void init() { AdornStats.init(); SofaSleeping.init(); AdornCriteria.init(); - AdornRecipes.init(); + AdornRecipeTypes.init(); + AdornRecipeSerializers.init(); AdornLootConditionTypes.init(); AdornLootFunctionTypes.init(); Compat.init(); diff --git a/forge/src/main/java/juuxel/adorn/platform/forge/Adorn.java b/forge/src/main/java/juuxel/adorn/platform/forge/Adorn.java index 00077e713..fd6f70840 100644 --- a/forge/src/main/java/juuxel/adorn/platform/forge/Adorn.java +++ b/forge/src/main/java/juuxel/adorn/platform/forge/Adorn.java @@ -27,7 +27,8 @@ import juuxel.adorn.platform.forge.event.ItemEvents; import juuxel.adorn.platform.forge.networking.AdornNetworking; import juuxel.adorn.platform.forge.registrar.ForgeRegistrar; -import juuxel.adorn.recipe.AdornRecipes; +import juuxel.adorn.recipe.AdornRecipeSerializers; +import juuxel.adorn.recipe.AdornRecipeTypes; import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.ModLoadingContext; @@ -53,10 +54,11 @@ public Adorn() { register(AdornBlockEntities.BLOCK_ENTITIES, modBus); AdornItemGroups.init(); register(AdornItemGroups.ITEM_GROUPS, modBus); - AdornRecipes.init(); + AdornRecipeTypes.init(); + AdornRecipeSerializers.init(); register(AdornMenus.MENUS, modBus); - register(AdornRecipes.RECIPE_SERIALIZERS, modBus); - register(AdornRecipes.RECIPE_TYPES, modBus); + register(AdornRecipeSerializers.RECIPE_SERIALIZERS, modBus); + register(AdornRecipeTypes.RECIPE_TYPES, modBus); register(AdornLootConditionTypes.LOOT_CONDITION_TYPES, modBus); register(AdornLootFunctionTypes.LOOT_FUNCTION_TYPES, modBus); register(AdornStats.CUSTOM_STATS, modBus);