====== Recipe Generation ======
Before reading this, make sure you've read [[datagen_setup|Getting started with Data Generation]], and have a class that implements ''DataGenerationEntrypoint''
To begin, create a class that extends ''FabricRecipeProvider'', and register it in your datagen entrypoint like so:
private static class MyRecipeGenerator extends FabricRecipeProvider {
private MyRecipeGenerator(FabricDataOutput generator) {
super(generator);
}
@Override
protected void generateRecipes(Consumer 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 exporter) {
ShapelessRecipeJsonBuilder.create(RecipeCategory.BUILDING_BLOCKS, SIMPLE_ITEM).input(SIMPLE_BLOCK).criterion(FabricRecipeProvider.hasItem(SIMPLE_ITEM),
FabricRecipeProvider.conditionsFromItem(SIMPLE_ITEM)).criterion(FabricRecipeProvider.hasItem(SIMPLE_BLOCK),
FabricRecipeProvider.conditionsFromItem(SIMPLE_BLOCK)).offerTo(exporter);
}
===== Adding A Shaped Recipe =====
In this example, we will create a shaped recipe where a stone block is crafted from ''EXAMPLE_ITEM''s and ''EXAMPLE_BLOCK''s.
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 exporter) {
ShapedRecipeJsonBuilder.create(RecipeCategory.BUILDING_BLOCKS, Blocks.STONE_BLOCK).pattern("bbb").pattern("iii")
.input('b', SIMPLE_BLOCK)
.input('i', SIMPLE_ITEM)
.criterion(FabricRecipeProvider.hasItem(SIMPLE_ITEM),
FabricRecipeProvider.conditionsFromItem(SIMPLE_ITEM))
.criterion(FabricRecipeProvider.hasItem(SIMPLE_BLOCK),
FabricRecipeProvider.conditionsFromItem(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 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 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 :)