Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Minecraft:Predicate: Difference between revisions

From SAS Gaming Wiki
SyncBot (talk | contribs)
Sync: new page from Minecraft
 
SyncBot (talk | contribs)
Sync: updated from Minecraft
 
(4 intermediate revisions by the same user not shown)
Line 2: Line 2:
{{Exclusive|java}}
{{Exclusive|java}}


'''Predicates''' are [[Minecraft: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 [[Minecraft:data pack]]s or by [[Minecraft:commands]]. In practical terms, predicates are a flexible way for data packs to encode "if this, then that" logic without needing custom code.
A '''predicate''' (also known as a '''loot condition''') is a data structure commonly used throughout data packs and commands, invoked to check boolean conditions either in the world or within a given ''[[Minecraft:loot context]]''. Predicates do not change data or affect the world, they only ''check'' information (that they have access to) and return either a ''pass'' or a ''fail''. They can be defined and registered in [[Minecraft:data pack]]s, or they can be directly defined "in-line" in various places. They can be used throughout the game such as in commands, [[Minecraft:loot table]]s, and [[Minecraft:advancement]]s. 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.
'''Predicate files''' are standalone [[Minecraft:JSON]] files in data packs containing the definition for a predicate. The file path indicates the [[Minecraft:namespaced identifier]] used to reference it.


This article describes how predicates are defined and invoked, and also describes the JSON structure of a predicate.
This article describes how predicates are defined and invoked, and also describes the JSON structure of a predicate.
Line 69: Line 69:
<div class="treeview" style="margin-block-end: 1em;">
<div class="treeview" style="margin-block-end: 1em;">
* {{nbt|list}}{{nbt|compound}}: The root element of the predicate.
* {{nbt|list}}{{nbt|compound}}: The root element of the predicate.
** {{nbt|string|condition}}: The [[Minecraft:resource location]] of the condition type to check.
** {{nbt|string|condition}}{{until|JE 26.3}} / {{nbt|string|type}}{{upcoming|JE 26.3}}: The [[Minecraft:resource location]] of the condition type to check.
** Other parts of the predicate, specified below. In lists each element must evaluate to true for the predicate to pass.
** Other parts of the predicate, specified below. In lists each element must evaluate to true for the predicate to pass.
</div>
</div>
Line 76: Line 76:


<div class="treeview" id="condition_all_of" style="margin-block-end: 1em;">
<div class="treeview" id="condition_all_of" style="margin-block-end: 1em;">
* '''all_of'''&mdash;Evaluates a list of predicates and passes if all of them pass. Invokable from <b><span style="color:#00af89">any context</span></b>.
* '''all_of''' &mdash; Evaluates a list of predicates and passes if all of them pass. Invokable from <b><span style="color:#00af89">any context</span></b>.
** {{nbt|list|terms}}: The list of predicates to evaluate.
** {{nbt|list|terms}}: The list of predicates to evaluate.{{until|JE 26.3}} / an inline value, a single namespaced ID, a list of namespaced IDs, a list of inline values, or a hash-prefixed tag ID of a {{cd|minecraft:predicate}} type.{{upcoming|JE 26.3}}
*** {{nbt|list}}{{nbt|compound}} A predicate, following this structure recursively.
*** {{nbt|list}}{{nbt|compound}} A predicate, following this structure recursively.
</div>
</div>


<div class="treeview" id="condition_alternative" style="margin-block-end: 1em;">
<div class="treeview" id="condition_alternative" style="margin-block-end: 1em;">
* '''any_of'''&mdash;Evaluates a list of predicates and passes if any one of them passes. Invokable from <b><span style="color:#00af89">any context</span></b>.
* '''any_of''' &mdash; Evaluates a list of predicates and passes if any one of them passes. Invokable from <b><span style="color:#00af89">any context</span></b>.
** {{nbt|list|terms}}: The list of predicates to evaluate.
** {{nbt|list|terms}}: The list of predicates to evaluate.{{until|JE 26.3}} / an inline value, a single namespaced ID, a list of namespaced IDs, a list of inline values, or a hash-prefixed tag ID of a {{cd|minecraft:predicate}} type.{{upcoming|JE 26.3}}
*** {{nbt|list}}{{nbt|compound}} A predicate, following this structure recursively. Note that ''any_of'' only applies to {{nbt|list|terms}}, nested lists are ''all_of''.
*** {{nbt|list}}{{nbt|compound}} A predicate, following this structure recursively. Note that ''any_of'' only applies to {{nbt|list|terms}}, nested lists are ''all_of''.
</div>
</div>


<div class="treeview" id="condition_block_state_property" style="margin-block-end: 1em;">
<div class="treeview" id="condition_block_state_property" style="margin-block-end: 1em;">
* '''block_state_property'''&mdash;Checks the mined block and its [[Minecraft:block states]]. Requires <b><span style="color:#00af89">block state</span></b> provided by [[Minecraft:loot context]], and always <b><span style="color:#d33">fails</span></b> if not provided.
* '''block_state_property'''{{until|JE 26.3}} &mdash; Checks the mined block and its [[Minecraft:block states]]. Requires <b><span style="color:#00af89">block state</span></b> provided by [[Minecraft:loot context]], and always <b><span style="color:#d33">fails</span></b> if not provided.
** {{nbt|string|block}}: A block ID. The test fails if the block doesn't match.
** {{nbt|string|block}}: A block ID. The test fails if the block doesn't match.
** {{nbt|compound|properties}}: ''(Optional)'' A map of block state names to values. Errors if the block doesn't have these properties.
** {{nbt|compound|properties}}: ''(Optional)'' A map of block state names to values. Errors if the block doesn't have these properties.
Line 98: Line 98:


<div class="treeview" id="condition_damage_source_properties" style="margin-block-end: 1em;">
<div class="treeview" id="condition_damage_source_properties" style="margin-block-end: 1em;">
* '''damage_source_properties'''&mdash;Checks properties of the damage source. Requires <b><span style="color:#00af89">origin</span></b> and <b><span style="color:#00af89">damage source</span></b> provided by [[Minecraft:loot context]], and always <b><span style="color:#d33">fails</span></b> if not provided.
* '''damage_source_properties''' &mdash; Checks properties of the damage source. Requires <b><span style="color:#00af89">origin</span></b> and <b><span style="color:#00af89">damage source</span></b> provided by [[Minecraft:loot context]], and always <b><span style="color:#d33">fails</span></b> if not provided.
** {{nbt|compound|predicate}}: Predicate applied to the damage source.
** {{nbt|compound|predicate}}: Predicate applied to the damage source.
*** {{Nbt_inherit/conditions/damage_type|indent=***}}
*** {{Nbt_inherit/conditions/damage_type|indent=***}}
Line 104: Line 104:


<div class="treeview" id="condition_entity_properties" style="margin-block-end: 1em;">
<div class="treeview" id="condition_entity_properties" style="margin-block-end: 1em;">
* '''enchantment_active_check'''&mdash;Checks if the enchantment has been active. Requires <b><span style="color:#00af89">enchantment active status</span></b> provided by [[Minecraft:loot context]], and always <b><span style="color:#d33">fails</span></b> if not provided. It is therefore only usable from the {{cd|enchanted_location}} loot context.  
* '''enchantment_active_check''' &mdash; Checks if the enchantment has been active. Requires <b><span style="color:#00af89">enchantment active status</span></b> provided by [[Minecraft:loot context]], and always <b><span style="color:#d33">fails</span></b> if not provided. It is therefore only usable from the {{cd|enchanted_location}} loot context.  
** {{nbt|boolean|active}}: Whether to check for an active ({{cd|true}}) or inactive ({{cd|false}}) enchantment.
** {{nbt|boolean|active}}: Whether to check for an active ({{cd|true}}) or inactive ({{cd|false}}) enchantment.
</div>
</div>


<div class="treeview" id="condition_entity_properties" style="margin-block-end: 1em;">
<div class="treeview" id="condition_entity_properties" style="margin-block-end: 1em;">
* '''entity_properties'''&mdash;Checks properties of an entity. Invokable from <b><span style="color:#00af89">any context</span></b>.
* '''entity_properties''' &mdash; Checks properties of an entity. Invokable from <b><span style="color:#00af89">any context</span></b>.
** {{nbt|string|entity}}: The entity to check. Specifies an entity from [[Minecraft:loot context]]. Can be {{Loot entity target}}.
** {{nbt|string|entity}}: The entity to check. Specifies an entity from [[Minecraft:loot context]]. Can be {{Loot entity target}}.
** {{nbt|compound|predicate}}: Predicate applied to entity, uses same structure as advancements.
** {{nbt|compound|predicate}}: Predicate applied to entity, uses same structure as advancements.
Line 116: Line 116:


<div class="treeview" id="condition_entity_scores" style="margin-block-end: 1em;">
<div class="treeview" id="condition_entity_scores" style="margin-block-end: 1em;">
* '''entity_scores'''&mdash;Checks the [[Minecraft:scoreboard]] scores of an entity. Requires <b><span style="color:#00af89">the specified entity</span></b> provided by [[Minecraft:loot context]], and always <b><span style="color:#d33">fails</span></b> if not provided.
* '''entity_scores''' &mdash; Checks the [[Minecraft:scoreboard]] scores of an entity. Requires <b><span style="color:#00af89">the specified entity</span></b> provided by [[Minecraft:loot context]], and always <b><span style="color:#d33">fails</span></b> if not provided.
** {{nbt|string|entity}}: The entity to check. Specifies an entity from [[Minecraft:loot context]]. Can be {{Loot entity target}}.
** {{nbt|string|entity}}: The entity to check. Specifies an entity from [[Minecraft:loot context]]. Can be {{Loot entity target}}.
** {{nbt|compound|scores}}: Scores to check. All specified scores must pass for the condition to pass.
** {{nbt|compound|scores}}: Scores to check. All specified scores must pass for the condition to pass.
*** {{nbt|compound|A score}}: Key name is the objective while the value specifies a range of score values required for the condition to pass.
*** {{nbt|compound|A score}}: Key name is the objective while the value specifies a range of score values required for the condition to pass.
**** {{nbt|int}}{{nbt|compound|min}}: A [[Minecraft:Loot table#Number provider|number provider]]. Minimum score. Optional.
**** {{nbt|int}}{{nbt|compound|min}}: A [[Minecraft:Loot table#Number provider|number provider]].{{until|JE 26.3}} / an inline value or a namespaced ID of a {{cd|minecraft:number_provider}} type.{{upcoming|JE 26.3}} Minimum score. Optional.
**** {{nbt|int}}{{nbt|compound|max}}: A [[Minecraft:Loot table#Number provider|number provider]]. Maximum score. Optional.
**** {{nbt|int}}{{nbt|compound|max}}: A [[Minecraft:Loot table#Number provider|number provider]].{{until|JE 26.3}} / an inline value or a namespaced ID of a {{cd|minecraft:number_provider}} type.{{upcoming|JE 26.3}} Maximum score. Optional.
*** {{nbt|int|A 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.
*** {{nbt|int|A 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.
</div>
</div>


<div class="treeview" id="condition_inverted" style="margin-block-end: 1em;">
<div class="treeview" id="condition_inverted" style="margin-block-end: 1em;">
* '''inverted'''&mdash;Inverts another predicate condition. Invokable from <b><span style="color:#00af89">any context</span></b>.
* '''inverted''' &mdash; Inverts another predicate condition. Invokable from <b><span style="color:#00af89">any context</span></b>.
** {{nbt|compound|term}}: The condition to be negated, following the same structure as outlined here, recursively.
** {{nbt|compound|term}}: The condition to be negated, following the same structure as outlined here, recursively.{{until|JE 26.3}} / an inline value or a namespaced ID of a {{cd|minecraft:predicate}} type.{{upcoming|JE 26.3}}
</div>
</div>


<div class="treeview" id="condition_killed_by_player" style="margin-block-end: 1em;">
<div class="treeview" id="condition_killed_by_player" style="margin-block-end: 1em;">
* '''killed_by_player'''&mdash;Checks if there is a {{cd|attacking_player}} entity provided by [[Minecraft:loot context]]. Requires <b><span style="color:#00af89">{{cd|attacking_player}} entity</span></b> provided by [[Minecraft:loot context]], and always <b><span style="color:#d33">fails</span></b> if not provided.
* '''killed_by_player''' &mdash; Checks if there is a {{cd|attacking_player}} entity provided by [[Minecraft:loot context]]. Requires <b><span style="color:#00af89">{{cd|attacking_player}} entity</span></b> provided by [[Minecraft:loot context]], and always <b><span style="color:#d33">fails</span></b> if not provided.
</div>
</div>


<div class="treeview" id="condition_location_check" style="margin-block-end: 1em;">
<div class="treeview" id="condition_location_check" style="margin-block-end: 1em;">
* '''location_check'''&mdash;Checks the current location against location criteria. Requires <b><span style="color:#00af89">origin</span></b> provided by [[Minecraft:loot context]], and always <b><span style="color:#d33">fails</span></b> if not provided.
* '''location_check''' &mdash; Checks the current location against location criteria. Requires <b><span style="color:#00af89">origin</span></b> provided by [[Minecraft:loot context]], and always <b><span style="color:#d33">fails</span></b> if not provided.
** {{nbt|int|offsetX}}: An optional x offset to the location.
** {{nbt|int|offsetX}}: An optional x offset to the location.
** {{nbt|int|offsetY}}: An optional y offset to the location.
** {{nbt|int|offsetY}}: An optional y offset to the location.
Line 144: Line 144:


<div class="treeview" id="condition_match_tool" style="margin-block-end: 1em;">
<div class="treeview" id="condition_match_tool" style="margin-block-end: 1em;">
* '''match_tool'''&mdash;Checks tool used to mine the block. Requires <b><span style="color:#00af89">tool</span></b> provided by [[Minecraft:loot context]], and always <b><span style="color:#d33">fails</span></b> if not provided.
* '''match_block'''{{upcoming|JE 26.3}} &mdash; Matches block state and optionally block entity data and components (if present).
** {{nbt|string}}{{nbt|list|blocks}}: Optional; Can be a single block ID, a list of namespaced block IDs, or a hash-prefixed block tag to match.
**** {{nbt|compound|state}}: Optional; The block state property keys to values to match.
**** {{nbt|compound|nbt}}: Optional; [[Minecraft:Block entity]] NBT to match. See [[Minecraft:Block entity format]]. Match will fail if the field is present, but the block entity is not available in context.
**** {{nbt|compound|components}}: Optional; Map of exact components to match. Match will fail if the field is present, but the block entity is not available in context.
**** {{nbt|compound|predicates}}: Optional; Map of component predicates to match. Match will fail if the field is present, but the block entity is not available in context.
</div>
 
<div class="treeview" id="condition_match_tool" style="margin-block-end: 1em;">
* '''match_tool''' &mdash; Checks tool used to mine the block. Requires <b><span style="color:#00af89">tool</span></b> provided by [[Minecraft:loot context]], and always <b><span style="color:#d33">fails</span></b> if not provided.
** {{nbt|compound|predicate}}: Predicate applied to item, uses same structure as advancements.
** {{nbt|compound|predicate}}: Predicate applied to item, uses same structure as advancements.
*** {{nbt inherit/conditions/item|indent=***}}
*** {{nbt inherit/conditions/item|indent=***}}
Line 150: Line 159:


<div class="treeview" id="condition_random_chance" style="margin-block-end: 1em;">
<div class="treeview" id="condition_random_chance" style="margin-block-end: 1em;">
* '''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 <b><span style="color:#00af89">any context</span></b>.
* '''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 <b><span style="color:#00af89">any context</span></b>.
** {{nbt|float}}{{nbt|compound|chance}}: A [[Minecraft:Loot table#Number provider|number provider]]. Success rate as a number 0.0&ndash;1.0.
** {{nbt|float}}{{nbt|compound|chance}}: A [[Minecraft:Loot table#Number provider|number provider]].{{until|JE 26.3}} / an inline value or a namespaced ID of a {{cd|minecraft:number_provider}} type.{{upcoming|JE 26.3}} Success rate as a number 0.0 &ndash; 1.0.
</div>
</div>


<div class="treeview" id="condition_random_chance_with_looting" style="margin-block-end: 1em;">
<div class="treeview" id="condition_random_chance_with_looting" style="margin-block-end: 1em;">
* '''random_chance_with_enchanted_bonus'''&mdash;Generates a random number between 0.0 and 1.0, and checks if it is less than the value determined using the level of a given enchantment. Requires <b><span style="color:#00af89"><code>attacker</code> entity</span></b> provided by [[Minecraft:loot context]], and if not provided, the enchantment level is regarded as 0.
* '''random_chance_with_enchanted_bonus''' &mdash; Generates a random number between 0.0 and 1.0, and checks if it is less than the value determined using the level of a given enchantment. Requires <b><span style="color:#00af89"><code>attacker</code> entity</span></b> provided by [[Minecraft: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&ndash;1.0.
** {{nbt|float|unenchanted_chance}}: The success rate to use when the enchantment is not present; 0.0&ndash;1.0.
** {{nbt|float}}{{nbt|compound|enchanted_chance}}: [[Minecraft:level-based value]]. The success rate based on the level when then enchantment is present; 0.0&ndash;1.0.
** {{nbt|float}}{{nbt|compound|enchanted_chance}}: [[Minecraft:level-based value]]. The success rate based on the level when then enchantment is present; 0.0&ndash;1.0.
Line 162: Line 171:


<div class="treeview" id="condition_reference" style="margin-block-end: 1em;">
<div class="treeview" id="condition_reference" style="margin-block-end: 1em;">
* '''reference'''&mdash;Invokes a predicate file and returns its result. Invokable from <b><span style="color:#00af89">any context</span></b>. Cannot be used in [[Minecraft:Enchantment_definition#Effect_components|enchantment definitions]].
* '''reference'''{{until|JE 26.3}} &mdash; Invokes a predicate file and returns its result. Invokable from <b><span style="color:#00af89">any context</span></b>. Cannot be used in [[Minecraft:Enchantment_definition#Effect_components|enchantment definitions]].
** {{nbt|string|name}}: The [[Minecraft:resource location]] of the predicate to invoke. A cyclic reference causes a parsing failure.
** {{nbt|string|name}}: The [[Minecraft:resource location]] of the predicate to invoke. A cyclic reference causes a parsing failure.
</div>
</div>


<div class="treeview" id="condition_survives_explosion" style="margin-block-end: 1em;">
<div class="treeview" id="condition_survives_explosion" style="margin-block-end: 1em;">
* '''survives_explosion'''&mdash;Returns success with {{cd|1 ÷ explosion radius}} probability. Requires <b><span style="color:#00af89">explosion radius</span></b> provided by [[Minecraft:loot context]], and always <b><span style="color:#00af89">success</span></b> if not provided.
* '''survives_explosion''' &mdash; Returns success with {{cd|1 ÷ explosion radius}} probability. Requires <b><span style="color:#00af89">explosion radius</span></b> provided by [[Minecraft:loot context]], and always <b><span style="color:#00af89">success</span></b> if not provided.
</div>
</div>


<div class="treeview" id="condition_table_bonus" style="margin-block-end: 1em;">
<div class="treeview" id="condition_table_bonus" style="margin-block-end: 1em;">
* '''table_bonus'''&mdash;Passes with probability picked from a list, indexed by enchantment power. Requires <b><span style="color:#00af89">tool</span></b> provided by [[Minecraft:loot context]]. If not provided, the enchantment level is regarded as 0.
* '''table_bonus''' &mdash; Passes with probability picked from a list, indexed by enchantment power. Requires <b><span style="color:#00af89">tool</span></b> provided by [[Minecraft:loot context]]. If not provided, the enchantment level is regarded as 0.
** {{nbt|string|enchantment}}: [[Minecraft:Resource location]] of enchantment.  
** {{nbt|string|enchantment}}: [[Minecraft:Resource location]] of enchantment.  
** {{nbt|list|chances}}: List of probabilities for enchantment power, indexed from 0.
** {{nbt|list|chances}}: List of probabilities for enchantment power, indexed from 0.
Line 177: Line 186:


<div class="treeview" id="condition_time_check" style="margin-block-end: 1em;">
<div class="treeview" id="condition_time_check" style="margin-block-end: 1em;">
* '''time_check'''&mdash;Compares the current day time (or rather, <code>24000 * day count + day time</code>) against given values. Invokable from <b><span style="color:#00af89">any context</span></b>.
* '''time_check''' &mdash; Compares the current day time (or rather, <code>24000 * day count + day time</code>) against given values. Invokable from <b><span style="color:#00af89">any context</span></b>.
** {{nbt|string|clock}}: {{json ref|world clock}} to check the time of.
** {{nbt|string|clock}}: {{json ref|world clock}} to check the time of.
** {{nbt|compound|value}}: The time to compare the day time against.
** {{nbt|compound|value}}: The time to compare the day time against.
*** {{nbt|int}}{{nbt|compound|min}}: A [[Minecraft:Loot table#Number provider|number provider]]. The minimum value.
*** {{nbt|int}}{{nbt|compound|min}}: A [[Minecraft:Loot table#Number provider|number provider]].{{until|JE 26.3}} / an inline value or a namespaced ID of a {{cd|minecraft:number_provider}} type.{{upcoming|JE 26.3}} The minimum value.
*** {{nbt|int}}{{nbt|compound|max}}: A [[Minecraft:Loot table#Number provider|number provider]]. The maximum value.
*** {{nbt|int}}{{nbt|compound|max}}: A [[Minecraft:Loot table#Number provider|number provider]].{{until|JE 26.3}} / an inline value or a namespaced ID of a {{cd|minecraft:number_provider}} type.{{upcoming|JE 26.3}} 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|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.
** {{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.
Line 187: Line 196:


<div class="treeview" id="condition_value_check" style="margin-block-end: 1em;">
<div class="treeview" id="condition_value_check" style="margin-block-end: 1em;">
* '''value_check'''&mdash;Compares a number against another number or range of numbers. Invokable from <b><span style="color:#00af89">any context</span></b>.
* '''value_check''' &mdash; Compares a number against another number or range of numbers. Invokable from <b><span style="color:#00af89">any context</span></b>.
** {{nbt|int}}{{nbt|compound|value}}: A [[Minecraft:Loot table#Number provider|number provider]]. The number to test.
** {{nbt|int}}{{nbt|compound|value}}: A [[Minecraft:Loot table#Number provider|number provider]].{{until|JE 26.3}} / an inline value or a namespaced ID of a {{cd|minecraft:number_provider}} type.{{upcoming|JE 26.3}} The number to test.
** {{nbt|compound|range}}: The range of numbers to compare {{nbt|int}}{{nbt|compound|value}} against.
** {{nbt|compound|range}}: The range of numbers to compare {{nbt|int}}{{nbt|compound|value}} against.
*** {{nbt|int}}{{nbt|compound|min}}: A [[Minecraft:Loot table#Number provider|number provider]]. The minimum value.
*** {{nbt|int}}{{nbt|compound|min}}: A [[Minecraft:Loot table#Number provider|number provider]].{{until|JE 26.3}} / an inline value or a namespaced ID of a {{cd|minecraft:number_provider}} type.{{upcoming|JE 26.3}} The minimum value.
*** {{nbt|int}}{{nbt|compound|max}}: A [[Minecraft:Loot table#Number provider|number provider]]. The maximum value.
*** {{nbt|int}}{{nbt|compound|max}}: A [[Minecraft:Loot table#Number provider|number provider]].{{until|JE 26.3}} / an inline value or a namespaced ID of a {{cd|minecraft:number_provider}} type.{{upcoming|JE 26.3}} The maximum value.
** {{nbt|int|range}}: Shorthand version of {{nbt|compound|range}} above, used to compare {{nbt|int}}{{nbt|compound|value}} against a single number only. Number providers cannot be used in this shorthand form.
** {{nbt|int|range}}: Shorthand version of {{nbt|compound|range}} above, used to compare {{nbt|int}}{{nbt|compound|value}} against a single number only. Number providers cannot be used in this shorthand form.
</div>
</div>


<div class="treeview" id="condition_weather_check" style="margin-block-end: 1em;">
<div class="treeview" id="condition_weather_check" style="margin-block-end: 1em;">
* '''weather_check'''&mdash;Checks the current game weather. Invokable from <b><span style="color:#00af89">any context</span></b>.
* '''weather_check''' &mdash; Checks the current game weather. Invokable from <b><span style="color:#00af89">any context</span></b>.
** {{nbt|boolean|raining}}: If true, the condition passes only if it is raining or thundering.
** {{nbt|boolean|raining}}: If true, the condition passes only if it is raining or thundering.
** {{nbt|boolean|thundering}}: If true, the condition passes only if it is thundering.
** {{nbt|boolean|thundering}}: If true, the condition passes only if it is thundering.
Line 262: Line 271:
|{{HistoryLine|||dev=snap3|{{cd|minecraft:time_check}} loot predicate: added {{cd|clock}} field.}}
|{{HistoryLine|||dev=snap3|{{cd|minecraft:time_check}} loot predicate: added {{cd|clock}} field.}}
|{{HistoryLine|||dev=pre1|Added the {{cd|minecraft:environment_attribute_check}} loot predicate.}}
|{{HistoryLine|||dev=pre1|Added the {{cd|minecraft:environment_attribute_check}} loot predicate.}}
|{{HistoryLine|java upcoming}}
|{{HistoryLine||26.2|dev=snap3|The entity predicate format has changed from a structure with multiple optional fields to one similar to data component maps.|Added {{cd|minecraft:entity_tags}} entity sub-predicate.}}
|{{HistoryLine||26.2|dev=snap3|The Entity predicate format has changed from a structure with multiple optional fields to one similar to data component maps.|Added {{cd|minecraft:entity_tags}} entity sub-predicate.}}
|{{HistoryLine|||dev=snap4|The entity sub-predicate {{cd|slime}} has been renamed to {{cd|cube_mob}}.}}
|{{HistoryLine|upcoming java}}
|{{HistoryLine||26.3|dev=snap3|New entries added to previously empty {{cd|minecraft:predicate}}: {{cd|minecraft:tool/can_silk_touch}}, {{cd|minecraft:tool/can_shear}}.|The {{cd|minecraft:potion_contents}} data component predicate has been changed to allow matching on specific potion effects.}}
|{{HistoryLine|||dev=snap4|Added the {{cd|match_block}} condition type.
|The {{cd|condition}} field has been renamed to {{cd|type}}.
|Numerous fields in predicates now accept an inline value or a namespaced ID of a corresponding type.
|Removed the {{cd|reference}} condition type.
|Removed the {{cd|block_state_property}} condition type. It has been fully replaced by {{cd|match_block}}.
}}
}}
}}



Latest revision as of 11:08, 23 July 2026

Template:For Template:Exclusive

A predicate (also known as a loot condition) is a data structure commonly used throughout data packs and commands, invoked to check boolean conditions either in the world or within a given Minecraft:loot context. Predicates do not change data or affect the world, they only check information (that they have access to) and return either a pass or a fail. They can be defined and registered in Minecraft:data packs, or they can be directly defined "in-line" in various places. They can be used throughout the game such as in commands, Minecraft:loot tables, and Minecraft:advancements. 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 Minecraft:JSON files in data packs containing the definition for a predicate. The file path indicates the Minecraft:namespaced identifier used to reference it.

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 Minecraft:JSON format.

Predicate files are part of the data pack directory structure, highlighted below:

Template:Data pack directory

The root element of a predicate file can be either an Template:Nbt following the predicate structure below, or an Template:Nbt containing multiple predicates. In the latter case all predicates must evaluate to true.

Usage

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

Commands

Minecraft:Commands or functions can invoke predicate files in two ways:

  • Minecraft:Target selectors: The selector argument 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.
  • Template:Cmd: 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.

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 advancements and loot tables.

Examples

Below are a few simple predicate examples for context.

Example 1: Check if player is holding a diamond sword

{
  "condition": "minecraft:entity_properties",
  "entity": "this",
  "predicate": {
    "equipment": {
      "mainhand": {
        "items": ["minecraft:diamond_sword"]
      }
    }
  }
}

Example 2: Only run if it’s daytime

{
  "condition": "minecraft:time_check",
  "value": { "min": 0, "max": 12000 },
  "period": 24000
}

Example 3: Nested example using any_of

{
  "condition": "minecraft:any_of",
  "terms": [
    { "condition": "minecraft:random_chance", "chance": 0.25 },
    { "condition": "minecraft:weather_check", "raining": true }
  ]
}

These snippets can be placed inside Template:Cd within a data pack, then referenced using commands such as:

/execute if predicate my_pack:daytime_check run say Good morning!

JSON format

This section describes the JSON format of a predicate.

The possible values for Template:Nbt and associated extra contents:

  • all_of — Evaluates a list of predicates and passes if all of them pass. Invokable from any context.
  • any_of — Evaluates a list of predicates and passes if any one of them passes. Invokable from any context.
  • enchantment_active_check — Checks if the enchantment has been active. Requires enchantment active status provided by Minecraft:loot context, and always fails if not provided. It is therefore only usable from the Template:Cd loot context.
  • inverted — Inverts another predicate condition. Invokable from any context.
  • match_blockTemplate:Upcoming — Matches block state and optionally block entity data and components (if present).
    • Template:NbtTemplate:Nbt: Optional; Can be a single block ID, a list of namespaced block IDs, or a hash-prefixed block tag to match.
        • Template:Nbt: Optional; The block state property keys to values to match.
        • Template:Nbt: Optional; Minecraft:Block entity NBT to match. See Minecraft:Block entity format. Match will fail if the field is present, but the block entity is not available in context.
        • Template:Nbt: Optional; Map of exact components to match. Match will fail if the field is present, but the block entity is not available in context.
        • Template:Nbt: Optional; Map of component predicates to match. Match will fail if the field is present, but the block entity is not available in context.
  • random_chance_with_enchanted_bonus — Generates a random number between 0.0 and 1.0, and checks if it is less than the value determined using the level of a given enchantment. Requires attacker entity provided by Minecraft:loot context, and if not provided, the enchantment level is regarded as 0.
  • survives_explosion — Returns success with Template:Cd probability. Requires explosion radius provided by Minecraft:loot context, and always success if not provided.
  • weather_check — Checks the current game weather. Invokable from any context.
    • Template:Nbt: If true, the condition passes only if it is raining or thundering.
    • Template:Nbt: If true, the condition passes only if it is thundering.

History

Template:HistoryTable

See also

External links

Navigation

Template:Navbox Java Edition technical

Minecraft:de:Prädikate Minecraft:fr:Prédicat Minecraft:ja:プレディケート Minecraft:pt:Predicado Minecraft:zh:谓词