From a64c3bccd5bcb3b4d65d536d7a4aeb175437f420 Mon Sep 17 00:00:00 2001 From: BlayTheNinth <1933180+BlayTheNinth@users.noreply.github.com> Date: Sun, 19 Nov 2023 13:14:31 +0100 Subject: [PATCH] feat: Add recipe type registration --- .../mods/balm/fabric/FabricBalmRuntime.java | 8 +++++++ .../balm/fabric/recipe/FabricBalmRecipes.java | 24 +++++++++++++++++++ .../mods/balm/forge/ForgeBalmRuntime.java | 8 +++++++ .../balm/forge/recipe/ForgeBalmRecipes.java | 23 ++++++++++++++++++ .../balm/neoforge/NeoForgeBalmRuntime.java | 8 +++++++ .../neoforge/recipe/NeoForgeBalmRecipes.java | 23 ++++++++++++++++++ .../net/blay09/mods/balm/api/BalmRuntime.java | 3 +++ .../mods/balm/api/recipe/BalmRecipes.java | 12 ++++++++++ 8 files changed, 109 insertions(+) create mode 100644 fabric/src/main/java/net/blay09/mods/balm/fabric/recipe/FabricBalmRecipes.java create mode 100644 forge/src/main/java/net/blay09/mods/balm/forge/recipe/ForgeBalmRecipes.java create mode 100644 neoforge/src/main/java/net/blay09/mods/balm/neoforge/recipe/NeoForgeBalmRecipes.java create mode 100644 shared/src/main/java/net/blay09/mods/balm/api/recipe/BalmRecipes.java diff --git a/fabric/src/main/java/net/blay09/mods/balm/fabric/FabricBalmRuntime.java b/fabric/src/main/java/net/blay09/mods/balm/fabric/FabricBalmRuntime.java index 9d0f9a87..476fe00d 100644 --- a/fabric/src/main/java/net/blay09/mods/balm/fabric/FabricBalmRuntime.java +++ b/fabric/src/main/java/net/blay09/mods/balm/fabric/FabricBalmRuntime.java @@ -9,6 +9,7 @@ import net.blay09.mods.balm.api.config.BalmConfig; import net.blay09.mods.balm.api.entity.BalmEntities; import net.blay09.mods.balm.api.event.BalmEvents; +import net.blay09.mods.balm.api.recipe.BalmRecipes; import net.blay09.mods.balm.api.stats.BalmStats; import net.blay09.mods.balm.fabric.event.FabricBalmCommonEvents; import net.blay09.mods.balm.fabric.event.FabricBalmEvents; @@ -31,6 +32,7 @@ import net.blay09.mods.balm.fabric.menu.FabricBalmMenus; import net.blay09.mods.balm.fabric.network.FabricBalmNetworking; import net.blay09.mods.balm.fabric.provider.FabricBalmProviders; +import net.blay09.mods.balm.fabric.recipe.FabricBalmRecipes; import net.blay09.mods.balm.fabric.sound.FabricBalmSounds; import net.blay09.mods.balm.fabric.stats.FabricBalmStats; import net.blay09.mods.balm.fabric.world.FabricBalmWorldGen; @@ -67,6 +69,7 @@ public class FabricBalmRuntime implements BalmRuntime { private final BalmCommands commands = new FabricBalmCommands(); private final BalmLootTables lootTables = new CommonBalmLootTables(); private final BalmStats stats = new FabricBalmStats(); + private final BalmRecipes recipes = new FabricBalmRecipes(); public FabricBalmRuntime() { FabricBalmCommonEvents.registerEvents(events); @@ -152,6 +155,11 @@ public BalmStats getStats() { return stats; } + @Override + public BalmRecipes getRecipes() { + return recipes; + } + @Override public boolean isModLoaded(String modId) { return FabricLoader.getInstance().isModLoaded(modId); 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 new file mode 100644 index 00000000..d7a0ee41 --- /dev/null +++ b/fabric/src/main/java/net/blay09/mods/balm/fabric/recipe/FabricBalmRecipes.java @@ -0,0 +1,24 @@ +package net.blay09.mods.balm.fabric.recipe; + +import net.blay09.mods.balm.api.DeferredObject; +import net.blay09.mods.balm.api.recipe.BalmRecipes; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeType; + +import java.util.function.Supplier; + +public class FabricBalmRecipes implements BalmRecipes { + + @Override + public > DeferredObject> registerRecipeType(Supplier> supplier, ResourceLocation identifier) { + return new DeferredObject<>(identifier, () -> { + RecipeType recipeType = supplier.get(); + recipeType = Registry.register(BuiltInRegistries.RECIPE_TYPE, identifier, recipeType); + return recipeType; + }).resolveImmediately(); + } + +} diff --git a/forge/src/main/java/net/blay09/mods/balm/forge/ForgeBalmRuntime.java b/forge/src/main/java/net/blay09/mods/balm/forge/ForgeBalmRuntime.java index 55753d14..46cc0c0f 100644 --- a/forge/src/main/java/net/blay09/mods/balm/forge/ForgeBalmRuntime.java +++ b/forge/src/main/java/net/blay09/mods/balm/forge/ForgeBalmRuntime.java @@ -9,6 +9,7 @@ import net.blay09.mods.balm.api.config.BalmConfig; import net.blay09.mods.balm.api.entity.BalmEntities; import net.blay09.mods.balm.api.event.BalmEvents; +import net.blay09.mods.balm.api.recipe.BalmRecipes; import net.blay09.mods.balm.api.stats.BalmStats; import net.blay09.mods.balm.common.CommonBalmLootTables; import net.blay09.mods.balm.forge.event.ForgeBalmEvents; @@ -31,6 +32,7 @@ import net.blay09.mods.balm.forge.menu.ForgeBalmMenus; import net.blay09.mods.balm.forge.network.ForgeBalmNetworking; import net.blay09.mods.balm.forge.provider.ForgeBalmProviders; +import net.blay09.mods.balm.forge.recipe.ForgeBalmRecipes; import net.blay09.mods.balm.forge.sound.ForgeBalmSounds; import net.blay09.mods.balm.forge.stats.ForgeBalmStats; import net.blay09.mods.balm.forge.world.ForgeBalmWorldGen; @@ -66,6 +68,7 @@ public class ForgeBalmRuntime implements BalmRuntime { private final BalmCommands commands = new ForgeBalmCommands(); private final BalmLootTables lootTables = new CommonBalmLootTables(); private final BalmStats stats = new ForgeBalmStats(); + private final BalmRecipes recipes = new ForgeBalmRecipes(); private final List addonClasses = new ArrayList<>(); @@ -153,6 +156,11 @@ public BalmStats getStats() { return stats; } + @Override + public BalmRecipes getRecipes() { + return recipes; + } + @Override public boolean isModLoaded(String modId) { return ModList.get().isLoaded(modId); 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 new file mode 100644 index 00000000..5fb1df61 --- /dev/null +++ b/forge/src/main/java/net/blay09/mods/balm/forge/recipe/ForgeBalmRecipes.java @@ -0,0 +1,23 @@ +package net.blay09.mods.balm.forge.recipe; + +import net.blay09.mods.balm.api.DeferredObject; +import net.blay09.mods.balm.api.recipe.BalmRecipes; +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.RecipeType; +import net.minecraftforge.registries.DeferredRegister; +import net.minecraftforge.registries.ForgeRegistries; +import net.minecraftforge.registries.RegistryObject; + +import java.util.function.Supplier; + +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); + } + +} diff --git a/neoforge/src/main/java/net/blay09/mods/balm/neoforge/NeoForgeBalmRuntime.java b/neoforge/src/main/java/net/blay09/mods/balm/neoforge/NeoForgeBalmRuntime.java index 26f3fc53..f9663e05 100644 --- a/neoforge/src/main/java/net/blay09/mods/balm/neoforge/NeoForgeBalmRuntime.java +++ b/neoforge/src/main/java/net/blay09/mods/balm/neoforge/NeoForgeBalmRuntime.java @@ -16,6 +16,7 @@ import net.blay09.mods.balm.api.provider.BalmProviders; import net.blay09.mods.balm.api.proxy.ProxyResolutionException; 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; @@ -31,6 +32,7 @@ import net.blay09.mods.balm.neoforge.menu.NeoForgeBalmMenus; import net.blay09.mods.balm.neoforge.network.NeoForgeBalmNetworking; import net.blay09.mods.balm.neoforge.provider.NeoForgeBalmProviders; +import net.blay09.mods.balm.neoforge.recipe.NeoForgeBalmRecipes; import net.blay09.mods.balm.neoforge.sound.NeoForgeBalmSounds; import net.blay09.mods.balm.neoforge.stats.NeoForgeBalmStats; import net.blay09.mods.balm.neoforge.world.NeoForgeBalmWorldGen; @@ -68,6 +70,7 @@ public class NeoForgeBalmRuntime implements BalmRuntime { private final BalmCommands commands = new NeoForgeBalmCommands(); private final BalmLootTables lootTables = new CommonBalmLootTables(); private final BalmStats stats = new NeoForgeBalmStats(); + private final BalmRecipes recipes = new NeoForgeBalmRecipes(); private final List addonClasses = new ArrayList<>(); @@ -155,6 +158,11 @@ public BalmStats getStats() { return stats; } + @Override + public BalmRecipes getRecipes() { + return recipes; + } + @Override public boolean isModLoaded(String modId) { return ModList.get().isLoaded(modId); diff --git a/neoforge/src/main/java/net/blay09/mods/balm/neoforge/recipe/NeoForgeBalmRecipes.java b/neoforge/src/main/java/net/blay09/mods/balm/neoforge/recipe/NeoForgeBalmRecipes.java new file mode 100644 index 00000000..9ac5d54d --- /dev/null +++ b/neoforge/src/main/java/net/blay09/mods/balm/neoforge/recipe/NeoForgeBalmRecipes.java @@ -0,0 +1,23 @@ +package net.blay09.mods.balm.neoforge.recipe; + +import net.blay09.mods.balm.api.DeferredObject; +import net.blay09.mods.balm.api.recipe.BalmRecipes; +import net.blay09.mods.balm.neoforge.DeferredRegisters; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeType; +import net.neoforged.neoforge.registries.DeferredRegister; +import net.neoforged.neoforge.registries.ForgeRegistries; +import net.neoforged.neoforge.registries.RegistryObject; + +import java.util.function.Supplier; + +public class NeoForgeBalmRecipes 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); + } + +} diff --git a/shared/src/main/java/net/blay09/mods/balm/api/BalmRuntime.java b/shared/src/main/java/net/blay09/mods/balm/api/BalmRuntime.java index 0c410ce5..7a8ac5b7 100644 --- a/shared/src/main/java/net/blay09/mods/balm/api/BalmRuntime.java +++ b/shared/src/main/java/net/blay09/mods/balm/api/BalmRuntime.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; @@ -54,6 +55,8 @@ public interface BalmRuntime { BalmStats getStats(); + BalmRecipes getRecipes(); + boolean isModLoaded(String modId); String getModName(String modId); SidedProxy sidedProxy(String commonName, String clientName); 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 new file mode 100644 index 00000000..4827b686 --- /dev/null +++ b/shared/src/main/java/net/blay09/mods/balm/api/recipe/BalmRecipes.java @@ -0,0 +1,12 @@ +package net.blay09.mods.balm.api.recipe; + +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.RecipeType; + +import java.util.function.Supplier; + +public interface BalmRecipes { + > DeferredObject> registerRecipeType(Supplier> supplier, ResourceLocation identifier); +}