Skip to content

Items - Crafting Module

anvil.api.items.crafting

Recipes and the crafting item catalog.

Each recipe type writes one typed document. Its file class builds it, and values are checked when the file is exported.

anvil.api.items.crafting.recipe

The parts every recipe type shares, and the base of the recipe file classes.

Each recipe type has its own module with a body (_XRecipe), the document written to the file (_XRecipeFile) and the file class you create and build.

anvil.api.items.crafting.shaped

The minecraft:recipe_shaped.

ShapedCraftingRecipe

Bases: _BaseRecipe[_ShapedRecipeFile]

A shaped crafting recipe: ingredients placed in a pattern on the crafting grid.

Documentation reference

identifier property

The file's identifier.

name property

The identifier's name, without its namespace.

__export__()

Exports the addon object after potentially shortening its content and replacing backslashes. Logs the event and writes the object to a file.

__init__(name, assume_symmetry=True, tags=('crafting_table',))

Creates a shaped recipe.

Parameters:

Name Type Description Default
name str

The name of the recipe, also its file name.

required
assume_symmetry bool

Whether the mirrored pattern also crafts the result. Defaults to True.

True
tags Sequence[str]

The stations that use the recipe. Defaults to ("crafting_table",).

('crafting_table',)

__schema__() classmethod

The JSON Schema (draft 2020-12) of this file: the schema of its _document_type, with the file's type as title and where it is written under x-anvil-file.

Raises:

Type Description
TypeError

When the class is an abstract file base, with no document type.

ingredients(items, keep_empty_slots=False)

Sets the grid: up to 3 rows of up to 3 items, None for an empty slot. Each different item gets its own pattern symbol.

Parameters:

Name Type Description Default
items Sequence[Sequence[...]]

The rows, each item an item or an (item, data) tuple.

required
keep_empty_slots bool

Keeps the empty rows and columns around the items. Defaults to False.

False

Raises:

Type Description
ValueError

When there are more than 3 rows or 3 items in a row.

priority(priority)

Sets the priority of the recipe when several recipes match.

Parameters:

Name Type Description Default
priority int

The priority, lower values first.

required

result(item, count=1, data=0)

Sets the item produced.

Parameters:

Name Type Description Default
item Item | Block | BlockDescriptor | str

The item.

required
count int

How many are produced. Defaults to 1.

1
data int

The deprecated data value. Defaults to 0, left out.

0

unlock_context(unlock_context)

Unlocks the recipe in the recipe book in a context.

Parameters:

Name Type Description Default
unlock_context RecipeUnlockContext

The context.

required

unlock_items(unlock_items)

Unlocks the recipe in the recipe book when the player gets one of the items.

Parameters:

Name Type Description Default
unlock_items Sequence[Item | Block | BlockDescriptor | str]

The items.

required

anvil.api.items.crafting.shapeless

The minecraft:recipe_shapeless, also used by the stonecutter.

ShapelessRecipe

Bases: _BaseRecipe[_ShapelessRecipeFile]

A shapeless crafting recipe: ingredients placed anywhere on the crafting grid.

Documentation reference

identifier property

The file's identifier.

name property

The identifier's name, without its namespace.

__export__()

Exports the addon object after potentially shortening its content and replacing backslashes. Logs the event and writes the object to a file.

__init__(name, tags=('crafting_table',))

Creates a shapeless recipe.

Parameters:

Name Type Description Default
name str

The name of the recipe, also its file name.

required
tags Sequence[str]

The stations that use the recipe. Defaults to ("crafting_table",).

('crafting_table',)

__schema__() classmethod

The JSON Schema (draft 2020-12) of this file: the schema of its _document_type, with the file's type as title and where it is written under x-anvil-file.

Raises:

Type Description
TypeError

When the class is an abstract file base, with no document type.

ingredients(items)

Adds the ingredients, at most 9. None entries are skipped.

Parameters:

Name Type Description Default
items Sequence[...]

The items, each an item or an (item, data) tuple.

required

priority(priority)

Sets the priority of the recipe when several recipes match.

Parameters:

Name Type Description Default
priority int

The priority, lower values first.

required

result(item, count=1, data=0)

Sets the item produced.

Parameters:

Name Type Description Default
item Item | Block | BlockDescriptor | str

The item.

required
count int

How many are produced. Defaults to 1.

1
data int

The deprecated data value. Defaults to 0, left out.

0

unlock_context(unlock_context)

Unlocks the recipe in the recipe book in a context.

Parameters:

Name Type Description Default
unlock_context RecipeUnlockContext

The context.

required

