![]() |
VOOZH | about |
Predicates are JSON structures invoked to check conditions within the world. They return a pass or fail result to the invoker, which acts differently based on the result. They can be defined and invoked by data packs or by commands. In practical terms, predicates are a flexible way for data packs to encode "if this, then that" logic without needing custom code.
Predicate files are standalone data pack files containing one or more predicates.
This article describes how predicates are defined and invoked, and also describes the JSON structure of a predicate.
A predicate file is defined with the JSON format.
Predicate files are part of the data pack directory structure, highlighted below:
The root element of a predicate file can be either an [NBT Compound / JSON Object] object following the predicate structure below, or an [NBT List / JSON Array] array containing multiple predicates. In the latter case all predicates must evaluate to true.
Predicates and predicate files can be invoked in several different manners from other data pack files:
Commands or functions can invoke predicate files in two ways:
predicate= 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./execute: A subcommand, /execute if predicate, can invoke a predicate file or an in-line predicate definition 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.The condition type minecraft:reference invokes a predicate file and returns the result to the invoker.
In addition to predicate files, predicates themselves are used in other locations within other data pack files such as advancements and loot tables.
Below are a few simple predicate examples for context.
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"equipment": {
"mainhand": {
"items": ["minecraft:diamond_sword"]
}
}
}
}
{
"condition": "minecraft:time_check",
"value": { "min": 0, "max": 12000 },
"period": 24000
}
{
"condition": "minecraft:any_of",
"terms": [
{ "condition": "minecraft:random_chance", "chance": 0.25 },
{ "condition": "minecraft:weather_check", "raining": true }
]
}These snippets can be placed inside data/<namespace>/predicate/ within a data pack, then referenced using commands such as:
/execute if predicate my_pack:daytime_check run say Good morning!
This section describes the JSON format of a predicate.
The possible values for [String] condition and associated extra contents:
enchanted_location loot context.
true) or inactive (false) enchantment.this, attacker, direct_attacker, attacking_player, target_entity, or interacting_entity..this, attacker, direct_attacker, attacking_player, target_entity, or interacting_entity..attacking_player entity provided by loot context. Requires attacking_player entity provided by loot context, and always fails if not provided.attacker entity provided by loot context, and if not provided, the enchantment level is regarded as 0.
0 as level.1 Γ· explosion radius probability. Requires explosion radius provided by loot context, and always success if not provided.24000 * day count + day time) against given values. Invokable from any context.
| Java Edition | |||||||
|---|---|---|---|---|---|---|---|
| 1.15 | 19w38a | Added predicates to data packs. | |||||
| 1.16 | 20w12a | Added fishing_hook sub-predicate into entity predicate to check properties of the fishing hook. | |||||
| 1.19 | 22w14a | player, fishing_hook, lightning_bolt, and catType fields have been replaced with type_specific. type_specific has field type (one of player, fishing_hook, lightning_bolt, or cat) and same sub-fields as removed fields. | |||||
| 1.19.3 | 23w06a | Removed is_projectile, is_explosion, bypasses_armor, bypasses_invulnerability, bypasses_magic, is_fire, is_magic, and is_lightning fields from damage_source_properties. | |||||
A new tags array has been added to damage_source_properties. Each entry has two fields:
| |||||||
| 1.20 | 23w18a | Condition alternative has been renamed to any_of. | |||||
Added new condition all_of that passes only when all sub-conditions pass, with the same syntax as any_of. | |||||||
| 1.20.5 | 24w09a | Item predicate format has been updated:
| |||||
Block predicate format has been updated:
| |||||||
Fluid predicate format has been updated:
| |||||||
Entity predicate format has been updated:
| |||||||
Location predicate format has been updated:
| |||||||
| 24w10a | Added entity sub-predicate slots, used to check single or multiple slots on any entity. | ||||||
| 24w11a | Removed entity sub-predicate any
Component-specific item predicate properties have been moved to separate field predicates | ||||||
|
Item sub-predicate format has been updated:
| |||||||
| 1.21 | 24w18a | Renamed random_chance_with_looting to random_chance_with_enchanted_bonus, changing the chance field from a float to a level-based value, removing the looting_multiplier field, and adding a enchantment field. | |||||
Changed the chance field of random_chance from a float into a number provider. | |||||||
Added a can_see_sky field to location predicates. | |||||||
Renamed enchantment to enchantments in the minecraft:enchantments item sub-predicate; now accepting multiple possible enchantments, or tags. | |||||||
|
Changes to the entity predicate:
| |||||||
Renamed loot context entities: killer renamed to attacker; direct_killer renamed to direct_attacker; killer_player renamed to attacking player. | |||||||
| 24w19a | Added is_direct field to damage type predicates. | ||||||
| 24w21a | Added jukebox_playable item predicate. | ||||||
The gamemode field of the player predicate now accepts a list of gamemodes rather than a single string. | |||||||
| pre1 | Split chance into unenchanted_chance and enchanted_chance in the random_chance_with_enchanted_bonus condition. | ||||||
| 1.21.2 | 24w35a | New entity sub-predicate for testing sheep wool. Fields: sheared and color. | |||||
| 24w36a | New entity sub-predicate for testing player input. Available inputs to test are forward, backward left, right, jump, sneak, and sprint. | ||||||
| 24w37a | New entity sub-predicate for salmon. Fields: variant. | ||||||
| 24w39a | Removed the minecraft:boat entity sub-predicate, since boats no longer have variants. | ||||||
| 1.21.5 | 25w03a | A new optional field was added to entity predicate: components. | |||||
Several entity sub-predicates have been removed and replaced with combination of components predicate and variant entity components. | |||||||
The field color has been removed from minecraft:sheep sub-predicate. | |||||||
| 25w07a | The stepping_on entity predicate can only evaluate to true if the entity is on ground. | ||||||
| 25w10a | New optional fields have been added to block predicates: components and predicates. | ||||||
A new optional field has been added to entity predicates: predicates. | |||||||
| 1.21.11 | 25w41a | Component predicates (predicates field in block, item and entity predicates) now include predicates for checking existence of every component type. | |||||
The flags entity predicate now supports new values. | |||||||
| 26.1 | snap1 | player Sub-Predicate has a new optional field: food. | |||||
| snap3 | minecraft:time_check loot predicate: added clock field. | ||||||
| pre1 | Added the minecraft:environment_attribute_check loot predicate. | ||||||
| 26.2 | snap3 | The entity predicate format has changed from a structure with multiple optional fields to one similar to data component maps. | |||||
Added minecraft:entity_tags entity sub-predicate. | |||||||
| snap4 | The entity sub-predicate slime has been renamed to cube_mob. | ||||||