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.
At a glance
Section titled “At a glance”| 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 |
Quick start
Section titled “Quick start”In the mod’s common class, with REGISTRAR, the mod’s Registrar:
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)));CodecRecipeType
Section titled “CodecRecipeType”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:
current = WASHING.find(level, input).orElse(null);The CodecRecipe Javadoc says what of a recipe to keep across a data-pack reload.
RecipeCodecs
Section titled “RecipeCodecs”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:
{ "type": "mymod:washing", "input": { "ingredient": { "item": "minecraft:raw_iron" }, "count": 2 }, "result": { "item": "minecraft:iron_nugget", "count": 9 }}- An ingredient is an
item, atag, or a list of them, as in a crafting recipe. - A counted ingredient wraps one under
ingredient, beside itscount. - A result names its
item, and may give acountand the item’snbt. - A fluid names its
fluidand itsamountin millibuckets, and may give itsnbt. nbtis SNBT text,"{Damage:5}", or a JSON object read the same way.
Recipes
Section titled “Recipes”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:
Optional<RecipeEntry<SmeltingRecipe>> smelting = Recipes.find(level, RecipeType.SMELTING, input);ItemStack made = smelting.map(found -> Recipes.result(level, found.recipe())).orElse(ItemStack.EMPTY);See also
Section titled “See also”- Platform info:
RecipeViewers, which shows a mod’s recipes in recipe viewers. - Saved data and reloaders: the reload event that replaces the recipes.