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

Minecraft:Slot sources: Difference between revisions

From SAS Gaming Wiki
SyncBot (talk | contribs)
Sync: updated from Minecraft
SyncBot (talk | contribs)
Sync: updated from Minecraft
 
(2 intermediate revisions by the same user not shown)
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''' allow the location of any [[Minecraft:inventory]] slot to be specified within [[Minecraft:data pack]]s and the arguments of [[Minecraft:commands]].
'''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 ==
Slot sources are JSON objects, with the following fields.
* <code>type</code>: the slot source type.
* <code><type-specific></code>: additional fields depending on the type.


* <code>minecraft:empty</code> Type
<div class="treeview">
** Empty selection containing no slots.
* {{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.


* <code>minecraft:group</code> Type
<div class="treeview" id="filtered">
** Merges several slot sources into one, with the resulting selection containing all slots from each slot source provided.
* {{nbt|compound}}: A slot source
*** If a slot is included in more than one slot source, it will be repeated in the resulting slot source.
** {{nbt|string|type}}: {{cd|filtered}}
*** e.g. <code>[a, b] + [c, a]</code> -> <code>[a, b, c, a]</code>
** {{nbt|compound|item_filter}}: An [[Minecraft:item predicate]] to match against the items in each slot.
** Format:
*** {{Nbt inherit/conditions/item}}
*** <code>terms</code>: list of slot sources to join.
** {{nbt|string}}{{Upcoming|Java 26.3}}{{nbt|list}}{{nbt|compound|slot_source}}: The slot source to filter.
** Can alternatively be written inline as a list of slot sources.
</div>


* <code>minecraft:slot_range</code> Type
==== limit_slots ====
** Selects slots within a slot range from the inventory of an entity or block entity.
** Mirrors the behavior of the <code>from</code> argument of the <code>/[[Minecraft:Commands/item|item]]</code> command.
** Format:
*** <code>source</code>: an entity or block entity from which the slots will be sourced, from loot context.
**** Can be <code>block_entity</code>, this, <code>attacking_entity</code>, <code>last_damage_player</code>, <code>direct_attacker</code>, <code>target_entity</code>, or <code>interacting_entity</code>
*** <code>slots</code>: a slot range in the format of <code><slot_type></code> or <code><slot_type>.<slot_number></code> (e.g. <code>armor.chest</code> or <code>container.*</code>).


* <code>minecraft:contents</code> Type
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.
** Selects all non-empty slots from the inventory component of one or more items.
*** If no item is stored inside that component, the resulting selection will be empty.
** The location of the item(s) whose inventory component to use is specified by another slot source.
*** If the slot source includes more than one item with that component, the resulting selections will be merged identically as with the <code>minecraft:group</code> type.
*** e.g. <code>Bundle [a, b] + Shulker Box [c, d]</code> -> <code>[a, b, c, d]</code>
** Format:
*** <code>component</code>: the inventory component to target.
**** Allowed values are <code>minecraft:bundle_contents</code>, <code>minecraft:charged_projectiles</code>, and <code>minecraft:container</code>
*** <code>slot_source</code>: a slot source containing slots with item(s) to target.


* <code>minecraft:filtered</code> Type
<div class="treeview" id="limit_slots">
** Applies a filter to the selected slots, excluding any non-matching slots from the resulting selection.
* {{nbt|compound}}: A slot source
** Format:
** {{nbt|string|type}}: {{cd|limit_slots}}
*** <code>item_filter</code>: an item predicate to match against the items in each slot.
** {{nbt|int|limit}}: The maximum number of slots to include in the resulting selection.
*** <code>slot_source</code>: the slot source to filter.
** {{nbt|string}}{{Upcoming|Java 26.3}}{{nbt|list}}{{nbt|compound|slot_source}}: The slot source to limit.
</div>


* <code>minecraft:limit_slots</code> Type
== Example ==
** Limits the number of slots provided, with the resulting selection containing at most that number of slots.
Example slot source selecting every slot with more than 16 items from the hotbar and armor slots of an entity:<syntaxhighlight lang="json">
*** Any slots bringing the number of slots above that limit will be excluded, in order of inclusion.
*** e.g. <code>[a, b, c, d]</code> -> <code>[a, b, c]</code> if the limit is set to <code>3</code>
** Format:
*** <code>limit</code>: integer, the maximum number of slots to include in the resulting selection.
*** <code>slot_source</code>: the slot source to limit.
* 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 80: Line 127:
|{{HistoryLine|upcoming java}}
|{{HistoryLine|upcoming java}}
|{{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.}}
|{{HistoryLine|||dev=snap9|Changed {{cd|minecraft:group}} so it can only use an inline definition in a top-level file.
}}}}


== Navigation ==
== Navigation ==

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

Template:In development

Slot sources may be defined inline, or stored as Minecraft:JSON files and referenced elsewhere, as part of the data pack directory structure:

Template:Data pack directory

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

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.

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.

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.

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.

filtered

Applies a filter to the selected slots, excluding any non-matching slots from the resulting selection.

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.

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:HistoryTable

Navigation

Template:Navbox Java Edition technical

Minecraft:de:Inventarplatzquelle Minecraft:ja:スロット供与子 Minecraft:pt:Fontes de espaço Minecraft:ru:Источники слотов Minecraft:zh:槽位源