Predicate

Predicates are JSON structures found in multiple different locations within data packs. They are 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.

Predicate files are standalone data pack files that contain one or more predicates. Predicates can also be defined in other ways.

This article describes how predicates are defined and invoked, and also describes the JSON structure of a predicate.

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


 * (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 file can be either an following the predicate structure below, or an  containing multiple predicates.

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

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


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

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

Predicates' presence in other files
In addition to predicate files, predicates themselves are used in other locations within other data pack files such as advancements and loot tables.

Predicate JSON format
This section describes the JSON format of a predicate.


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

The possible values for and associated extra contents:


 * alternative&mdash;Evaluates a list of predicates and passes if any one of them passes. Invokable from  any context .
 * : The list of predicates to evaluate. A predicate within this array must be a.
 * A predicate, 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 state names to values. Errors if the block doesn't have these properties.
 * : A block state and a exact value. The value is a string.
 * : A block state name and a ranged value to match.
 * : The min value.
 * : The max value.


 * damage_source_properties&mdash;Checks properties of damage source. Invokable from  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,   to only select the killer if they are a player, or   for the direct entity that killed   entity.
 * : 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,   to only select the killer if they are a player, or   for the direct entity that killed   entity.
 * : 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.
 * : A number Provider. Minimum score.
 * : A 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  loot tables , and  fails  when invoked from anything else.


 * 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 . When invoked from anything else, the looting level is regarded as 0.
 * : 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 success with probability. Invokable only from  loot tables , and  success  when invoked from anything else.


 * table_bonus&mdash;Passes with probability picked from a list, indexed by enchantment power. Invokable from  loot tables . When invoked from anything else, the enchantment level is regarded as 0.
 * : Resource location of enchantment.
 * : List of probabilities for enchantment power, 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.
 * : A number Provider. The minimum value.
 * : A 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 .
 * : A number Provider. The number to test.
 * : The range of numbers to compare against.
 * : A number Provider. The minimum value.
 * : A 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 プレディケート 战利品表谓词