Skip to content

Predicates

Jacky edited this page Jul 6, 2022 · 3 revisions

Predicates are preconditions that determine whether the action of a recipe will be applied, based on arithmetic/logical conditions on fields.

Field access

There are two ways to address fields. The following two snippets are equivalent.

Compact

    when:
      villager.profession: none # Accesses "villager.profession"
      villager.world.time: "> 1000" # Accesses "villager.world.time"

Detailed

    when:
      villager:
        profession: none # Accesses "villager.profession"
        world.time: "> 1000" # Accesses "villager.world.time" (you can mix and match)

Boolean logic

There are three Boolean logic predicates: and, or, not. and and or takes a list of other predicate blocks.

    when: # Example 1
        and: # both predicate blocks 1 and 2 must be fulfilled
         # predicate block 1
         - villager.profession: LIBRARIAN
         # predicate block 2
         - result.type: "minecraft:enchanted_book"
         # you can add more predicate blocks to the list

    when: # Example 2
        or: # only one of the predicate blocks needs to be fulfilled
         # predicate block 1
         - villager.profession: ARMORER
         # predicate block 2
         - villager.profession: WEAPONSMITH
         # you can add more predicate blocks to the list

Of course, the when: block implicitly ands predicates inside the block for you. (i.e. all predicates in a when: block must be fulfilled) Therefore, example 1 is equivalent to the following:

    when: # both predicates must be fulfilled
        villager.profession: LIBRARIAN
        result.type: "minecraft:enchanted_book"
        # you can add more predicates to the block

not takes a single predicate block.

    when: # predicate must not be fulfilled
        not:
            villager.profession: LIBRARIAN

Matching villagers

Fields

See fields and how to use them.

profession - the profession of a villager

All professions as of 1.16:

NONE,
ARMORER,
BUTCHER,
CARTOGRAPHER,
CLERIC,
FARMER,
FISHERMAN,
FLETCHER,
LEATHERWORKER,
LIBRARIAN,
MASON,
NITWIT,
SHEPHERD,
TOOLSMITH,
WEAPONSMITH

type - villager biome

All types as of 1.16:

DESERT,
JUNGLE,
PLAINS,
SAVANNA
SNOW,
SWAMP,
TAIGA

Examples

To match a librarian villager:

    when:
        villager.profession: LIBRARIAN

To match both toolsmith and weaponsmith villagers:

    when:
        or:
         - villager.profession: TOOLSMITH
         - villager.profession: WEAPONSMITH

Or, with a regular expression: (Don't use regular expressions if you don't know how to write them!)

    when:
        villager.profession: matches ^(TOOL|WEAPON)SMITH$

Items

You can match items in the 2 ingredient slots and the result slot.

Fields: ingredient-0, ingredient-1, result

Clone this wiki locally