unlock_items(unlock_items)

Unlocks the recipe in the recipe book when the player gets one of the items.

Parameters:

Name Type Description Default
unlock_items Sequence[Item | Block | BlockDescriptor | str]

The items.

required

StoneCutterRecipe

Bases: ShapelessRecipe

A stonecutter recipe: a shapeless recipe with one ingredient, used by the stonecutter.

Documentation reference

identifier property

The file's identifier.

name property

The identifier's name, without its namespace.

__export__()

Exports the addon object after potentially shortening its content and replacing backslashes. Logs the event and writes the object to a file.

__init__(name, tags=('stonecutter',))

Creates a stonecutter recipe.

Parameters:

Name Type Description Default
name str

The name of the recipe, also its file name.

required
tags Sequence[str]

The stations that use the recipe. Defaults to ("stonecutter",).

('stonecutter',)

__schema__() classmethod

The JSON Schema (draft 2020-12) of this file: the schema of its _document_type, with the file's type as title and where it is written under x-anvil-file.

Raises:

Type Description
TypeError

When the class is an abstract file base, with no document type.

ingredient(item, data=0)

Sets the ingredient.

Parameters:

Name Type Description Default
item Item | Block | BlockDescriptor | str

The item.

required
data int

The deprecated data value. Defaults to 0, left out.

0

ingredients(items)

Adds the ingredients, at most 9. None entries are skipped.

Parameters:

Name Type Description Default
items Sequence[...]

The items, each an item or an (item, data) tuple.

required

priority(priority)

Sets the priority of the recipe when several recipes match.

Parameters:

Name Type Description Default
priority int

The priority, lower values first.

required

result(item, count=1, data=0)

Sets the item produced.

Parameters:

Name Type Description Default
item Item | Block | BlockDescriptor | str

The item.

required
count int

How many are produced. Defaults to 1.

1
data int

The deprecated data value. Defaults to 0, left out.

0

unlock_context(unlock_context)

Unlocks the recipe in the recipe book in a context.

Parameters:

Name Type Description Default
unlock_context RecipeUnlockContext

The context.

required

unlock_items(unlock_items)

Unlocks the recipe in the recipe book when the player gets one of the items.

Parameters:

Name Type Description Default
unlock_items Sequence[Item | Block | BlockDescriptor | str]

The items.

required

anvil.api.items.crafting.furnace

The minecraft:recipe_furnace.

SmeltingRecipe

Bases: _BaseRecipe[_FurnaceRecipeFile]

A furnace recipe: an item smelted in furnaces, smokers, blast furnaces or campfires.

Documentation reference

identifier property

The file's identifier.

name property

The identifier's name, without its namespace.

__export__()

Exports the addon object after potentially shortening its content and replacing backslashes. Logs the event and writes the object to a file.

__init__(name, tags)

Creates a furnace recipe.

Parameters:

Name Type Description Default
name str

The name of the recipe, also its file name.

required
tags Sequence[SmeltingTags]

The stations that smelt the item.

required

__schema__() classmethod

The JSON Schema (draft 2020-12) of this file: the schema of its _document_type, with the file's type as title and where it is written under x-anvil-file.

Raises:

Type Description
TypeError

When the class is an abstract file base, with no document type.

input(identifier)

Sets the item smelted.

Parameters:

Name Type Description Default
identifier Item | Block | BlockDescriptor | str

The item.

required

output(identifier)

Sets the item produced.

Parameters:

Name Type Description Default
identifier Item | Block | BlockDescriptor | str

The item.

required

priority(priority)

Sets the priority of the recipe when several recipes match.

Parameters:

Name Type Description Default
priority int

The priority, lower values first.

required

unlock_context(unlock_context)

Unlocks the recipe in the recipe book in a context.

Parameters:

Name Type Description Default
unlock_context RecipeUnlockContext

The context.

required

unlock_items(unlock_items)

Unlocks the recipe in the recipe book when the player gets one of the items.

Parameters:

Name Type Description Default
unlock_items Sequence[Item | Block | BlockDescriptor | str]

The items.

required

anvil.api.items.crafting.smithing_transform

The minecraft:recipe_smithing_transform.

SmithingRecipe

Bases: _BaseRecipe[_SmithingTransformRecipeFile]

A smithing table transform recipe: a base item upgraded with a template and a material.

Documentation reference

identifier property

The file's identifier.

name property

The identifier's name, without its namespace.

__export__()

Exports the addon object after potentially shortening its content and replacing backslashes. Logs the event and writes the object to a file.

__init__(name, tags=('smithing_table',))

