🇬🇧 English
🇬🇧 English
Appearance
🇬🇧 English
🇬🇧 English
Appearance
This page is written for version:
1.21
This page is written for version:
1.21
PREREQUISITES
Make sure you've completed the datagen setup process first.
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.
import java.util.List;
import java.util.concurrent.CompletableFuture;
import net.minecraft.data.server.recipe.RecipeExporter;
import net.minecraft.data.server.recipe.ShapedRecipeJsonBuilder;
import net.minecraft.data.server.recipe.ShapelessRecipeJsonBuilder;
import net.minecraft.item.Items;
import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.book.RecipeCategory;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.registry.tag.ItemTags;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;
public class FabricDocsReferenceRecipeProvider extends FabricRecipeProvider {
public FabricDocsReferenceRecipeProvider(FabricDataOutput output, CompletableFuture<RegistryWrapper.WrapperLookup> registriesFuture) {
super(output, registriesFuture);
}
@Override
public void generate(RecipeExporter recipeExporter) {
}
}
To finish setup, add this provider to your DataGeneratorEntrypoint
within the onInitializeDataGenerator
method.
pack.addProvider(FabricDocsReferenceRecipeProvider::new);
Shapeless recipes are fairly straightforward. Just add them to the generate
method in your provider:
ShapelessRecipeJsonBuilder.create(RecipeCategory.BUILDING_BLOCKS, Items.DIRT) // You can also specify an int to produce more than one
.input(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
.criterion(FabricRecipeProvider.hasItem(Items.COARSE_DIRT), FabricRecipeProvider.conditionsFromItem(Items.COARSE_DIRT))
.offerTo(recipeExporter);
For a shaped recipe, you define the shape using a String
, then define what each char
in the String
represents.
ShapedRecipeJsonBuilder.create(RecipeCategory.MISC, Items.CRAFTING_TABLE, 4)
.pattern("ll")
.pattern("ll")
.input('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
.criterion(FabricRecipeProvider.hasItem(Items.CRAFTING_TABLE), FabricRecipeProvider.conditionsFromItem(Items.CRAFTING_TABLE))
.offerTo(recipeExporter);
ShapedRecipeJsonBuilder.create(RecipeCategory.MISC, Items.LOOM, 4)
.pattern("ww")
.pattern("ll")
.input('w', ItemTags.WOOL) // 'w' means "any wool"
.input('l', ItemTags.LOGS)
.group("multi_bench")
.criterion(FabricRecipeProvider.hasItem(Items.LOOM), FabricRecipeProvider.conditionsFromItem(Items.LOOM))
.offerTo(recipeExporter);
FabricRecipeProvider.createDoorRecipe(Items.OAK_DOOR, Ingredient.ofItems(Items.OAK_BUTTON)) // Using a helper method!
.criterion(FabricRecipeProvider.hasItem(Items.OAK_BUTTON), FabricRecipeProvider.conditionsFromItem(Items.OAK_BUTTON))
.offerTo(recipeExporter);
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 work similarly, but require a few extra parameters. For example, smelting recipes need to know how much experience to award.
FabricRecipeProvider.offerSmelting(recipeExporter,
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
);