🇬🇧 English
🇬🇧 English
Appearance
🇬🇧 English
🇬🇧 English
Appearance
This page is written for version:
1.21.4
This page is written for version:
1.21.4
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.recipe.RecipeExporter;
import net.minecraft.data.recipe.RecipeGenerator;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.book.RecipeCategory;
import net.minecraft.registry.RegistryKeys;
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
protected RecipeGenerator getRecipeGenerator(RegistryWrapper.WrapperLookup registryLookup, RecipeExporter exporter) {
return new RecipeGenerator(registryLookup, exporter) {
@Override
public void generate() {
RegistryWrapper.Impl<Item> itemLookup = registries.getOrThrow(RegistryKeys.ITEM);
}
};
}
@Override
public String getName() {
return "FabricDocsReferenceRecipeProvider";
}
}
To finish setup, add this provider to your DataGeneratorEntrypoint
within the onInitializeDataGenerator
method.
Shapeless recipes are fairly straightforward. Just add them to the generate
method in your provider:
createShapeless(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(hasItem(Items.COARSE_DIRT), conditionsFromItem(Items.COARSE_DIRT))
.offerTo(exporter);
For a shaped recipe, you define the shape using a String
, then define what each char
in the String
represents.
createShaped(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(hasItem(Items.CRAFTING_TABLE), conditionsFromItem(Items.CRAFTING_TABLE))
.offerTo(exporter);
createShaped(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(hasItem(Items.LOOM), conditionsFromItem(Items.LOOM))
.offerTo(exporter);
createDoorRecipe(Items.OAK_DOOR, Ingredient.ofItems(Items.OAK_BUTTON)) // Using a helper method!
.criterion(hasItem(Items.OAK_BUTTON), conditionsFromItem(Items.OAK_BUTTON))
.offerTo(exporter);
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.
offerSmelting(
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
);