Recipe Generation 1.21.4
A guide to setting up recipe generation with datagen.
WARNING
This page is written for version 1.21.4. Documentation for older versions may be incomplete.
PREREQUISITES
Make sure you've completed the datagen setup process first.
Setup
First, we'll need our provider. Make a class that extends FabricRecipeProvider. All our recipe generation will happen inside the generate method of our provider.
java
import java.util.List;
import java.util.concurrent.CompletableFuture;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.data.recipes.RecipeOutput;
import net.minecraft.data.recipes.RecipeProvider;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
public class FabricDocsReferenceRecipeProvider extends FabricRecipeProvider {
public FabricDocsReferenceRecipeProvider(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registriesFuture) {
super(output, registriesFuture);
}
@Override
protected RecipeProvider createRecipeProvider(HolderLookup.Provider registryLookup, RecipeOutput exporter) {
return new RecipeProvider(registryLookup, exporter) {
@Override
public void buildRecipes() {
HolderLookup.RegistryLookup<Item> itemLookup = registries.lookupOrThrow(Registries.ITEM);
}
};
}
@Override
public String getName() {
return "FabricDocsReferenceRecipeProvider";
}
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
To finish setup, add this provider to your DataGeneratorEntrypoint within the onInitializeDataGenerator method.
java
pack.addProvider(FabricDocsReferenceBlockLootTableProvider::new);1
Shapeless Recipes
Shapeless recipes are fairly straightforward. Just add them to the generate method in your provider:
java
shapeless(RecipeCategory.BUILDING_BLOCKS, Items.DIRT) // You can also specify an int to produce more than one
.requires(Items.COARSE_DIRT) // You can also specify an int to require more than one, or a tag to accept multiple things
// Create an advancement that gives you the recipe
.unlockedBy(getHasName(Items.COARSE_DIRT), has(Items.COARSE_DIRT))
.save(output);1
2
3
4
5
6
2
3
4
5
6
Shaped Recipes
For a shaped recipe, you define the shape using a String, then define what each char in the String represents.
java
shaped(RecipeCategory.MISC, Items.CRAFTING_TABLE, 4)
.pattern("ll")
.pattern("ll")
.define('l', ItemTags.LOGS) // 'l' means "any log"
.group("multi_bench") // Put it in a group called "multi_bench" - groups are shown in one slot in the recipe book
.unlockedBy(getHasName(Items.CRAFTING_TABLE), has(Items.CRAFTING_TABLE))
.save(output);
shaped(RecipeCategory.MISC, Items.LOOM, 4)
.pattern("ww")
.pattern("ll")
.define('w', ItemTags.WOOL) // 'w' means "any wool"
.define('l', ItemTags.LOGS)
.group("multi_bench")
.unlockedBy(getHasName(Items.LOOM), has(Items.LOOM))
.save(output);
doorBuilder(Items.OAK_DOOR, Ingredient.of(Items.OAK_BUTTON)) // Using a helper method!
.unlockedBy(getHasName(Items.OAK_BUTTON), has(Items.OAK_BUTTON))
.save(output);1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
TIP
There's a lot of helper methods for creating common recipes. Check out what RecipeProvider has to offer! Use Alt + 7 in IntelliJ to open the structure of a class, including a method list.
Other Recipes
Other recipes work similarly, but require a few extra parameters. For example, smelting recipes need to know how much experience to award.
java
oreSmelting(
List.of(Items.BREAD, Items.COOKIE, Items.HAY_BLOCK), // Inputs
RecipeCategory.FOOD, // Category
Items.WHEAT, // Output
0.1f, // Experience
300, // Cooking time
"food_to_wheat" // group
);1
2
3
4
5
6
7
8
2
3
4
5
6
7
8