Creates a smithing transform recipe.

Parameters:

Name Type Description Default
name str

The name of the recipe, also its file name.

required
tags Sequence[str]

The stations that use the recipe. Defaults to ("smithing_table",).

('smithing_table',)

__schema__() classmethod

The JSON Schema (draft 2020-12) of this file: the schema of its _document_type, with the file's type as title and where it is written under x-anvil-file.

Raises:

Type Description
TypeError

When the class is an abstract file base, with no document type.

addition(identifier)

Sets the material added.

Parameters:

Name Type Description Default
identifier Item | Block | BlockDescriptor | str

The item.

required

base(identifier)

Sets the item transformed.

Parameters:

Name Type Description Default
identifier Item | Block | BlockDescriptor | str

The item.

required

priority(priority)

Sets the priority of the recipe when several recipes match.

Parameters:

Name Type Description Default
priority int

The priority, lower values first.

required

result(identifier)

Sets the item produced.

Parameters:

Name Type Description Default
identifier Item | Block | BlockDescriptor | str

The item.

required

template(identifier)

Sets the smithing template item.

Parameters:

Name Type Description Default
identifier Item | Block | BlockDescriptor | str

The item.

required

unlock_context(unlock_context)

Unlocks the recipe in the recipe book in a context.

Parameters:

Name Type Description Default
unlock_context RecipeUnlockContext

The context.

required

unlock_items(unlock_items)

Unlocks the recipe in the recipe book when the player gets one of the items.

Parameters:

Name Type Description Default
unlock_items Sequence[Item | Block | BlockDescriptor | str]

The items.

required

anvil.api.items.crafting.smithing_trim

The minecraft:recipe_smithing_trim.

SmithingTrimRecipe

Bases: _BaseRecipe[_SmithingTrimRecipeFile]

A smithing table trim recipe: armor decorated with a trim template and a material.

Documentation reference

identifier property

The file's identifier.

name property

The identifier's name, without its namespace.

__export__()

Exports the addon object after potentially shortening its content and replacing backslashes. Logs the event and writes the object to a file.

__init__(name, tags=('smithing_table',))

Creates a smithing trim recipe.

Parameters:

Name Type Description Default
name str

The name of the recipe, also its file name.

required
tags Sequence[str]

The stations that use the recipe. Defaults to ("smithing_table",).

('smithing_table',)

__schema__() classmethod

The JSON Schema (draft 2020-12) of this file: the schema of its _document_type, with the file's type as title and where it is written under x-anvil-file.

Raises:

Type Description
TypeError

When the class is an abstract file base, with no document type.

addition(item=None, tag=None)

Sets the trim material: an item, or any item of a tag.

Parameters:

Name Type Description Default
item Item | Block | BlockDescriptor | str

The item.

None
tag str

The item tag, such as minecraft:trim_materials.

None

base(item=None, tag=None)

Sets the armor trimmed: an item, or any item of a tag.

Parameters:

Name Type Description Default
item Item | Block | BlockDescriptor | str

The item.

None
tag str

The item tag, such as minecraft:trimmable_armors.

None

priority(priority)

Sets the priority of the recipe when several recipes match.

Parameters:

Name Type Description Default
priority int

The priority, lower values first.

required

template(item=None, tag=None)

Sets the trim template: an item, or any item of a tag.

Parameters:

Name Type Description Default
item Item | Block | BlockDescriptor | str

The item.

None
tag str

The item tag, such as minecraft:trim_templates.

None

unlock_context(unlock_context)

Unlocks the recipe in the recipe book in a context.

Parameters:

Name Type Description Default
unlock_context RecipeUnlockContext

The context.

required

unlock_items(unlock_items)

Unlocks the recipe in the recipe book when the player gets one of the items.

Parameters:

Name Type Description Default
unlock_items Sequence[Item | Block | BlockDescriptor | str]

The items.

required

anvil.api.items.crafting.brewing

The brewing recipes: minecraft:recipe_brewing_container and minecraft:recipe_brewing_mix.

PotionBrewingRecipe

Bases: _PotionRecipe[_BrewingContainerRecipeFile]

A brewing container recipe: changes the potion container, such as a potion into a splash potion.

Documentation reference

identifier property

The file's identifier.

name property

The identifier's name, without its namespace.

__export__()

Exports the addon object after potentially shortening its content and replacing backslashes. Logs the event and writes the object to a file.

__init__(name, tags=('brewing_stand',))

Creates a brewing recipe.

Parameters:

Name Type Description Default
name str

The name of the recipe, also its file name.

required
tags Sequence[str]

