User Tools

Site Tools


tutorial:datagen_recipe

This is an old revision of the document!


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(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.1662883672.txt.gz · Last modified: 2022/09/11 08:07 by nexus-dino