Skip to content

Recipes

These types give a mod’s machine its own recipe type and find the recipes data packs hold for it. Use CodecRecipeType for a new type, which needs only a record and its codec, and Recipes to find recipes of a type the mod did not make, such as vanilla’s smelting.

Type Summary Status Since Side Thread
CodecRecipe One recipe of a CodecRecipeType: its ID and the mod’s data. Experimental 2.15.0 both any
CodecRecipeType A recipe type whose recipes are a mod’s own data, read from data packs by a Codec. Experimental 2.15.0 both setup
CountedIngredient An ingredient and how many items of it a recipe uses. Experimental 2.15.0 both any
RecipeCodecs Codecs for recipe parts, in the keys vanilla’s own recipe files use. Experimental 2.15.0 both any
RecipeEntry A recipe and its ID, as Recipes finds them. Experimental 2.15.0 both any
RecipeRules The rules of a recipe type whose recipes are a mod’s own data. Experimental 2.15.0 both any
Recipes A level’s recipes by recipe type, and what a recipe makes. Experimental 2.15.0 both any

In the mod’s common class, with REGISTRAR, the mod’s Registrar:

Make a washing recipe type from a record
record WashRecipe(CountedIngredient input, ItemStack result) {
static final Codec<WashRecipe> CODEC = RecordCodecBuilder.create(i -> i.group(
RecipeCodecs.COUNTED_INGREDIENT.fieldOf("input").forGetter(WashRecipe::input),
RecipeCodecs.RESULT.fieldOf("result").forGetter(WashRecipe::result))
.apply(i, WashRecipe::new));
}
static final CodecRecipeType<WashRecipe> WASHING = CodecRecipeType.register(REGISTRAR, "washing",
WashRecipe.CODEC, (recipe, input, level) -> recipe.input().test(input.getItem(0)));

Experimental · Since 2.15.0 · Side: both · Thread: setup

CodecRecipeType registers a recipe type whose recipes are a record the mod reads with a Codec, so the mod writes no recipe class and no serializer. In a machine’s block entity, with WASHING from the quick start, input, its input slots as a Container, level, its level, and current, a field holding the recipe found last, when the input changes:

Find the recipe for a machine's input
current = WASHING.find(level, input).orElse(null);

The CodecRecipe Javadoc says what of a recipe to keep across a data-pack reload.

Experimental · Since 2.15.0 · Side: both · Thread: any

RecipeCodecs reads the parts of a recipe file in the keys vanilla’s own recipe files use, so data-pack authors write a mod’s recipes as they write vanilla’s. A washing recipe from the quick start, in data/mymod/recipes/wash_raw_iron.json:

A washing recipe
{
"type": "mymod:washing",
"input": { "ingredient": { "item": "minecraft:raw_iron" }, "count": 2 },
"result": { "item": "minecraft:iron_nugget", "count": 9 }
}
  • An ingredient is an item, a tag, or a list of them, as in a crafting recipe.
  • A counted ingredient wraps one under ingredient, beside its count.
  • A result names its item, and may give a count and the item’s nbt.
  • A fluid names its fluid and its amount in millibuckets, and may give its nbt.
  • nbt is SNBT text, "{Damage:5}", or a JSON object read the same way.

Experimental · Since 2.15.0 · Side: both · Thread: any

Recipes finds a level’s recipes of any recipe type: the one that matches an input, or every one. With level, a server level, and input, a Container holding raw iron:

Find what a furnace would make from raw iron
Optional<RecipeEntry<SmeltingRecipe>> smelting = Recipes.find(level, RecipeType.SMELTING, input);
ItemStack made = smelting.map(found -> Recipes.result(level, found.recipe())).orElse(ItemStack.EMPTY);