Predicate

Predicates are data pack files, invoked with various means to check conditions within the world. They return a pass or fail result to the invoker, who will act differently based on this result.

This page describes how predicates are defined and invoked. Also described here is the JSON structure of a predicate condition, the primary JSON structure used within predicates.

Within this article, the term "predicate condition" may be referred to by the short form "condition."

Definition
A predicate is defined with the JSON format. It contains either the structure of a condition, or an array with multiple conditions.


 * (data pack name)
 * pack.mcmeta
 * pack.png
 * data
 * (namespace)
 * advancements
 * (advancement).json
 * functions
 * (function).mcfunction
 * item_modifiers
 * (modifier).json
 * loot_tables
 * (loot table).json
 * predicates
 * (predicate).json
 * Further folders&hellip;

The root element of a predicate can be either an, following the structure of a condition below, or an containing multiple conditions.

Invocation
Predicates can be invoked in several different manners from other data pack files:

Invocation from commands
Commands or functions can invoke predicates in two ways:


 * Target selectors: The selector argument  checks predicates as a filter for entity selection. The predicate is invoked once per entity that needs filtering, each time being at the entity's location.
 * : A subcommand,, can invoke a predicate to either return a result or to decide whether to continue with a subcommand chain. The predicate is invoked once at the current contextual position of execution.

Invocation from other conditions
The condition type  invokes a predicate file and returns the result to the invoker.

Predicate conditions' presence in other files
In addition to predicates, the JSON structure of predicate conditions, described below, is used in other locations within other data pack files such as advancements and loot tables.

Predicate condition JSON format
This section describes the JSON format of a single predicate condition. Multiple conditions may be entered into a single predicate by placing them into a JSON array.


 * : The root element of the condition.
 * : The resource location of the condition type to check.
 * Other parts of the condition, specified below.

The possible values for and associated extra contents:


 * alternative&mdash;Evaluates a list of conditions and passes if any one of them passes. Invokable from  any context .
 * : The list of conditions to evaluate. Conditinons within this array must be, they cannot themselves be arrays.
 * A condition, following this structure recursively.


 * block_state_property&mdash;Checks the mined block and its block states. Invokable from  loot tables , and always  fails  when invoked from anything else.
 * : A block ID. The test fails if the block doesn't match.
 * : (Optional) A map of block property names to values. All values are strings. The test fails if the block doesn't match.


 * damage_source_properties&mdash;Checks properties of damage source. Invokable from  advancements  or  loot tables , and  fails  when invoked from anything else.
 * : Predicate applied to the damage source.


 * entity_properties&mdash;Checks properties of an entity. Invokable from  any context .
 * : The entity to check. Set to  to use the entity that invoked this condition,   for the killer of the   entity, or   to only select the killer if they are a player.
 * : Predicate applied to entity, uses same structure as advancements.


 * entity_scores&mdash;Checks the scoreboard scores of an entity. May be invoked from  any context .
 * : The entity to check. Set to  to use the entity that invoked this condition,   for the killer of the   entity, or   to only select the killer if they are a player.
 * : Scores to check. All specified scores must pass for the condition to pass.
 * : Key name is the objective while the value specifies a range of score values required for the condition to pass.
 * : Number Provider. Minimum score.
 * : Number Provider. Maximum score.
 * : Shorthand version of the other syntax above, to check the score against a single number only. Key name is the objective while the value is the required score.


 * inverted&mdash;Inverts another loot table condition. Invokable from  any context .
 * : The condition to be negated, following the same structure as outlined here, recursively.


 * killed_by_player&mdash;Checks if a  entity exists. Invokable from  advancements  or  loot tables , and  fails  when invoked from anything else.
 * : If true, the condition passes if  is not available.


 * location_check&mdash;Checks the current location against location criteria. Invokable from  any context .
 * - optional offsets to location
 * - optional offsets to location
 * - optional offsets to location
 * : Predicate applied to location, uses same structure as advancements.


 * match_tool&mdash;Checks tool used to mine the block. Invokable from  loot tables , and  fails  when invoked from anything else.
 * : Predicate applied to item, uses same structure as advancements.


 * random_chance&mdash;Generates a random number between 0.0 and 1.0, and checks if it is less than a specified value. Invokable from  any context .
 * : Success rate as a number 0.0–1.0.


 * random_chance_with_looting&mdash;Generates a random number between 0.0 and 1.0, and checks if it is less than a specified value which has been affected by the level of Looting on the  entity. Invokable from  advancements  and  loot tables , and  fails  when invoked from anything else.
 * : Base success rate.
 * : Looting adjustment to the base success rate. Formula is.


 * reference&mdash;Invokes a predicate file and returns its result. Invokable from  any context .
 * : The resource location of the predicate to invoke. A cyclic reference causes a parsing failure.


 * survives_explosion&mdash;Returns true with probability. Invokable only from  loot tables , and  fails  when invoked from anything else.


 * table_bonus&mdash;Passes with probability picked from table, indexed by enchantment level. Invokable from  any context .
 * : Resource location of enchantment.
 * : List of probabilities for enchantment level, indexed from 0.


 * time_check&mdash;Compares the current game time (the age of the world in game ticks) against given values. Invokable from  any context .
 * : The time to compare the game time against.
 * : Number Provider. The minimum value.
 * : Number Provider. The maximum value.
 * : Shorthand version of above, used to check for a single value only. Number providers cannot be used in this shorthand form.
 * : If present, the game time is first reduced modulo the given number before being checked against . For example, setting this to 24000 causes the checked time to be equal to the current daytime.


 * value_check&mdash;Compares a number against another number or range of numbers. Invokable from  any context .
 * : Number Provider. The number to test.
 * : The range of numbers to compare against.
 * : Number Provider. The minimum value.
 * : Number Provider. The maximum value.
 * : Shorthand version of above, used to compare  against a single number only. Number providers cannot be used in this shorthand form.

<div class="treeview" id="condition_weather_check" style="margin-block-end: 1em;">
 * weather_check&mdash;Checks the current game weather. Invokable from  any context .
 * : If true, the condition passes only if it is raining or thundering.
 * : If true, the condition passes only if it is thundering.

History
Prädikate Prédicat プレディケート 战利品表谓词