{{For|predicates inside models|Tutorials/Models#Item predicates}}
{{Exclusive|java}}
'''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 acts 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 ==
A predicate file is defined with the [[JSON]] format.
Predicate files are part of the data pack directory structure, highlighted below:
{{Data pack directory|predicate|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.
* {{Cmd|execute}}: A subcommand, /execute if predicate
, 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.
=== Other predicates ===
The condition type minecraft:reference
invokes a predicate file and returns the result to the invoker.
=== Presence in other files ===
In addition to predicate files, predicates themselves are used in other locations within other data pack files such as [[Advancement/JSON format|advancements]] and [[Loot table|loot tables]].
== JSON format ==
This section describes the JSON format of a predicate.
attacker
entity provided by [[loot context]], and if not provided, the enchantment level is regarded as 0.
** {{nbt|float|unenchanted_chance}}: The success rate to use when the enchantment is not present; 0.0–1.0.
** {{nbt|float}}{{nbt|compound|enchanted_chance}}: [[level-based value]]. The success rate based on the level when then enchantment is present; 0.0–1.0.
** {{nbt|string|enchantment}}: {{json ref|enchantment|custom enchantment}}. The enchantment whose level to use for the chance calculation. If the enchantment is not present, uses {{cd|0}} as level.
24000 * day count + day time
) against given values. Invokable from any context.
** {{nbt|compound|value}}: The time to compare the day time against.
*** {{nbt|int}}{{nbt|compound|min}}: A [[Loot table#Number provider|number provider]]. The minimum value.
*** {{nbt|int}}{{nbt|compound|max}}: A [[Loot table#Number provider|number provider]]. The maximum value.
** {{nbt|int|value}}: Shorthand version of {{nbt|compound|value}} above, used to check for a single value only. Number providers cannot be used in this shorthand form.
** {{nbt|int|period}}: If present, the day time is first reduced modulo the given number before being checked against {{nbt|compound}}{{nbt|int|value}}. For example, setting this to 24000 causes the checked time to be equal to the current daytime.
sheared
and color
.}}
|{{HistoryLine|||dev=24w36a|New entity sub-predicate for testing player input. Available inputs to test are forward
, backward
left
, right
, jump
, sneak
, and sprint
.}}
|{{HistoryLine|||dev=24w37a|New entity sub-predicate for salmon. Fields: variant
.}}
|{{HistoryLine|||dev=24w39a|Removed the minecraft:boat
entity sub-predicate, since boats no longer have variants.}}
}}
== External links ==
* [https://misode.github.io/predicate/ Predicate Generator on misode.github.io]
== Navigation ==
{{Navbox Java Edition technical|datapack}}
[[de:Prädikate]]
[[fr:Prédicat]]
[[ja:プレディケート]]
[[pt:Predicado]]
[[zh:谓词]]