Skip to content

Commit

Permalink
feat: Add recipe type registration
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Nov 19, 2023
1 parent 70633fc commit a64c3bc
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <T extends Recipe<?>> DeferredObject<RecipeType<T>> registerRecipeType(Supplier<RecipeType<T>> supplier, ResourceLocation identifier) {
return new DeferredObject<>(identifier, () -> {
RecipeType<T> recipeType = supplier.get();
recipeType = Registry.register(BuiltInRegistries.RECIPE_TYPE, identifier, recipeType);
return recipeType;
}).resolveImmediately();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String> addonClasses = new ArrayList<>();

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <T extends Recipe<?>> DeferredObject<RecipeType<T>> registerRecipeType(Supplier<RecipeType<T>> supplier, ResourceLocation identifier) {
DeferredRegister<RecipeType<?>> register = DeferredRegisters.get(ForgeRegistries.RECIPE_TYPES, identifier.getNamespace());
RegistryObject<RecipeType<T>> registryObject = register.register(identifier.getPath(), supplier);
return new DeferredObject<>(identifier, registryObject, registryObject::isPresent);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String> addonClasses = new ArrayList<>();

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <T extends Recipe<?>> DeferredObject<RecipeType<T>> registerRecipeType(Supplier<RecipeType<T>> supplier, ResourceLocation identifier) {
DeferredRegister<RecipeType<?>> register = DeferredRegisters.get(ForgeRegistries.RECIPE_TYPES, identifier.getNamespace());
RegistryObject<RecipeType<T>> registryObject = register.register(identifier.getPath(), supplier);
return new DeferredObject<>(identifier, registryObject, registryObject::isPresent);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,6 +55,8 @@ public interface BalmRuntime {

BalmStats getStats();

BalmRecipes getRecipes();

boolean isModLoaded(String modId);
String getModName(String modId);
<T> SidedProxy<T> sidedProxy(String commonName, String clientName);
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
<T extends Recipe<?>> DeferredObject<RecipeType<T>> registerRecipeType(Supplier<RecipeType<T>> supplier, ResourceLocation identifier);
}

0 comments on commit a64c3bc

Please sign in to comment.