Minecraft:Loot context: Difference between revisions
More actions
Sync: updated from Minecraft |
Sync: updated from Minecraft |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
{{exclusive|java}} | {{exclusive|java}} | ||
A '''loot context''' is a set of parameters available to [[Minecraft:loot table]]s, [[Minecraft:predicate]]s, [[Minecraft:item modifier]]s, | A '''loot context''' is a set of parameters available to [[Minecraft:loot table]]s, [[Minecraft:predicate]]s, [[Minecraft:item modifier]]s, [[Minecraft:number provider]]s, and [[Minecraft:slot sources]]. | ||
When evaluating these data types in different situations, different parameters will be available. For example, a loot table that runs when the player mines a block would get a '''tool''' parameter if the player used an item to do it, but a loot table that populates a treasure chest would never get a '''tool''' parameter. Loot contexts are [[Minecraft:identifier]]s describing which parameters are available in specific situations. If one is set as the {{nbt|string|type}} of a loot table, it can be used to check whether the loot table depends on parameters that will never be available in its intended use case, allowing the game to report a problem when the [[Minecraft:data pack]] is loaded. | |||
== Loot context types and uses == | == Loot context types and uses == | ||
=== Used | === Used for loot tables === | ||
These loot context types are used | These loot context types are used for evaluating [[Minecraft:loot tables]], and other data types when they appear inside of loot tables. | ||
{| class="wikitable" data-description="Invocation methods for predicates and loot functions" | {| class="wikitable" data-description="Invocation methods for predicates and loot functions" | ||
! scope="col" | Loot context type | ! scope="col" | Loot context type | ||
| Line 13: | Line 15: | ||
! scope="col" | Loot context parameters that ''may be'' supplied | ! scope="col" | Loot context parameters that ''may be'' supplied | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:empty}} || | ||
* Used only by the hardcoded empty loot table. Supplies no loot context parameters. | * Used only by the hardcoded empty loot table. Supplies no loot context parameters. | ||
* Specifying {{cd|"type":"empty"}} means no context parameters can be used in this loot table. | * Specifying {{cd|"type":"empty"}} means no context parameters can be used in this loot table. | ||
| None || None | | None || None | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:chest}} || | ||
* Opening of a container with loot table (can be {{BlockLink|barrel}}, {{BlockLink|chest}}, {{BlockLink|trapped chest}}, {{BlockLink|hopper}}, {{EntityLink|minecart with chest}}, {{EntityLink|id=oak boat with chest|boat with chest}}, {{EntityLink|minecart with hopper}}, {{BlockLink|dispenser}}, {{BlockLink|dropper}}, {{BlockLink|shulker box}}, {{BlockLink|id=shulker boxes|link=Dyed Shulker Box|dyed shulker box}}, and {{BlockLink|decorated pot}}). | * Opening of a container with loot table (can be {{BlockLink|barrel}}, {{BlockLink|chest}}, {{BlockLink|trapped chest}}, {{BlockLink|hopper}}, {{EntityLink|minecart with chest}}, {{EntityLink|id=oak boat with chest|boat with chest}}, {{EntityLink|minecart with hopper}}, {{BlockLink|dispenser}}, {{BlockLink|dropper}}, {{BlockLink|shulker box}}, {{BlockLink|id=shulker boxes|link=Dyed Shulker Box|dyed shulker box}}, and {{BlockLink|decorated pot}}). | ||
* The command {{cmd|loot … loot <loot_table>}}. | * The command {{cmd|loot … loot <loot_table>}}. | ||
| Line 26: | Line 28: | ||
* '''{{cd|this}} entity:''' The entity that opened the chest. | * '''{{cd|this}} entity:''' The entity that opened the chest. | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:fishing}} || | ||
* [[Minecraft:Fishing]]. | * [[Minecraft:Fishing]]. | ||
* The command {{cmd|loot … fish <loot_table>}}. | * The command {{cmd|loot … fish <loot_table>}}. | ||
| Line 35: | Line 37: | ||
* '''{{cd|this}} entity:''' The fishing bobber. | * '''{{cd|this}} entity:''' The fishing bobber. | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:entity}} || | ||
* Loot from a living entity's death. | * Loot from a living entity's death. | ||
* The command {{cmd|loot … kill <target>}}. | * The command {{cmd|loot … kill <target>}}. | ||
| Line 47: | Line 49: | ||
* '''{{cd|attacking_player}} entity:''' The player that most recently damaged the victim entity. | * '''{{cd|attacking_player}} entity:''' The player that most recently damaged the victim entity. | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:equipment}} || | ||
* Used when equipping mobs spawned from a [[Minecraft:Monster Spawner]], [[Minecraft:Minecart with Monster Spawner]] or [[Minecraft:Trial Spawner]]. | * Used when equipping mobs spawned from a [[Minecraft:Monster Spawner]], [[Minecraft:Minecart with Monster Spawner]] or [[Minecraft:Trial Spawner]]. | ||
| | | | ||
| Line 54: | Line 56: | ||
| | | | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:archaeology}} || | ||
* Using a [[Minecraft:brush]] on [[Minecraft:suspicious sand]] or [[Minecraft:suspicious gravel]] that has a loot table. | * Using a [[Minecraft:brush]] on [[Minecraft:suspicious sand]] or [[Minecraft:suspicious gravel]] that has a loot table. | ||
| | | | ||
| Line 62: | Line 64: | ||
| | | | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:vault}} || | ||
* Display of items inside of a {{BlockLink|vault}}. | * Display of items inside of a {{BlockLink|vault}}. | ||
* Opening of a {{BlockLink|vault}}. | * Opening of a {{BlockLink|vault}}. | ||
| Line 71: | Line 73: | ||
* '''Tool:''' The item used as a key. | * '''Tool:''' The item used as a key. | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:gift}} || | ||
* Gift from a cat, villager or sniffer. | * Gift from a cat, villager or sniffer. | ||
* Item laid by a chicken. | * Item laid by a chicken. | ||
| Line 79: | Line 81: | ||
| | | | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:barter}} || | ||
* [[Minecraft:Bartering]] with piglins. | * [[Minecraft:Bartering]] with piglins. | ||
| | | | ||
| Line 85: | Line 87: | ||
| | | | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:advancement_reward}} || | ||
* Loot table set as an [[Minecraft:Advancement/JSON_format|advancement's reward]]. | * Loot table set as an [[Minecraft:Advancement/JSON_format|advancement's reward]]. | ||
| | | | ||
| Line 92: | Line 94: | ||
| | | | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:generic}} || | ||
* Not used. Supplies all loot context parameters. | * Not used. Supplies all loot context parameters. | ||
* Specifying {{cd|"type":"generic"}} or omitting it means no checking for context parameters in this loot table when loading the data pack. | * Specifying {{cd|"type":"generic"}} or omitting it means no checking for context parameters in this loot table when loading the data pack. | ||
| N/A || N/A | | N/A || N/A | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:block}} || | ||
* Loot from mining a block. | * Loot from mining a block. | ||
* Loot from a block being exploded. | * Loot from a block being exploded. | ||
| Line 110: | Line 112: | ||
* '''Explosion radius:''' The radius of the explosion that broke the block, if broken via an explosion. | * '''Explosion radius:''' The radius of the explosion that broke the block, if broken via an explosion. | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:shearing}} || | ||
* Shearing a {{EntityLink|bogged}}, {{EntityLink|sheep}}, {{EntityLink|mooshroom}} or {{EntityLink|snow golem}}. | * Shearing a {{EntityLink|bogged}}, {{EntityLink|sheep}}, {{EntityLink|mooshroom}} or {{EntityLink|snow golem}}. | ||
| | | | ||
| Line 118: | Line 120: | ||
| | | | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:entity_interact}} || | ||
* Using a [[Minecraft:brush]] on an {{EntityLink|armadillo}}. | * Using a [[Minecraft:brush]] on an {{EntityLink|armadillo}}. | ||
| | | | ||
| Line 126: | Line 128: | ||
* '''{{cd|interacting_entity}}:''' The player or entity that interacted. | * '''{{cd|interacting_entity}}:''' The player or entity that interacted. | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:block_interact}} || | ||
* Harvesting a {{BlockLink|beehive}}, {{BlockLink|cave vines}}, or {{BlockLink|sweet berry bush}} | * Harvesting a {{BlockLink|beehive}}, {{BlockLink|cave vines}}, or {{BlockLink|sweet berry bush}} | ||
* Carving a {{BlockLink|pumpkin}}. | * Carving a {{BlockLink|pumpkin}}. | ||
| Line 132: | Line 134: | ||
| | | | ||
* '''Block state:''' The block that was interacted with. | * '''Block state:''' The block that was interacted with. | ||
* '''Origin:''' The center of the block that was interacted with.{{upcoming|java 26.3}} | |||
| | | | ||
* '''Block entity:''' Any block entity data of the block that was interacted with, if it is a block entity. | * '''Block entity:''' Any block entity data of the block that was interacted with, if it is a block entity. | ||
| Line 138: | Line 141: | ||
|} | |} | ||
=== | === Not used in loot tables === | ||
These loot contexts | These loot contexts are not used to evaluate loot tables. Instead, they are used for other invocations of [[Minecraft:predicate]]s, [[Minecraft:item modifier]]s, [[Minecraft:slot sources]]{{upcoming|java 26.3}}, and [[Minecraft:number provider]]s{{upcoming|java 26.3}}. | ||
{| class="wikitable" data-description="Invocation methods for predicates" | {| class="wikitable" data-description="Invocation methods for predicates" | ||
! scope="col" | Loot context type | ! scope="col" | Loot context type | ||
| Line 146: | Line 149: | ||
! scope="col" | Loot context parameters that ''may be'' supplied | ! scope="col" | Loot context parameters that ''may be'' supplied | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:command}} || | ||
* Used | * Used to evaluate [[Minecraft:predicate]]s and [[Minecraft:item modifier]]s by commands such as {{cmd|item modify}} or {{cmd|execute (if{{!}}unless) predicate}}. | ||
| | |||
* '''Origin:''' The position where the command is run. | |||
| | |||
* '''{{cd|this}} entity:''' The entity that is {{cd|@s}} when the command is run. | |||
|- | |||
| {{cdanchor|minecraft:command_compute_default}}{{upcoming|java 26.3}} || | |||
* Used to evaluate [[Minecraft:number provider]]s by {{command|compute default}}. | |||
| | |||
* '''Origin:''' The position where the command is run. | |||
| | |||
* '''{{cd|this}} entity:''' The entity that is {{cd|@s}} when the command is run. | |||
|- | |||
| {{cdanchor|minecraft:command_compute_entity}}{{upcoming|java 26.3}} || | |||
* Used to evaluate [[Minecraft:number provider]]s by {{command|compute entity}}. | |||
| | |||
* '''Origin:''' The position where the command is run. | |||
* '''{{cd|target_entity}}:''' The entity passed to {{command|compute entity}}. | |||
| | |||
* '''{{cd|this}} entity:''' The entity that is {{cd|@s}} when the command is run. | |||
|- | |||
| {{cdanchor|minecraft:command_compute_position}}{{upcoming|java 26.3}} || | |||
* Used to evaluate [[Minecraft:number provider]]s by {{command|compute block}}. | |||
| | | | ||
* '''Origin:''' The position where the command is run. | * '''Origin:''' The position where the command is run. | ||
* '''Block state:''' The current state of the block at the position passed to {{command|compute block}}. | |||
| | | | ||
* '''{{cd|this}} entity:''' The entity that is {{cd|@s}} when the command is run. | * '''{{cd|this}} entity:''' The entity that is {{cd|@s}} when the command is run. | ||
* '''Block entity:''' The block entity of the block passed to {{command|compute block}}, if it was a block entity. | |||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:command_slot_source}}{{upcoming|java 26.3}} || | ||
* Used | * Used to evaluate [[Minecraft:slot sources]] by commands such as {{cmd|item}} or {{cmd|execute (if{{!}}unless) item}}. | ||
| | | | ||
* '''Origin:''' The position where the command is run. | * '''Origin:''' The position where the command is run. | ||
| Line 161: | Line 188: | ||
* '''{{cd|this}} entity:''' The entity that is {{cd|@s}} when the command is run. | * '''{{cd|this}} entity:''' The entity that is {{cd|@s}} when the command is run. | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:selector}} || | ||
* Used | * Used by the {{cd|predicate}} [[Minecraft:Target selectors|target selector]] argument. | ||
| | | | ||
* '''Origin:''' The position of the entity being checked. | * '''Origin:''' The position of the entity being checked. | ||
| Line 168: | Line 195: | ||
| | | | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:advancement_entity}} || | ||
* Used | * Used when an advancement invokes a predicate on an entity. | ||
| | | | ||
* '''{{cd|this}} entity:''' The entity being checked. | * '''{{cd|this}} entity:''' The entity being checked. | ||
| Line 175: | Line 202: | ||
| | | | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:advancement_location}}|| | ||
* Used | * Used when an advancement invokes a predicate on the location of a block where an item was used on. | ||
| | | | ||
* '''{{cd|this}} entity:''' The player to gain the advancement. | * '''{{cd|this}} entity:''' The player to gain the advancement. | ||
| Line 185: | Line 212: | ||
* '''Block entity:''' {{upcoming|java 26.3}} Any block entity data of the block at the location, if it was a block entity. | * '''Block entity:''' {{upcoming|java 26.3}} Any block entity data of the block at the location, if it was a block entity. | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:block_use}}|| | ||
* Used | * Used when an advancement invokes a predicate on {{cd|default_block_use}} trigger. | ||
| | | | ||
* '''{{cd|this}} entity:''' The player to gain the advancement. | * '''{{cd|this}} entity:''' The player to gain the advancement. | ||
| Line 193: | Line 220: | ||
| | | | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:container_process}}{{upcoming|java 26.3}} || | ||
* Used | * Used by [[Minecraft:smelting]] blocks and [[Minecraft:brewing stand]]s to evaluate [[Minecraft:Data component format#cooking_fuel|{{cd|cooking_fuel}}]] and [[Minecraft:Data component format#brewing_fuel|{{cd|brewing_fuel}}]] respectively. | ||
| | | | ||
* '''Origin:''' The center of the workstation block. | * '''Origin:''' The center of the workstation block. | ||
| Line 202: | Line 229: | ||
| | | | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:enchanted_damage}} || rowspan="5"| | ||
* Used by enchantments invoking predicates, see {{slink|Custom enchantment|Effect components}} | * Used by enchantments invoking predicates, see {{slink|Custom enchantment|Effect components}} | ||
| | | | ||
| Line 213: | Line 240: | ||
* '''{{cd|direct_attacker}} entity:''' The projectile entity used in the attack. | * '''{{cd|direct_attacker}} entity:''' The projectile entity used in the attack. | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:enchanted_item}} | ||
| | | | ||
* '''Tool:''' The item enchanted with the evaluated enchantment. | * '''Tool:''' The item enchanted with the evaluated enchantment. | ||
| Line 219: | Line 246: | ||
| | | | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:enchanted_location}} | ||
| | | | ||
* '''{{cd|this}} entity:''' The attacked entity. | * '''{{cd|this}} entity:''' The attacked entity. | ||
| Line 227: | Line 254: | ||
| | | | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:enchanted_entity}} | ||
| | | | ||
* '''{{cd|this}} entity:''' The attacked entity. | * '''{{cd|this}} entity:''' The attacked entity. | ||
| Line 234: | Line 261: | ||
| | | | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:hit_block}} | ||
| | | | ||
* '''{{cd|this}} entity:''' The entity that hit the block. | * '''{{cd|this}} entity:''' The entity that hit the block. | ||
| Line 242: | Line 269: | ||
| | | | ||
|- | |- | ||
| {{ | | {{cdanchor|minecraft:villager_trade}} | ||
| Used for evaluating [[Minecraft:villager trade definition|villager trades]]. | | Used for evaluating [[Minecraft:villager trade definition|villager trades]]. | ||
| | | | ||
Latest revision as of 11:15, 27 August 2026
A loot context is a set of parameters available to Minecraft:loot tables, Minecraft:predicates, Minecraft:item modifiers, Minecraft:number providers, and Minecraft:slot sources.
When evaluating these data types in different situations, different parameters will be available. For example, a loot table that runs when the player mines a block would get a tool parameter if the player used an item to do it, but a loot table that populates a treasure chest would never get a tool parameter. Loot contexts are Minecraft:identifiers describing which parameters are available in specific situations. If one is set as the Template:Nbt of a loot table, it can be used to check whether the loot table depends on parameters that will never be available in its intended use case, allowing the game to report a problem when the Minecraft:data pack is loaded.
Loot context types and uses
Used for loot tables
These loot context types are used for evaluating Minecraft:loot tables, and other data types when they appear inside of loot tables.
| Loot context type | When it is used | Loot context parameters that are supplied | Loot context parameters that may be supplied |
|---|---|---|---|
| Template:Cdanchor |
|
None | None |
| Template:Cdanchor |
|
|
|
| Template:Cdanchor |
|
|
|
| Template:Cdanchor |
|
|
|
| Template:Cdanchor |
|
|
|
| Template:Cdanchor |
|
|
|
| Template:Cdanchor |
|
|
|
| Template:Cdanchor |
|
|
|
| Template:Cdanchor |
|
|
|
| Template:Cdanchor |
|
|
|
| Template:Cdanchor |
|
N/A | N/A |
| Template:Cdanchor |
|
|
|
| Template:Cdanchor |
|
|
|
| Template:Cdanchor |
|
|
|
| Template:Cdanchor |
|
|
|
Not used in loot tables
These loot contexts are not used to evaluate loot tables. Instead, they are used for other invocations of Minecraft:predicates, Minecraft:item modifiers, Minecraft:slot sourcesTemplate:Upcoming, and Minecraft:number providersTemplate:Upcoming.
| Loot context type | When it is used | Loot context parameters that are supplied | Loot context parameters that may be supplied |
|---|---|---|---|
| Template:Cdanchor |
|
|
|
| Template:CdanchorTemplate:Upcoming |
|
|
|
| Template:CdanchorTemplate:Upcoming |
|
|
|
| Template:CdanchorTemplate:Upcoming |
|
|
|
| Template:CdanchorTemplate:Upcoming |
|
|
|
| Template:Cdanchor |
|
|
|
| Template:Cdanchor |
|
|
|
| Template:Cdanchor |
|
|
|
| Template:Cdanchor |
|
|
|
| Template:CdanchorTemplate:Upcoming |
|
|
|
| Template:Cdanchor |
|
|
|
| Template:Cdanchor |
|
||
| Template:Cdanchor |
|
||
| Template:Cdanchor |
|
||
| Template:Cdanchor |
|
||
| Template:Cdanchor | Used for evaluating villager trades. |
|
|
Template:Navbox Java Edition technical
Minecraft:de:Beutekontext Minecraft:fr:Contexte de butin Minecraft:ja:ルート文脈 Minecraft:pt:Contexto de saque Minecraft:zh:战利品上下文