The stations that use the recipe. Defaults to ("brewing_stand",).

('brewing_stand',)

__schema__() classmethod

The JSON Schema (draft 2020-12) of this file: the schema of its _document_type, with the file's type as title and where it is written under x-anvil-file.

Raises:

Type Description
TypeError

When the class is an abstract file base, with no document type.

priority(priority)

Sets the priority of the recipe when several recipes match.

Parameters:

Name Type Description Default
priority int

The priority, lower values first.

required

recipe(item, reagent, output)

Sets the brewing.

Parameters:

Name Type Description Default
item Item | Block | BlockDescriptor | str

The input potion.

required
reagent Item | Block | BlockDescriptor | str

The item brewed with the input potion.

required
output Item | Block | BlockDescriptor | str

The output potion.

required

unlock_context(unlock_context)

Unlocks the recipe in the recipe book in a context.

Parameters:

Name Type Description Default
unlock_context RecipeUnlockContext

The context.

required

unlock_items(unlock_items)

Unlocks the recipe in the recipe book when the player gets one of the items.

Parameters:

Name Type Description Default
unlock_items Sequence[Item | Block | BlockDescriptor | str]

The items.

required

PotionMixingRecipe

Bases: _PotionRecipe[_BrewingMixRecipeFile]

A brewing mix recipe: changes the potion type, such as awkward into strength.

Documentation reference

identifier property

The file's identifier.

name property

The identifier's name, without its namespace.

__export__()

Exports the addon object after potentially shortening its content and replacing backslashes. Logs the event and writes the object to a file.

__init__(name, tags=('brewing_stand',))

Creates a brewing recipe.

Parameters:

Name Type Description Default
name str

The name of the recipe, also its file name.

required
tags Sequence[str]

The stations that use the recipe. Defaults to ("brewing_stand",).

('brewing_stand',)

__schema__() classmethod

The JSON Schema (draft 2020-12) of this file: the schema of its _document_type, with the file's type as title and where it is written under x-anvil-file.

Raises:

Type Description
TypeError

When the class is an abstract file base, with no document type.

priority(priority)

Sets the priority of the recipe when several recipes match.

Parameters:

Name Type Description Default
priority int

The priority, lower values first.

required

recipe(item, reagent, output)

Sets the brewing.

Parameters:

Name Type Description Default
item Item | Block | BlockDescriptor | str

The input potion.

required
reagent Item | Block | BlockDescriptor | str

The item brewed with the input potion.

required
output Item | Block | BlockDescriptor | str

The output potion.

required

unlock_context(unlock_context)

Unlocks the recipe in the recipe book in a context.

Parameters:

Name Type Description Default
unlock_context RecipeUnlockContext

The context.

required

unlock_items(unlock_items)

Unlocks the recipe in the recipe book when the player gets one of the items.

Parameters:

Name Type Description Default
unlock_items Sequence[Item | Block | BlockDescriptor | str]

The items.

required

anvil.api.items.crafting.catalog

CraftingItemCatalog

Bases: JsonFile[_CraftingItemsCatalogFile]

The crafting item catalog: the groups and items added to the creative inventory and the recipe book. Additions go at the end of their category.

Documentation reference

identifier property

The file's identifier.

name property

The identifier's name, without its namespace.

__export__()

Exports the addon object after potentially shortening its content and replacing backslashes. Logs the event and writes the object to a file.

__schema__() classmethod

The JSON Schema (draft 2020-12) of this file: the schema of its _document_type, with the file's type as title and where it is written under x-anvil-file.

Raises:

Type Description
TypeError

When the class is an abstract file base, with no document type.

add_group(category, name, icon, items=())

Adds a group to a category, or adds the items to the group when it is already there. The items' menu category is set to the category and group.

Parameters:

Name Type Description Default
category ItemCategory

The category to add the group to.

required
name str

The group's display name, localized as tag.<namespace>:<name>.

required
icon Item | Block | BlockDescriptor

The item shown as the group's icon.

required
items Sequence[Item | Block]

The items of the group.

()

Returns:

Name Type Description
CraftingItemCatalog CraftingItemCatalog

The current instance of CraftingItemCatalog.

add_loose_items(category, items)

Adds items to a category outside of any collapsible group. The items' menu category is set to the category.

Parameters:

Name Type Description Default
category ItemCategory

The category to add the items to.

required
items Sequence[Item | Block]

The items to add.

required

Returns:

Name Type Description
CraftingItemCatalog CraftingItemCatalog

The current instance of CraftingItemCatalog.

queue()

Queues the catalog for export.