How to generate a crafting recipe with datagen (Minecraft mod)
A recipe provider writes recipe JSON from a short builder: a shaped recipe builder (ShapedRecipeBuilder.shaped(category, result, count); the category exists from 1.19.3, and from 1.21.2 the provider’s shaped method starts it), then pattern lines, define for each letter, unlockedBy for the recipe book, and save. The datagen task writes the file. Fabric: extend FabricRecipeProvider and fill buildRecipes. Forge and NeoForge: extend RecipeProvider and fill its recipe method, gathered in GatherDataEvent. Run ./gradlew runDatagen (Fabric) or runData (Forge and NeoForge).
Works on Minecraft 1.20.1 to 26.3 on NeoForge; Minecraft 1.18.2 to 26.3 on Fabric; Minecraft 1.16.5 to 1.20.1 on Forge. Each example was compiled against its loader and version before it shipped in Linen.
- Write a recipe provider class for your loader.
- In the recipe method (buildRecipes), chain shaped recipe builder calls and save them.
- Register the provider with the data generator.
- Run the datagen task and check the recipe file it writes.
What you can change
Section titled “What you can change”The example uses these values. Change them in the code.
| Setting | In the example | What it does |
|---|---|---|
| ingredient | IRON_INGOT |
What the recipe is made from. |
For each loader and version
Section titled “For each loader and version”The example mod is examplemod in the package com.example.examplemod. Use your own mod id and package.
Fabric 1.19.3 to 1.20.1
Section titled “Fabric 1.19.3 to 1.20.1”Uses:
FabricRecipeProviderShapedRecipeBuilder.shapedShapedRecipeBuilder.patternShapedRecipeBuilder.unlockedBy
Run ./gradlew runDatagen: the files are written to src/main/generated. Before 1.20.5 buildRecipes takes a Consumer<FinishedRecipe> instead of a RecipeOutput.
src/main/java/com/example/examplemod/datagen/ExampleModDataGenerator.java
package com.example.examplemod.datagen;
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
// Fabric API's datagen entrypoint ("fabric-datagen" in fabric.mod.json): ./gradlew runDatagen runs the providers added here.public class ExampleModDataGenerator implements DataGeneratorEntrypoint { @Override public void onInitializeDataGenerator(FabricDataGenerator generator) { FabricDataGenerator.Pack pack = generator.createPack(); }}src/main/java/com/example/examplemod/datagen/MarbleBlockRecipeProvider.java
package com.example.examplemod.datagen;
import com.example.examplemod.registry.ModBlocks;import java.util.function.Consumer;import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;import net.minecraft.data.recipes.RecipeCategory;import net.minecraft.data.recipes.FinishedRecipe;import net.minecraft.data.recipes.ShapedRecipeBuilder;import net.minecraft.world.item.Items;
// Writes the crafting recipe of Marble Block: eight IRON_INGOT in a ring. Runs only when datagen runs.public class MarbleBlockRecipeProvider extends FabricRecipeProvider { public MarbleBlockRecipeProvider(FabricDataOutput output) { super(output); }
@Override public void buildRecipes(Consumer<FinishedRecipe> output) { ShapedRecipeBuilder.shaped(RecipeCategory.BUILDING_BLOCKS, ModBlocks.MARBLE_BLOCK) .pattern("###") .pattern("# #") .pattern("###") .define('#', Items.IRON_INGOT) .unlockedBy("has_IRON_INGOT", has(Items.IRON_INGOT)) .save(output); }}In src/main/java/com/example/examplemod/datagen/ExampleModDataGenerator.java, inside onInitializeDataGenerator:
pack.addProvider(MarbleBlockRecipeProvider::new);In src/main/resources/fabric.mod.json, add this to the list at /entrypoints/fabric-datagen:
"com.example.examplemod.datagen.ExampleModDataGenerator"Add this line to build.gradle:
fabricApi { configureDataGeneration() { client = true } }It’s registered like any other block: see a new block.
NeoForge 1.20.1, Forge 1.19.3 to 1.20.1
Section titled “NeoForge 1.20.1, Forge 1.19.3 to 1.20.1”Uses:
RecipeProviderShapedRecipeBuilder.shapedShapedRecipeBuilder.patternGatherDataEvent.includeServer
Run ./gradlew runData: the files are written to src/generated/resources.
src/main/java/com/example/examplemod/datagen/MarbleBlockRecipeProvider.java
package com.example.examplemod.datagen;
import com.example.examplemod.registry.ModBlocks;import java.util.function.Consumer;import net.minecraft.data.PackOutput;import net.minecraft.data.recipes.RecipeCategory;import net.minecraft.data.recipes.FinishedRecipe;import net.minecraft.data.recipes.RecipeProvider;import net.minecraft.data.recipes.ShapedRecipeBuilder;import net.minecraft.world.item.Items;import net.minecraftforge.data.event.GatherDataEvent;
// Writes the crafting recipe of Marble Block: eight IRON_INGOT in a ring. Runs only when ./gradlew runData runs.public class MarbleBlockRecipeProvider extends RecipeProvider { public MarbleBlockRecipeProvider(PackOutput output) { super(output); }
@Override protected void buildRecipes(Consumer<FinishedRecipe> output) { ShapedRecipeBuilder.shaped(RecipeCategory.BUILDING_BLOCKS, ModBlocks.MARBLE_BLOCK.get()) .pattern("###") .pattern("# #") .pattern("###") .define('#', Items.IRON_INGOT) .unlockedBy("has_IRON_INGOT", has(Items.IRON_INGOT)) .save(output); }
// Listens on the mod event bus (the mod's constructor) when datagen runs. public static void gather(GatherDataEvent event) { event.getGenerator().addProvider(event.includeServer(), new MarbleBlockRecipeProvider(event.getGenerator().getPackOutput())); }}In your main mod class, inside <init>:
modEventBus.addListener(MarbleBlockRecipeProvider::gather);It’s registered like any other block: see a new block.
Fabric 1.20.2 to 1.20.4
Section titled “Fabric 1.20.2 to 1.20.4”Uses:
FabricRecipeProviderShapedRecipeBuilder.shapedShapedRecipeBuilder.patternShapedRecipeBuilder.unlockedBy
Run ./gradlew runDatagen: the files are written to src/main/generated. Before 1.20.5 FabricRecipeProvider takes only the FabricDataOutput.
src/main/java/com/example/examplemod/datagen/ExampleModDataGenerator.java
package com.example.examplemod.datagen;
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
// Fabric API's datagen entrypoint ("fabric-datagen" in fabric.mod.json): ./gradlew runDatagen runs the providers added here.public class ExampleModDataGenerator implements DataGeneratorEntrypoint { @Override public void onInitializeDataGenerator(FabricDataGenerator generator) { FabricDataGenerator.Pack pack = generator.createPack(); }}src/main/java/com/example/examplemod/datagen/MarbleBlockRecipeProvider.java
package com.example.examplemod.datagen;
import com.example.examplemod.registry.ModBlocks;import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;import net.minecraft.data.recipes.RecipeCategory;import net.minecraft.data.recipes.RecipeOutput;import net.minecraft.data.recipes.ShapedRecipeBuilder;import net.minecraft.world.item.Items;
// Writes the crafting recipe of Marble Block: eight IRON_INGOT in a ring. Runs only when datagen runs.public class MarbleBlockRecipeProvider extends FabricRecipeProvider { public MarbleBlockRecipeProvider(FabricDataOutput output) { super(output); }
@Override public void buildRecipes(RecipeOutput output) { ShapedRecipeBuilder.shaped(RecipeCategory.BUILDING_BLOCKS, ModBlocks.MARBLE_BLOCK) .pattern("###") .pattern("# #") .pattern("###") .define('#', Items.IRON_INGOT) .unlockedBy("has_IRON_INGOT", has(Items.IRON_INGOT)) .save(output); }}In src/main/java/com/example/examplemod/datagen/ExampleModDataGenerator.java, inside onInitializeDataGenerator:
pack.addProvider(MarbleBlockRecipeProvider::new);In src/main/resources/fabric.mod.json, add this to the list at /entrypoints/fabric-datagen:
"com.example.examplemod.datagen.ExampleModDataGenerator"Add this line to build.gradle:
fabricApi { configureDataGeneration() { client = true } }It’s registered like any other block: see a new block.
Fabric 1.20.5 to 1.21.1
Section titled “Fabric 1.20.5 to 1.21.1”Uses:
FabricRecipeProviderShapedRecipeBuilder.shapedShapedRecipeBuilder.patternShapedRecipeBuilder.unlockedBy
Run ./gradlew runDatagen: the files are written to src/main/generated.
src/main/java/com/example/examplemod/datagen/ExampleModDataGenerator.java
package com.example.examplemod.datagen;
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
// Fabric API's datagen entrypoint ("fabric-datagen" in fabric.mod.json): ./gradlew runDatagen runs the providers added here.public class ExampleModDataGenerator implements DataGeneratorEntrypoint { @Override public void onInitializeDataGenerator(FabricDataGenerator generator) { FabricDataGenerator.Pack pack = generator.createPack(); }}src/main/java/com/example/examplemod/datagen/MarbleBlockRecipeProvider.java
package com.example.examplemod.datagen;
import com.example.examplemod.registry.ModBlocks;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.data.recipes.RecipeCategory;import net.minecraft.data.recipes.RecipeOutput;import net.minecraft.data.recipes.ShapedRecipeBuilder;import net.minecraft.world.item.Items;
// Writes the crafting recipe of Marble Block: eight IRON_INGOT in a ring. Runs only when datagen runs.public class MarbleBlockRecipeProvider extends FabricRecipeProvider { public MarbleBlockRecipeProvider(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registries) { super(output, registries); }
@Override public void buildRecipes(RecipeOutput output) { ShapedRecipeBuilder.shaped(RecipeCategory.BUILDING_BLOCKS, ModBlocks.MARBLE_BLOCK) .pattern("###") .pattern("# #") .pattern("###") .define('#', Items.IRON_INGOT) .unlockedBy("has_IRON_INGOT", has(Items.IRON_INGOT)) .save(output); }}In src/main/java/com/example/examplemod/datagen/ExampleModDataGenerator.java, inside onInitializeDataGenerator:
pack.addProvider(MarbleBlockRecipeProvider::new);In src/main/resources/fabric.mod.json, add this to the list at /entrypoints/fabric-datagen:
"com.example.examplemod.datagen.ExampleModDataGenerator"Add this line to build.gradle:
fabricApi { configureDataGeneration() { client = true } }It’s registered like any other block: see a new block.
NeoForge 1.20.2 to 1.21.1
Section titled “NeoForge 1.20.2 to 1.21.1”Uses:
RecipeProviderShapedRecipeBuilder.shapedShapedRecipeBuilder.patternGatherDataEvent.includeServer
Run ./gradlew runData: the files are written to src/generated/resources.
src/main/java/com/example/examplemod/datagen/MarbleBlockRecipeProvider.java
package com.example.examplemod.datagen;
import com.example.examplemod.registry.ModBlocks;import java.util.concurrent.CompletableFuture;import net.minecraft.core.HolderLookup;import net.minecraft.data.PackOutput;import net.minecraft.data.recipes.RecipeCategory;import net.minecraft.data.recipes.RecipeOutput;import net.minecraft.data.recipes.RecipeProvider;import net.minecraft.data.recipes.ShapedRecipeBuilder;import net.minecraft.world.item.Items;import net.neoforged.neoforge.data.event.GatherDataEvent;
// Writes the crafting recipe of Marble Block: eight IRON_INGOT in a ring. Runs only when ./gradlew runData runs.public class MarbleBlockRecipeProvider extends RecipeProvider { public MarbleBlockRecipeProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> registries) { super(output, registries); }
@Override protected void buildRecipes(RecipeOutput output) { ShapedRecipeBuilder.shaped(RecipeCategory.BUILDING_BLOCKS, ModBlocks.MARBLE_BLOCK.get()) .pattern("###") .pattern("# #") .pattern("###") .define('#', Items.IRON_INGOT) .unlockedBy("has_IRON_INGOT", has(Items.IRON_INGOT)) .save(output); }
// Listens on the mod event bus (the mod's constructor) when datagen runs. public static void gather(GatherDataEvent event) { event.getGenerator().addProvider(event.includeServer(), new MarbleBlockRecipeProvider(event.getGenerator().getPackOutput(), event.getLookupProvider())); }}In your main mod class, inside <init>:
modEventBus.addListener(MarbleBlockRecipeProvider::gather);It’s registered like any other block: see a new block.
Fabric 1.21.2 to 1.21.11
Section titled “Fabric 1.21.2 to 1.21.11”Uses:
FabricRecipeProviderShapedRecipeBuilder.shapedShapedRecipeBuilder.patternShapedRecipeBuilder.unlockedBy
Run ./gradlew runDatagen: the files are written to src/main/generated.
src/main/java/com/example/examplemod/datagen/ExampleModDataGenerator.java
package com.example.examplemod.datagen;
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
// Fabric API's datagen entrypoint ("fabric-datagen" in fabric.mod.json): ./gradlew runDatagen runs the providers added here.public class ExampleModDataGenerator implements DataGeneratorEntrypoint { @Override public void onInitializeDataGenerator(FabricDataGenerator generator) { FabricDataGenerator.Pack pack = generator.createPack(); }}src/main/java/com/example/examplemod/datagen/MarbleBlockRecipeProvider.java
package com.example.examplemod.datagen;
import com.example.examplemod.registry.ModBlocks;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.data.recipes.RecipeCategory;import net.minecraft.data.recipes.RecipeOutput;import net.minecraft.data.recipes.RecipeProvider;import net.minecraft.world.item.Items;
// Writes the crafting recipe of Marble Block: eight IRON_INGOT in a ring. Runs only when datagen runs.public class MarbleBlockRecipeProvider extends FabricRecipeProvider { public MarbleBlockRecipeProvider(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registries) { super(output, registries); }
@Override protected RecipeProvider createRecipeProvider(HolderLookup.Provider registries, RecipeOutput output) { return new RecipeProvider(registries, output) { @Override public void buildRecipes() { shaped(RecipeCategory.BUILDING_BLOCKS, ModBlocks.MARBLE_BLOCK) .pattern("###") .pattern("# #") .pattern("###") .define('#', Items.IRON_INGOT) .unlockedBy("has_IRON_INGOT", has(Items.IRON_INGOT)) .save(output); } }; }
@Override public String getName() { return "MarbleBlock recipes"; }}In src/main/java/com/example/examplemod/datagen/ExampleModDataGenerator.java, inside onInitializeDataGenerator:
pack.addProvider(MarbleBlockRecipeProvider::new);In src/main/resources/fabric.mod.json, add this to the list at /entrypoints/fabric-datagen:
"com.example.examplemod.datagen.ExampleModDataGenerator"Add this line to build.gradle:
fabricApi { configureDataGeneration() { client = true } }It’s registered like any other block: see a new block.
NeoForge 1.21.2 to 1.21.3
Section titled “NeoForge 1.21.2 to 1.21.3”Uses:
RecipeProviderRecipeProvider.RunnerRecipeProvider.shapedGatherDataEvent.includeServer
Run ./gradlew runData: the files are written to src/generated/resources.
src/main/java/com/example/examplemod/datagen/MarbleBlockRecipeProvider.java
package com.example.examplemod.datagen;
import com.example.examplemod.registry.ModBlocks;import java.util.concurrent.CompletableFuture;import net.minecraft.core.HolderLookup;import net.minecraft.data.PackOutput;import net.minecraft.data.recipes.RecipeCategory;import net.minecraft.data.recipes.RecipeOutput;import net.minecraft.data.recipes.RecipeProvider;import net.minecraft.world.item.Items;import net.neoforged.neoforge.data.event.GatherDataEvent;
// Writes the crafting recipe of Marble Block: eight IRON_INGOT in a ring. Runs only when ./gradlew runData runs.public class MarbleBlockRecipeProvider extends RecipeProvider { protected MarbleBlockRecipeProvider(HolderLookup.Provider registries, RecipeOutput output) { super(registries, output); }
@Override protected void buildRecipes() { shaped(RecipeCategory.BUILDING_BLOCKS, ModBlocks.MARBLE_BLOCK.get()) .pattern("###") .pattern("# #") .pattern("###") .define('#', Items.IRON_INGOT) .unlockedBy("has_IRON_INGOT", has(Items.IRON_INGOT)) .save(output); }
// Since 1.21.2 the game runs a recipe provider through a Runner, which is the data provider. public static class Runner extends RecipeProvider.Runner { public Runner(PackOutput output, CompletableFuture<HolderLookup.Provider> registries) { super(output, registries); }
@Override protected RecipeProvider createRecipeProvider(HolderLookup.Provider registries, RecipeOutput output) { return new MarbleBlockRecipeProvider(registries, output); }
@Override public String getName() { return "Marble Block recipes"; } }
// Listens on the mod event bus (the mod's constructor) when datagen runs; only when server data is generated. public static void gather(GatherDataEvent event) { event.getGenerator().addProvider(event.includeServer(), new Runner(event.getGenerator().getPackOutput(), event.getLookupProvider())); }}In your main mod class, inside <init>:
modEventBus.addListener(MarbleBlockRecipeProvider::gather);It’s registered like any other block: see a new block.
NeoForge 1.21.4 to 26.2
Section titled “NeoForge 1.21.4 to 26.2”Uses:
RecipeProviderRecipeProvider.RunnerRecipeProvider.shapedShapedRecipeBuilder.patternGatherDataEvent.Server.createProvider
Run ./gradlew runData: the files are written to src/generated/resources.
src/main/java/com/example/examplemod/datagen/MarbleBlockRecipeProvider.java
package com.example.examplemod.datagen;
import com.example.examplemod.registry.ModBlocks;import java.util.concurrent.CompletableFuture;import net.minecraft.core.HolderLookup;import net.minecraft.data.PackOutput;import net.minecraft.data.recipes.RecipeCategory;import net.minecraft.data.recipes.RecipeOutput;import net.minecraft.data.recipes.RecipeProvider;import net.minecraft.world.item.Items;import net.neoforged.neoforge.data.event.GatherDataEvent;
// Writes the crafting recipe of Marble Block: eight IRON_INGOT in a ring. Runs only when ./gradlew runData runs.public class MarbleBlockRecipeProvider extends RecipeProvider { protected MarbleBlockRecipeProvider(HolderLookup.Provider registries, RecipeOutput output) { super(registries, output); }
@Override protected void buildRecipes() { shaped(RecipeCategory.BUILDING_BLOCKS, ModBlocks.MARBLE_BLOCK.get()) .pattern("###") .pattern("# #") .pattern("###") .define('#', Items.IRON_INGOT) .unlockedBy("has_IRON_INGOT", has(Items.IRON_INGOT)) .save(output); }
// Since 1.21.4 the game runs a recipe provider through a Runner, which is the data provider. public static class Runner extends RecipeProvider.Runner { public Runner(PackOutput output, CompletableFuture<HolderLookup.Provider> registries) { super(output, registries); }
@Override protected RecipeProvider createRecipeProvider(HolderLookup.Provider registries, RecipeOutput output) { return new MarbleBlockRecipeProvider(registries, output); }
@Override public String getName() { return "Marble Block recipes"; } }
// Listens on the mod event bus (the mod's constructor) when datagen runs; recipes are server data. public static void gather(GatherDataEvent.Server event) { event.createProvider(Runner::new); }}In your main mod class, inside <init>:
modEventBus.addListener(MarbleBlockRecipeProvider::gather);It’s registered like any other block: see a new block.
Fabric 26.1 to 26.2
Section titled “Fabric 26.1 to 26.2”Uses:
FabricRecipeProviderShapedRecipeBuilder.shapedShapedRecipeBuilder.patternShapedRecipeBuilder.unlockedBy
Run ./gradlew runDatagen: the files are written to src/main/generated.
src/main/java/com/example/examplemod/datagen/ExampleModDataGenerator.java
package com.example.examplemod.datagen;
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
// Fabric API's datagen entrypoint ("fabric-datagen" in fabric.mod.json): ./gradlew runDatagen runs the providers added here.public class ExampleModDataGenerator implements DataGeneratorEntrypoint { @Override public void onInitializeDataGenerator(FabricDataGenerator generator) { FabricDataGenerator.Pack pack = generator.createPack(); }}src/main/java/com/example/examplemod/datagen/MarbleBlockRecipeProvider.java
package com.example.examplemod.datagen;
import com.example.examplemod.registry.ModBlocks;import java.util.concurrent.CompletableFuture;import net.fabricmc.fabric.api.datagen.v1.FabricPackOutput;import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;import net.minecraft.core.HolderLookup;import net.minecraft.data.recipes.RecipeCategory;import net.minecraft.data.recipes.RecipeOutput;import net.minecraft.data.recipes.RecipeProvider;import net.minecraft.world.item.Items;
// Writes the crafting recipe of Marble Block: eight IRON_INGOT in a ring. Runs only when datagen runs.public class MarbleBlockRecipeProvider extends FabricRecipeProvider { public MarbleBlockRecipeProvider(FabricPackOutput output, CompletableFuture<HolderLookup.Provider> registries) { super(output, registries); }
@Override protected RecipeProvider createRecipeProvider(HolderLookup.Provider registries, RecipeOutput output) { return new RecipeProvider(registries, output) { @Override public void buildRecipes() { shaped(RecipeCategory.BUILDING_BLOCKS, ModBlocks.MARBLE_BLOCK) .pattern("###") .pattern("# #") .pattern("###") .define('#', Items.IRON_INGOT) .unlockedBy("has_IRON_INGOT", has(Items.IRON_INGOT)) .save(output); } }; }
@Override public String getName() { return "MarbleBlock recipes"; }}In src/main/java/com/example/examplemod/datagen/ExampleModDataGenerator.java, inside onInitializeDataGenerator:
pack.addProvider(MarbleBlockRecipeProvider::new);In src/main/resources/fabric.mod.json, add this to the list at /entrypoints/fabric-datagen:
"com.example.examplemod.datagen.ExampleModDataGenerator"Add this line to build.gradle:
fabricApi { configureDataGeneration() { client = true } }It’s registered like any other block: see a new block.
NeoForge 26.3
Section titled “NeoForge 26.3”Uses:
RecipeProviderRecipeProvider.asBootstrapRecipeProvider.shapedShapedRecipeBuilder.patternPackGenerator.createReloadableRegistryObjects
Since 26.3 a recipe provider is registered as reloadable registry objects (RecipeProvider.asBootstrap) instead of a data provider Runner.
src/main/java/com/example/examplemod/datagen/MarbleBlockRecipeProvider.java
package com.example.examplemod.datagen;
import com.example.examplemod.registry.ModBlocks;import net.minecraft.advancements.Advancement;import net.minecraft.core.RegistrySetBuilder;import net.minecraft.data.recipes.RecipeCategory;import net.minecraft.data.recipes.RecipeProvider;import net.minecraft.data.worldgen.BootstrapContext;import net.minecraft.world.item.Items;import net.minecraft.world.item.crafting.Recipe;import net.neoforged.neoforge.data.event.GatherDataEvent;
// Writes the crafting recipe of Marble Block: eight IRON_INGOT in a ring. Runs only when ./gradlew runData runs.public class MarbleBlockRecipeProvider extends RecipeProvider { protected MarbleBlockRecipeProvider(BootstrapContext<Recipe<?>> recipes, BootstrapContext<Advancement> advancements) { super(recipes, advancements); }
@Override protected void buildRecipes() { shaped(RecipeCategory.BUILDING_BLOCKS, ModBlocks.MARBLE_BLOCK.get()) .pattern("###") .pattern("# #") .pattern("###") .define('#', Items.IRON_INGOT) .unlockedBy("has_IRON_INGOT", has(Items.IRON_INGOT)) .save(output); }
// Listens on the mod event bus (the mod's constructor) when datagen runs. Since 26.3 recipes and their advancements are reloadable registry objects. public static void gather(GatherDataEvent.Server event) { event.getDefaultPackGenerator().createReloadableRegistryObjects(new RegistrySetBuilder().add(RecipeProvider.asBootstrap(MarbleBlockRecipeProvider::new))); }}In your main mod class, inside <init>:
modEventBus.addListener(MarbleBlockRecipeProvider::gather);It’s registered like any other block: see a new block.
Fabric 26.3
Section titled “Fabric 26.3”Uses:
FabricRecipeProviderShapedRecipeBuilder.shapedShapedRecipeBuilder.patternShapedRecipeBuilder.unlockedBy
Run ./gradlew runDatagen: the files are written to src/main/generated.
src/main/java/com/example/examplemod/datagen/ExampleModDataGenerator.java
package com.example.examplemod.datagen;
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
// Fabric API's datagen entrypoint ("fabric-datagen" in fabric.mod.json): ./gradlew runDatagen runs the providers added here.public class ExampleModDataGenerator implements DataGeneratorEntrypoint { @Override public void onInitializeDataGenerator(FabricDataGenerator generator) { FabricDataGenerator.Pack pack = generator.createPack(); }}src/main/java/com/example/examplemod/datagen/MarbleBlockRecipeProvider.java
package com.example.examplemod.datagen;
import com.example.examplemod.registry.ModBlocks;import java.util.concurrent.CompletableFuture;import net.fabricmc.fabric.api.datagen.v1.FabricPackOutput;import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;import net.minecraft.advancements.Advancement;import net.minecraft.core.HolderLookup;import net.minecraft.data.recipes.RecipeCategory;import net.minecraft.data.recipes.RecipeProvider;import net.minecraft.data.worldgen.BootstrapContext;import net.minecraft.world.item.Items;import net.minecraft.world.item.crafting.Recipe;
// Writes the crafting recipe of Marble Block: eight IRON_INGOT in a ring. Runs only when datagen runs.public class MarbleBlockRecipeProvider extends FabricRecipeProvider { public MarbleBlockRecipeProvider(FabricPackOutput output, CompletableFuture<HolderLookup.Provider> registries) { super(output, registries); }
@Override protected RecipeProvider createRecipeProvider(HolderLookup.Provider registries, BootstrapContext<Recipe<?>> recipes, BootstrapContext<Advancement> advancements) { return new RecipeProvider(recipes, advancements) { @Override public void buildRecipes() { shaped(RecipeCategory.BUILDING_BLOCKS, ModBlocks.MARBLE_BLOCK) .pattern("###") .pattern("# #") .pattern("###") .define('#', Items.IRON_INGOT) .unlockedBy("has_IRON_INGOT", has(Items.IRON_INGOT)) .save(output); } }; }
@Override public String getName() { return "MarbleBlock recipes"; }}In src/main/java/com/example/examplemod/datagen/ExampleModDataGenerator.java, inside onInitializeDataGenerator:
pack.addProvider(MarbleBlockRecipeProvider::new);In src/main/resources/fabric.mod.json, add this to the list at /entrypoints/fabric-datagen:
"com.example.examplemod.datagen.ExampleModDataGenerator"Add this line to build.gradle:
fabricApi { configureDataGeneration() { client = true } }It’s registered like any other block: see a new block.
Forge 1.17.1 to 1.18.2
Section titled “Forge 1.17.1 to 1.18.2”Uses:
RecipeProviderShapedRecipeBuilder.shapedShapedRecipeBuilder.patternGatherDataEvent.includeServer
Run ./gradlew runData: the files are written to src/generated/resources.
src/main/java/com/example/examplemod/datagen/MarbleBlockRecipeProvider.java
package com.example.examplemod.datagen;
import com.example.examplemod.registry.ModBlocks;import java.util.function.Consumer;import net.minecraft.data.DataGenerator;import net.minecraft.data.recipes.FinishedRecipe;import net.minecraft.data.recipes.RecipeProvider;import net.minecraft.data.recipes.ShapedRecipeBuilder;import net.minecraft.world.item.Items;import net.minecraftforge.forge.event.lifecycle.GatherDataEvent;
// Writes the crafting recipe of Marble Block: eight IRON_INGOT in a ring. Runs only when ./gradlew runData runs.public class MarbleBlockRecipeProvider extends RecipeProvider { public MarbleBlockRecipeProvider(DataGenerator generator) { super(generator); }
@Override protected void buildCraftingRecipes(Consumer<FinishedRecipe> output) { ShapedRecipeBuilder.shaped(ModBlocks.MARBLE_BLOCK.get()) .pattern("###") .pattern("# #") .pattern("###") .define('#', Items.IRON_INGOT) .unlockedBy("has_IRON_INGOT", has(Items.IRON_INGOT)) .save(output); }
// Listens on the mod event bus (the mod's constructor) when datagen runs. public static void gather(GatherDataEvent event) { if (event.includeServer()) { event.getGenerator().addProvider(new MarbleBlockRecipeProvider(event.getGenerator())); } }}In your main mod class, inside <init>:
modEventBus.addListener(MarbleBlockRecipeProvider::gather);It’s registered like any other block: see a new block.
Forge 1.19 to 1.19.2
Section titled “Forge 1.19 to 1.19.2”Uses:
RecipeProviderShapedRecipeBuilder.shapedShapedRecipeBuilder.patternGatherDataEvent.includeServer
Run ./gradlew runData: the files are written to src/generated/resources.
src/main/java/com/example/examplemod/datagen/MarbleBlockRecipeProvider.java
package com.example.examplemod.datagen;
import com.example.examplemod.registry.ModBlocks;import java.util.function.Consumer;import net.minecraft.data.DataGenerator;import net.minecraft.data.recipes.FinishedRecipe;import net.minecraft.data.recipes.RecipeProvider;import net.minecraft.data.recipes.ShapedRecipeBuilder;import net.minecraft.world.item.Items;import net.minecraftforge.data.event.GatherDataEvent;
// Writes the crafting recipe of Marble Block: eight IRON_INGOT in a ring. Runs only when ./gradlew runData runs.public class MarbleBlockRecipeProvider extends RecipeProvider { public MarbleBlockRecipeProvider(DataGenerator generator) { super(generator); }
@Override protected void buildCraftingRecipes(Consumer<FinishedRecipe> output) { ShapedRecipeBuilder.shaped(ModBlocks.MARBLE_BLOCK.get()) .pattern("###") .pattern("# #") .pattern("###") .define('#', Items.IRON_INGOT) .unlockedBy("has_IRON_INGOT", has(Items.IRON_INGOT)) .save(output); }
// Listens on the mod event bus (the mod's constructor) when datagen runs. public static void gather(GatherDataEvent event) { event.getGenerator().addProvider(event.includeServer(), new MarbleBlockRecipeProvider(event.getGenerator())); }}In your main mod class, inside <init>:
modEventBus.addListener(MarbleBlockRecipeProvider::gather);It’s registered like any other block: see a new block.
Fabric 1.18.2 to 1.19.2
Section titled “Fabric 1.18.2 to 1.19.2”Uses:
FabricRecipeProviderShapedRecipeBuilder.shapedShapedRecipeBuilder.patternShapedRecipeBuilder.unlockedBy
src/main/java/com/example/examplemod/datagen/ExampleModDataGenerator.java
package com.example.examplemod.datagen;
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
// Fabric API's datagen entrypoint ("fabric-datagen" in fabric.mod.json): ./gradlew runDatagen runs the providers added here.public class ExampleModDataGenerator implements DataGeneratorEntrypoint { @Override public void onInitializeDataGenerator(FabricDataGenerator generator) { }}src/main/java/com/example/examplemod/datagen/MarbleBlockRecipeProvider.java
package com.example.examplemod.datagen;
import com.example.examplemod.registry.ModBlocks;import java.util.function.Consumer;import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;import net.minecraft.data.recipes.FinishedRecipe;import net.minecraft.data.recipes.ShapedRecipeBuilder;import net.minecraft.world.item.Items;
// Writes the crafting recipe of Marble Block: eight IRON_INGOT in a ring. Runs only when datagen runs.public class MarbleBlockRecipeProvider extends FabricRecipeProvider { public MarbleBlockRecipeProvider(FabricDataGenerator generator) { super(generator); }
@Override protected void generateRecipes(Consumer<FinishedRecipe> output) { ShapedRecipeBuilder.shaped(ModBlocks.MARBLE_BLOCK) .pattern("###") .pattern("# #") .pattern("###") .define('#', Items.IRON_INGOT) .unlockedBy("has_IRON_INGOT", has(Items.IRON_INGOT)) .save(output); }}In src/main/java/com/example/examplemod/datagen/ExampleModDataGenerator.java, inside onInitializeDataGenerator:
generator.addProvider(MarbleBlockRecipeProvider::new);In src/main/resources/fabric.mod.json, add this to the list at /entrypoints/fabric-datagen:
"com.example.examplemod.datagen.ExampleModDataGenerator"Add this line to build.gradle:
fabricApi { configureDataGeneration() { client = true } }It’s registered like any other block: see a new block.
Forge 1.16.5
Section titled “Forge 1.16.5”Uses:
RecipeProvider.buildShapelessRecipesShapedRecipeBuilder.shapedGatherDataEvent
Run ./gradlew runData: the files are written to src/generated/resources.
src/main/java/com/example/examplemod/datagen/MarbleBlockRecipeProvider.java
package com.example.examplemod.datagen;
import com.example.examplemod.registry.ModBlocks;import java.util.function.Consumer;import net.minecraft.data.DataGenerator;import net.minecraft.data.IFinishedRecipe;import net.minecraft.data.RecipeProvider;import net.minecraft.data.ShapedRecipeBuilder;import net.minecraft.item.Items;import net.minecraftforge.fml.event.lifecycle.GatherDataEvent;
// Writes the crafting recipe of Marble Block: eight IRON_INGOT in a ring. Runs only when ./gradlew runData runs.public class MarbleBlockRecipeProvider extends RecipeProvider { public MarbleBlockRecipeProvider(DataGenerator generator) { super(generator); }
// In 1.16.5 the method that builds the recipes is named buildShapelessRecipes, whatever it builds. @Override protected void buildShapelessRecipes(Consumer<IFinishedRecipe> output) { ShapedRecipeBuilder.shaped(ModBlocks.MARBLE_BLOCK.get()) .pattern("###") .pattern("# #") .pattern("###") .define('#', Items.IRON_INGOT) .unlockedBy("has_IRON_INGOT", has(Items.IRON_INGOT)) .save(output); }
// Listens on the mod event bus (the mod's constructor) when datagen runs. public static void gather(GatherDataEvent event) { if (event.includeServer()) { event.getGenerator().addProvider(new MarbleBlockRecipeProvider(event.getGenerator())); } }}In your main mod class, inside <init>:
modEventBus.addListener(MarbleBlockRecipeProvider::gather);It’s registered like any other block: see a new block.
Sources
Section titled “Sources”- https://docs.fabricmc.net/1.21.1/develop/data-generation/setup
- https://docs.neoforged.net/docs/1.21.1/resources/server/recipes/
- https://docs.neoforged.net/docs/1.21.1/resources/
Related how-tos
Section titled “Related how-tos”In Linen
Section titled “In Linen”Linen’s How-tos library has this page too, with the example for your own mod’s loader and Minecraft version. Hover a name in your code and Linen points to the how-tos that explain it. Both are free. Download Linen.