-
Notifications
You must be signed in to change notification settings - Fork 0
Recipe Book
This page covers the Recipe Book module of Dark Matter.
This module requires
enums
andminecraft
Recipe Book allows you to create new recipe book categories and groups, modify existing ones, add new recipe predicates, and also patches the recipe book to allow multiple pages of groups.
The RecipeBookHelper class provides utility methods for managing recipe book categories and groups.
Allows you to create a new recipe category. New categories must be present on both client and server!
public class CoolMod implements ModInitializer {
public static RecipeBookCategory FLETCHING;
@Override
public void onInitialize() {
FLETCHING = RecipeBookHelper.createCategory(new Identifier("modid", "fletching"));
}
}
Allows you to create client-only recipe book groups. It's recommended to always create a search group.
public class CoolModClient implements ClientModInitializer {
public static RecipeBookGroup COOKING_POT_SEARCH;
public static RecipeBookGroup COOKING_POT_MAIN;
@Override
public void onInitializeClient() {
COOKING_POT_SEARCH = RecipeBookHelper.createGroup(new Identifier("modid", "cooking_pot/search"), Items.COMPASS.getDefaultStack());
COOKING_POT_MAIN = RecipeBookHelper.createGroup(new Identifier("modid", "cooking_pot/main"), Items.BEETROOT_SOUP.getDefaultStack());
}
}
After creating your groups and categories, you will probably want to link them together and mark your search group as... a search group.
The first parameter is your category, the second is your search group, and then a list of all your categories in the order you want them to appear.
RecipeBookHelper.registerAndAddToSearch(COOKING_POT, COOKING_POT_SEARCH, List.of(COOKING_POT_SEARCH, COOKING_POT_MAIN));
But if you want to extend another mod's category, how do you avoid adding your groups before that mod? You can use FabricLoader's ObjectShare. You will need to ask the mod author to add this after they have created and registered their groups:
FabricLoader.getInstance().getObjectShare().put("modid:created_groups", COOKING_POT);
That way, if your add-on loads before the mod, you can ask FabricLoader to wait until the mod is initialized, just like this:
FabricLoader.getInstance().getObjectShare().whenAvailable("modid:created_groups", (s, o) -> {
if (o instanceof RecipeBookCategory) {
//do registration here. Including lookups.
}
});
Allows you to register a new group lookup. A lookup is a function which receives a recipe and returns a recipe book group. A lookup is linked to a recipe type. Last added lookups always run first.
For example:
RecipeBookHelper.registerGroupLookup(RecipeType.CRAFTING, recipe -> {
if ("new-redstone".equals(recipe.getId().getNamespace())) {
return RecipeBookGroup.CRAFTING_REDSTONE;
}
return null;
});
In 1.20+ you can receive a DynamicRegistryManager. Please note, the registry manager might* be null. Here's how this looks:
RecipeBookHelper.registerGroupLookup(RecipeType.CRAFTING, (recipe, dynamicRegistryManager) -> {
ItemStack stack = recipe.getOutput(dynamicRegistryManager);
if (stack.isIn(ItemTags.BOATS) || stack.isIn(ItemTags.CHEST_BOATS)) {
return MY_MOD_TRANSPORTATION;
}
return null;
});
The module also patches the recipe book widget to allow more than 6 categories via pages. This is similar to what Fabric API does with item groups.
Another thing this module does is convert immutable lists/maps to mutable counterparts. This allows you to add new groups to vanilla categories.
See those patches in action with Recipe Book is Pain. All versions since 0.10.0 use Dark Matter.
Dark Matter wiki by constellation-mc is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.