Minecraft:Slot sources: Difference between revisions
More actions
Sync: updated from Minecraft |
Sync: updated from Minecraft |
||
| Line 1: | Line 1: | ||
{{Exclusive|Java}} | |||
{{move|Slot source|reason =Match the name in the registry and the pattern of other similar pages.|admin =1}} | |||
{{improve lead}} | {{improve lead}} | ||
{{wip}} | {{wip}} | ||
'''Slot sources''' | '''Slot sources''' provide any number of [[Minecraft:inventory]] slots in [[Minecraft:data pack]]s via {{cd|slots}} type [[Minecraft:loot table]] entries and in [[Minecraft:argument types#minecraft:slot_source|slot_source]] argument type of [[Minecraft:commands]]{{Upcoming|Java 26.3}}. | ||
== Definition == | |||
{{in development|Java|section=1||26.3}} | |||
Slot sources may be defined inline, or stored as [[Minecraft:JSON]] files and referenced elsewhere, as part of the data pack directory structure: | |||
{{Data pack directory|slot_source|<nowiki><name>.json</nowiki>}} | |||
The root element of a slot source file can be either an {{nbt|compound|object}} following the slot source structure below, or an {{nbt|list|array}} containing multiple slot sources. In the latter case all resulting slots from each source are concatenated together, acting as a shorthand for the {{cd|group}} type. | |||
== Format == | == Format == | ||
* < | <div class="treeview"> | ||
** | * {{nbt|compound}}: The root tag. | ||
** {{nbt|string|type}}: The slot source type as a [[Minecraft:resource location]]. May be any of {{cd|contents|empty|filtered|group|limit_slots|slot_range|d=comma}}. | |||
** Extra fields of the slot source depending on {{nbt|string|type}}, described below. | |||
</div> | |||
The type values can omit or include the namespace {{cd|minecraft}}, for example using the type {{cd|empty}} or {{cd|minecraft:empty}} has the same effect. | |||
=== Inventory-based types === | |||
These types select any number of slots from an inventory provided by [[Minecraft:loot context]]. | |||
==== empty ==== | |||
Empty selection containing no slots. | |||
<div class="treeview" id="empty"> | |||
* {{nbt|compound}}: A slot source | |||
** {{nbt|string|type}}: {{cd|empty}} | |||
** No additional fields. | |||
</div> | |||
==== slot_range ==== | |||
Selects slots within a slot range from the inventory of an entity or block entity. Mirrors the behavior of the [[Minecraft:argument types#minecraft:item_slots|item_slots]] used in {{cmd|item ... from}} previously{{Upcoming|Java 26.3}} from the slot source. | |||
<div class="treeview" id="slot_range"> | |||
* {{nbt|compound}}: A slot source | |||
** {{nbt|string|type}}: {{cd|slot_range}} | |||
** {{nbt|string|source}}: (optional, defaults to {{cd|container}}){{Upcoming|Java 26.3}} An entity or block entity from which the slots will be sourced, from loot context. Can be {{cd|block_entity}}, {{cd|this}}, {{cd|attacking_entity}}, {{cd|last_damage_player}}, {{cd|direct_attacker}}, {{cd|target_entity}}, {{cd|interacting_entity}} or {{cd|container}}{{Upcoming|Java 26.3}}. | |||
** {{nbt|string|slots}}: [[Minecraft:Slot#Command argument|Slot range]] in the format of {{cd|<slot_type>}} or {{cd|<slot_type>.<slot_number>}}, wildcard ({{cd|*}}) is accepted (e.g. {{cd|armor.chest}} or {{cd|container.*}}) | |||
</div> | |||
=== Inheriting types === | |||
The types below restrict, merge or expand on existing slot sources. | |||
==== group ==== | |||
Merges several slot sources into one, with the resulting selection containing all slots from each slot source provided in the order they appear in {{nbt|string|terms}}. If a slot is included in more than one slot source, it will be repeated in the resulting slot source. | |||
<div class="treeview" id="group"> | |||
* {{nbt|compound}}: A slot source | |||
** {{nbt|string|type}}: {{cd|group}} | |||
** {{nbt|string}}{{Upcoming|Java 26.3}}{{nbt|compound}}{{Upcoming|Java 26.3}}{{nbt|list|terms}}: List of slot sources to join. Has to be inline if the group is top-level to avoid circular definitions. | |||
</div> | |||
==== contents ==== | |||
Selects all non-empty{{Until|Java 26.3}} slots from the inventory component of one or more items. If no item is stored inside that component, the resulting selection will be empty. If {{nbt|string|slot_source}} results in more than one item with that component, the resulting selections will be concatenated as with the {{cd|minecraft:group}} type. | |||
<div class="treeview" id="contents"> | |||
* {{nbt|compound}}: A slot source | |||
** {{nbt|string|type}}: {{cd|contents}} | |||
** {{nbt|string|component}}: The inventory component to target. Allowed values are {{cd|minecraft:bundle_contents}}, {{cd|minecraft:charged_projectiles}}, and {{cd|minecraft:container}}. | |||
** {{nbt|string}}{{Upcoming|Java 26.3}}{{nbt|list}}{{nbt|compound|slot_source}}: A slot source containing slots with item(s) to target. | |||
</div> | |||
==== filtered ==== | |||
Applies a filter to the selected slots, excluding any non-matching slots from the resulting selection. | |||
<div class="treeview" id="filtered"> | |||
* | * {{nbt|compound}}: A slot source | ||
*** | ** {{nbt|string|type}}: {{cd|filtered}} | ||
*** | ** {{nbt|compound|item_filter}}: An [[Minecraft:item predicate]] to match against the items in each slot. | ||
** | *** {{Nbt inherit/conditions/item}} | ||
** {{nbt|string}}{{Upcoming|Java 26.3}}{{nbt|list}}{{nbt|compound|slot_source}}: The slot source to filter. | |||
</div> | |||
==== limit_slots ==== | |||
Limits the number of slots provided, with the resulting selection containing at most that number of slots. Any slots bringing the number of slots above that limit will be excluded, in order of inclusion. | |||
<div class="treeview" id="limit_slots"> | |||
* | * {{nbt|compound}}: A slot source | ||
** | ** {{nbt|string|type}}: {{cd|limit_slots}} | ||
** | ** {{nbt|int|limit}}: The maximum number of slots to include in the resulting selection. | ||
** | ** {{nbt|string}}{{Upcoming|Java 26.3}}{{nbt|list}}{{nbt|compound|slot_source}}: The slot source to limit. | ||
</div> | |||
== Example == | |||
Example slot source selecting every slot with more than 16 items from the hotbar and armor slots of an entity:<syntaxhighlight lang="json"> | |||
{ | { | ||
"type": "minecraft:filtered", | "type": "minecraft:filtered", | ||
| Line 81: | Line 128: | ||
|{{HistoryLine||26.3|dev=snap1|Slot sources can now be defined as files inside a datapack, within the {{cd|slot_source}} folder.|{{cd|minecraft:contents}} is no longer restricted to only selecting non-empty slots.|Added {{cd|minecraft:reference}}.|Changed {{cd|minecraft:slot_range}}.}} | |{{HistoryLine||26.3|dev=snap1|Slot sources can now be defined as files inside a datapack, within the {{cd|slot_source}} folder.|{{cd|minecraft:contents}} is no longer restricted to only selecting non-empty slots.|Added {{cd|minecraft:reference}}.|Changed {{cd|minecraft:slot_range}}.}} | ||
|{{HistoryLine|||dev=snap4|Removed {{cd|minecraft:reference}}.| | |{{HistoryLine|||dev=snap4|Removed {{cd|minecraft:reference}}.| | ||
All fields calling for a slot source now accept an inline value or a namespaced ID of a {{cd|minecraft:slot_source}} type if they previously used a single inline value, and additionally a list of inline values, a list of namespaced IDs or a [[Minecraft:Tag (Java Edition)|tag]] when it used multiple.| | |||
Changed {{cd|minecraft:group}} shorthand accordingly.}} | |||
Changed {{cd|minecraft:group}}.}} | |||
|{{HistoryLine|||dev=snap9|Changed {{cd|minecraft:group}} so it can only use an inline definition in a top-level file. | |{{HistoryLine|||dev=snap9|Changed {{cd|minecraft:group}} so it can only use an inline definition in a top-level file. | ||
}}}} | }}}} | ||
Latest revision as of 11:16, 19 August 2026
Template:Exclusive Template:Move Template:Improve lead Template:Wip Slot sources provide any number of Minecraft:inventory slots in Minecraft:data packs via Template:Cd type Minecraft:loot table entries and in slot_source argument type of Minecraft:commandsTemplate:Upcoming.
Definition
Slot sources may be defined inline, or stored as Minecraft:JSON files and referenced elsewhere, as part of the data pack directory structure:
The root element of a slot source file can be either an Template:Nbt following the slot source structure below, or an Template:Nbt containing multiple slot sources. In the latter case all resulting slots from each source are concatenated together, acting as a shorthand for the Template:Cd type.
Format
- Template:Nbt: The root tag.
- Template:Nbt: The slot source type as a Minecraft:resource location. May be any of Template:Cd.
- Extra fields of the slot source depending on Template:Nbt, described below.
The type values can omit or include the namespace Template:Cd, for example using the type Template:Cd or Template:Cd has the same effect.
Inventory-based types
These types select any number of slots from an inventory provided by Minecraft:loot context.
empty
Empty selection containing no slots.
- Template:Nbt: A slot source
- Template:Nbt: Template:Cd
- No additional fields.
slot_range
Selects slots within a slot range from the inventory of an entity or block entity. Mirrors the behavior of the item_slots used in Template:Cmd previouslyTemplate:Upcoming from the slot source.
- Template:Nbt: A slot source
- Template:Nbt: Template:Cd
- Template:Nbt: (optional, defaults to Template:Cd)Template:Upcoming An entity or block entity from which the slots will be sourced, from loot context. Can be Template:Cd, Template:Cd, Template:Cd, Template:Cd, Template:Cd, Template:Cd, Template:Cd or Template:CdTemplate:Upcoming.
- Template:Nbt: Slot range in the format of Template:Cd or Template:Cd, wildcard (Template:Cd) is accepted (e.g. Template:Cd or Template:Cd)
Inheriting types
The types below restrict, merge or expand on existing slot sources.
group
Merges several slot sources into one, with the resulting selection containing all slots from each slot source provided in the order they appear in Template:Nbt. If a slot is included in more than one slot source, it will be repeated in the resulting slot source.
- Template:Nbt: A slot source
- Template:Nbt: Template:Cd
- Template:NbtTemplate:UpcomingTemplate:NbtTemplate:UpcomingTemplate:Nbt: List of slot sources to join. Has to be inline if the group is top-level to avoid circular definitions.
contents
Selects all non-emptyTemplate:Until slots from the inventory component of one or more items. If no item is stored inside that component, the resulting selection will be empty. If Template:Nbt results in more than one item with that component, the resulting selections will be concatenated as with the Template:Cd type.
- Template:Nbt: A slot source
- Template:Nbt: Template:Cd
- Template:Nbt: The inventory component to target. Allowed values are Template:Cd, Template:Cd, and Template:Cd.
- Template:NbtTemplate:UpcomingTemplate:NbtTemplate:Nbt: A slot source containing slots with item(s) to target.
filtered
Applies a filter to the selected slots, excluding any non-matching slots from the resulting selection.
- Template:Nbt: A slot source
- Template:Nbt: Template:Cd
- Template:Nbt: An Minecraft:item predicate to match against the items in each slot.
- Template:NbtTemplate:UpcomingTemplate:NbtTemplate:Nbt: The slot source to filter.
limit_slots
Limits the number of slots provided, with the resulting selection containing at most that number of slots. Any slots bringing the number of slots above that limit will be excluded, in order of inclusion.
- Template:Nbt: A slot source
- Template:Nbt: Template:Cd
- Template:Nbt: The maximum number of slots to include in the resulting selection.
- Template:NbtTemplate:UpcomingTemplate:NbtTemplate:Nbt: The slot source to limit.
Example
Example slot source selecting every slot with more than 16 items from the hotbar and armor slots of an entity:<syntaxhighlight lang="json"> {
"type": "minecraft:filtered",
"item_filter": {
"count": {
"min": 16
}
},
"slot_source": [
{
"type": "minecraft:slot_range",
"source": "this",
"slots": "hotbar.*"
},
{
"type": "minecraft:slot_range",
"source": "this",
"slots": "armor.*"
}
]
} </syntaxhighlight>
History
Template:Navbox Java Edition technical
Minecraft:de:Inventarplatzquelle Minecraft:ja:スロット供与子 Minecraft:pt:Fontes de espaço Minecraft:ru:Источники слотов Minecraft:zh:槽位源