User Tools

Site Tools


Sidebar

← Go back to the homepage

Fabric Tutorials

Setup

These pages will help you setup a productive development environment and semi-automated releases.

Basics

These pages are essential must-reads when modding with Fabric, and modding Minecraft in general, if you are new to modding, it is recommended you read the following.

Items

Blocks and Block Entities

Data Generation

World Generation

Commands

These pages will guide you through Mojang's Brigadier library which allows you to create commands with complex arguments and actions.

Events

These pages will guide you through using the many events included in Fabric API, and how to create your own events for you or other mods to use.

Entities

Fluids

Mixins & ASM

These pages will guide you through the usage of SpongePowered's Mixin library, which is a highly complex topic. We recommend you read these pages thoroughly.

Miscellaneous

Yarn

Contribute to Fabric

tutorial:datagen_recipe

To get started, create a class that extends FabricRecipeProvider, and register it in your datagen entrypoint like so:

private static class MyRecipeGenerator extends FabricRecipeProvider {
	private MyRecipeGenerator(FabricDataGenerator generator) {
                super(generator);
        }
 
        @Override
	protected void generateRecipes(Consumer<RecipeJsonProvider> exporter) {
                  // ...
        }
}
 
// ...
 
@Override
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
    // ...
    fabricDataGenerator.addProvider(MyRecipeGenerator::new);
    // ...
}

Adding A Shapeless Recipe

Now that you have your recipe generator, you can call different methods depending on what you want, in this example, we will create a recipe where a EXAMPLE_ITEM is given from EXAMPLE_BLOCK.

public static Block SIMPLE_BLOCK = Registry.register(Registry.BLOCK, new Identifier("mymod", "simple_block"), new Block(...));
public static BlockItem SIMPLE_ITEM = Registry.register(Registry.ITEM, new Identifier("mymod", "simple_item"), new Item(...));
// ...
 
@Override
protected void generateRecipes(Consumer<RecipeJsonProvider> exporter) {
          ShapelessRecipeJsonBuilder.create(SIMPLE_ITEM).input(SIMPLE_BLOCK).offerTo(exporter);
}

Adding A Smelting/Blasting/Smoking Recipe

Smelting/Blasting/Smoking recipes are quite similar to crafting recipes. The difference is that you use the CookingRecipeJsonBuilder:

public static final Block EXAMPLE_ORE = Registry.register(Registry.BLOCK, new Identifier("mymod", "example_ore"), new Block(...));
public static final Block DEEPSLATE_EXAMPLE_ORE = Registry.register(Registry.BLOCK, new Identifier("mymod", "deepslate_example_ore"), new Block(...));
public static final Item EXAMPLE_ORE_ITEM = Registry.register(Registry.ITEM, new Identifier("mymod", "example_ore"), new BlockItem(DEEPSLATE_EXAMPLE_ORE, ...));
public static final Item DEEPSLATE_EXAMPLE_ORE_ITEM = Registry.register(Registry.ITEM, new Identifier("mymod", "deepslate_example_ore"), new BlockItem(EXAMPLE_ORE, ...));
public static final Item RAW_EXAMPLE = Registry.register(Registry.ITEM, new Identifier("mymod", "raw_example"), new Item(...));
public static final Item EXAMPLE_INGOT = Registry.register(Registry.ITEM, new Identifier("mymod", "example_ingot"), new Item(...));
 
// Alternatively, you can just do List.of(...), but this is personal preference...
public static final List<ItemConvertible> SMELTABLE_TO_EXAMPLE_INGOT = Util.make(Lists.newArrayList(), list -> {
      list.add(EXAMPLE_ORE);
      list.add(DEEPSLATE_EXAMPLE_ORE);
      list.add(RAW_EXAMPLE);
});
 
@Override
protected void generateRecipes(Consumer<RecipeJsonProvider> exporter) {
	RecipeProvider.offerSmelting(exporter, SMELTABLE_TO_EXAMPLE_INGOT, EXAMPLE_INGOT, 0.45F, 300, "example");
}

Mojang has a lot of utility methods in RecipeProvider are available to use as well thanks to access wideners :)

tutorial/datagen_recipe.txt · Last modified: 2022/09/21 16:56 by nexus-dino