Skip to content

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.

  1. Write a recipe provider class for your loader.
  2. In the recipe method (buildRecipes), chain shaped recipe builder calls and save them.
  3. Register the provider with the data generator.
  4. Run the datagen task and check the recipe file it writes.

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.

The example mod is examplemod in the package com.example.examplemod. Use your own mod id and package.

Uses:

  • FabricRecipeProvider
  • ShapedRecipeBuilder.shaped
  • ShapedRecipeBuilder.pattern
  • ShapedRecipeBuilder.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.

Uses:

  • RecipeProvider
  • ShapedRecipeBuilder.shaped
  • ShapedRecipeBuilder.pattern
  • GatherDataEvent.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.

Uses:

  • FabricRecipeProvider
  • ShapedRecipeBuilder.shaped
  • ShapedRecipeBuilder.pattern
  • ShapedRecipeBuilder.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.

Uses:

  • FabricRecipeProvider
  • ShapedRecipeBuilder.shaped
  • ShapedRecipeBuilder.pattern
  • ShapedRecipeBuilder.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.

Uses:

  • RecipeProvider
  • ShapedRecipeBuilder.shaped
  • ShapedRecipeBuilder.pattern
  • GatherDataEvent.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.

Uses:

  • FabricRecipeProvider
  • ShapedRecipeBuilder.shaped
  • ShapedRecipeBuilder.pattern
  • ShapedRecipeBuilder.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.

Uses:

  • RecipeProvider
  • RecipeProvider.Runner
  • RecipeProvider.shaped
  • GatherDataEvent.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.

Uses:

  • RecipeProvider
  • RecipeProvider.Runner
  • RecipeProvider.shaped
  • ShapedRecipeBuilder.pattern
  • GatherDataEvent.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.

Uses:

  • FabricRecipeProvider
  • ShapedRecipeBuilder.shaped
  • ShapedRecipeBuilder.pattern
  • ShapedRecipeBuilder.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.

Uses:

  • RecipeProvider
  • RecipeProvider.asBootstrap
  • RecipeProvider.shaped
  • ShapedRecipeBuilder.pattern
  • PackGenerator.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.

Uses:

  • FabricRecipeProvider
  • ShapedRecipeBuilder.shaped
  • ShapedRecipeBuilder.pattern
  • ShapedRecipeBuilder.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.

Uses:

  • RecipeProvider
  • ShapedRecipeBuilder.shaped
  • ShapedRecipeBuilder.pattern
  • GatherDataEvent.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.

Uses:

  • RecipeProvider
  • ShapedRecipeBuilder.shaped
  • ShapedRecipeBuilder.pattern
  • GatherDataEvent.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.

Uses:

  • FabricRecipeProvider
  • ShapedRecipeBuilder.shaped
  • ShapedRecipeBuilder.pattern
  • ShapedRecipeBuilder.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.

Uses:

  • RecipeProvider.buildShapelessRecipes
  • ShapedRecipeBuilder.shaped
  • GatherDataEvent

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.

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.