From e03641163595569ffdd445ec8f69ad830d46e868 Mon Sep 17 00:00:00 2001 From: Simon B Date: Mon, 20 Nov 2023 15:07:12 +0100 Subject: [PATCH] feat: Take serializer when registering a recipe (#62) --- .../mods/balm/fabric/recipe/FabricBalmRecipes.java | 6 ++++-- .../mods/balm/forge/recipe/ForgeBalmRecipes.java | 13 +++++++++---- .../main/java/net/blay09/mods/balm/api/Balm.java | 5 +++++ .../blay09/mods/balm/api/recipe/BalmRecipes.java | 3 ++- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/fabric/src/main/java/net/blay09/mods/balm/fabric/recipe/FabricBalmRecipes.java b/fabric/src/main/java/net/blay09/mods/balm/fabric/recipe/FabricBalmRecipes.java index d7a0ee41..01248cd6 100644 --- a/fabric/src/main/java/net/blay09/mods/balm/fabric/recipe/FabricBalmRecipes.java +++ b/fabric/src/main/java/net/blay09/mods/balm/fabric/recipe/FabricBalmRecipes.java @@ -6,6 +6,7 @@ import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeType; import java.util.function.Supplier; @@ -13,9 +14,10 @@ public class FabricBalmRecipes implements BalmRecipes { @Override - public > DeferredObject> registerRecipeType(Supplier> supplier, ResourceLocation identifier) { + public > DeferredObject> registerRecipeType(Supplier> typeSupplier, Supplier> serializerSupplier, ResourceLocation identifier) { return new DeferredObject<>(identifier, () -> { - RecipeType recipeType = supplier.get(); + Registry.register(BuiltInRegistries.RECIPE_SERIALIZER, identifier, serializerSupplier.get()); + RecipeType recipeType = typeSupplier.get(); recipeType = Registry.register(BuiltInRegistries.RECIPE_TYPE, identifier, recipeType); return recipeType; }).resolveImmediately(); diff --git a/forge/src/main/java/net/blay09/mods/balm/forge/recipe/ForgeBalmRecipes.java b/forge/src/main/java/net/blay09/mods/balm/forge/recipe/ForgeBalmRecipes.java index 5fb1df61..964a7dea 100644 --- a/forge/src/main/java/net/blay09/mods/balm/forge/recipe/ForgeBalmRecipes.java +++ b/forge/src/main/java/net/blay09/mods/balm/forge/recipe/ForgeBalmRecipes.java @@ -5,6 +5,7 @@ import net.blay09.mods.balm.forge.DeferredRegisters; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeType; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; @@ -14,10 +15,14 @@ public class ForgeBalmRecipes implements BalmRecipes { @Override - public > DeferredObject> registerRecipeType(Supplier> supplier, ResourceLocation identifier) { - DeferredRegister> register = DeferredRegisters.get(ForgeRegistries.RECIPE_TYPES, identifier.getNamespace()); - RegistryObject> registryObject = register.register(identifier.getPath(), supplier); - return new DeferredObject<>(identifier, registryObject, registryObject::isPresent); + public > DeferredObject> registerRecipeType(Supplier> typeSupplier, Supplier> serializerSupplier, ResourceLocation identifier) { + DeferredRegister> serializerRegister = DeferredRegisters.get(ForgeRegistries.RECIPE_SERIALIZERS, identifier.getNamespace()); + RegistryObject> serializerObject = serializerRegister.register(identifier.getPath(), serializerSupplier); + + DeferredRegister> typeRegister = DeferredRegisters.get(ForgeRegistries.RECIPE_TYPES, identifier.getNamespace()); + RegistryObject> typeObject = typeRegister.register(identifier.getPath(), typeSupplier); + + return new DeferredObject<>(identifier, typeObject, () -> typeObject.isPresent() && serializerObject.isPresent()); } } diff --git a/shared/src/main/java/net/blay09/mods/balm/api/Balm.java b/shared/src/main/java/net/blay09/mods/balm/api/Balm.java index 85c6fb91..90a4da61 100644 --- a/shared/src/main/java/net/blay09/mods/balm/api/Balm.java +++ b/shared/src/main/java/net/blay09/mods/balm/api/Balm.java @@ -12,6 +12,7 @@ import net.blay09.mods.balm.api.network.BalmNetworking; import net.blay09.mods.balm.api.provider.BalmProviders; import net.blay09.mods.balm.api.proxy.SidedProxy; +import net.blay09.mods.balm.api.recipe.BalmRecipes; import net.blay09.mods.balm.api.sound.BalmSounds; import net.blay09.mods.balm.api.stats.BalmStats; import net.blay09.mods.balm.api.world.BalmWorldGen; @@ -99,6 +100,10 @@ public static BalmHooks getHooks() { return runtime.getHooks(); } + public static BalmRecipes getRecipes() { + return runtime.getRecipes(); + } + public static BalmRegistries getRegistries() { return runtime.getRegistries(); } diff --git a/shared/src/main/java/net/blay09/mods/balm/api/recipe/BalmRecipes.java b/shared/src/main/java/net/blay09/mods/balm/api/recipe/BalmRecipes.java index 4827b686..28425d84 100644 --- a/shared/src/main/java/net/blay09/mods/balm/api/recipe/BalmRecipes.java +++ b/shared/src/main/java/net/blay09/mods/balm/api/recipe/BalmRecipes.java @@ -3,10 +3,11 @@ import net.blay09.mods.balm.api.DeferredObject; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeType; import java.util.function.Supplier; public interface BalmRecipes { - > DeferredObject> registerRecipeType(Supplier> supplier, ResourceLocation identifier); + > DeferredObject> registerRecipeType(Supplier> typeSupplier, Supplier> serializerSupplier, ResourceLocation identifier); }