Difference between revisions of "Slot Data"

From wiki.vg
Jump to navigation Jump to search
(Updated to 1.3.1)
m (Add type links.)
 
(28 intermediate revisions by 19 users not shown)
Line 1: Line 1:
The '''slot''' data structure is how minecraft represents an item and its associated data in the [[Protocol|minecraft protocol]]
+
The '''Slot''' data structure is how Minecraft represents an item and its associated data in the [[Protocol|Minecraft Protocol]].
  
== Packets ==
+
=== Slot ===
  
* [[Protocol#Player_Block_Placement_.280x0F.29|0x0F player block placement]]
+
{| class="wikitable"
* [[Protocol#Window_click_.280x66.29|0x66 window click]]
+
! Name
* [[Protocol#Set_slot_.280x67.29|0x67 set slot]]
+
! Type
* [[Protocol#Window_items_.280x68.29|0x68 window items]] (as an array)
+
! Meaning
* [[Protocol#Creative_inventory_action_.280x6B.29|0x6B creative inventory action]]
+
|-
 +
| Present
 +
| {{Type|Boolean}}
 +
| True if there is an item in this position; false if it is empty.
 +
|-
 +
| Item ID
 +
| {{Type|Optional}} {{Type|VarInt}}
 +
| Omitted if present is false. The {{Minecraft Wiki|Java Edition data values#Blocks|item ID}}. Item IDs are distinct from block IDs; see [[Data Generators]] for more information
 +
|-
 +
| Item Count
 +
| {{Type|Optional}} {{Type|Byte}}
 +
| Omitted if present is false.
 +
|-
 +
| NBT
 +
| {{Type|Optional}} {{Type|NBT}}
 +
| Omitted if present is false. If 0 (TAG_End), there is no NBT data, and no further data follows. Otherwise the byte is the start of an NBT blob as shown below:
 +
|}
  
== Format ==
+
<pre>
 +
  COMPOUND
 +
    LIST 'StoredEnchantments'
 +
      COMPOUND
 +
        STRING 'id'
 +
        SHORT 'lvl'
 +
      END
 +
      COMPOUND
 +
        ...
 +
      END
 +
      ...
 +
    END
 +
    INT 'Unbreakable'
 +
    ...
 +
  END
 +
</pre>
  
The structure consists of at least a short, which gives the item/block ID [http://www.minecraftwiki.net/wiki/Block_ids#Block_IDs_.28Minecraft_Beta.29]. A value of <code>-1</code> signifies that the slot is empty, and no further data follows.
+
Note that on old versions, the enchantment id was sent as a SHORT, and not as a STRING.
  
For non-empty slots, at least two further fields follow. These fields are a byte (item count) and a short (damage/block metadata)
+
Since 1.20.2 the root compound also has no name anymore. The NBT data starts with one byte indicating the type, followed by the type-specific data.
  
For every block ID, except -1, further data follows. First, a short gives the length of a proceeding byte array. A value of <code>-1</code> signifies no further data.
+
See [[NBT]] for more information about the NBT format, and {{Minecraft Wiki|Player.dat format#Item structure|here}} for the contained information and its format. Note that tool durability is included in NBT, among other things.
  
The byte array (if present) contains gzipped (that is RFC 1952 rather than RFC 1950) [[NBT]] data. The format of this data is as follows:
+
== Examples ==
  
<code>
+
<pre>
   COMPOUND: <nowiki>''</nowiki>
+
   00                      | empty slot
    LIST: 'ench'
+
  01 01 01 00            | a stone block
      COMPOUND
+
   01 01 01 03 12 34 56 78 | a stone block with (made-up) NBT data
        SHORT: 'id'
+
</pre>
        SHORT: 'lvl'
 
      END
 
      COMPOUND
 
        ...etc
 
      END
 
   END
 
</code>
 
  
Each of the inner, untagged COMPOUNDs represents an enchantment, with its ID[http://www.minecraftwiki.net/wiki/Enchantment#Enchantment_Types] and level given as child SHORT elements.
+
[[Category:Protocol Details]]
 +
[[Category:Minecraft Modern]]

Latest revision as of 23:08, 24 February 2024

The Slot data structure is how Minecraft represents an item and its associated data in the Minecraft Protocol.

Slot

Name Type Meaning
Present Boolean True if there is an item in this position; false if it is empty.
Item ID Optional VarInt Omitted if present is false. The item ID. Item IDs are distinct from block IDs; see Data Generators for more information
Item Count Optional Byte Omitted if present is false.
NBT Optional NBT Omitted if present is false. If 0 (TAG_End), there is no NBT data, and no further data follows. Otherwise the byte is the start of an NBT blob as shown below:
  COMPOUND
    LIST 'StoredEnchantments'
      COMPOUND
        STRING 'id'
        SHORT 'lvl'
      END
      COMPOUND
        ...
      END
      ...
    END
    INT 'Unbreakable'
    ...
  END

Note that on old versions, the enchantment id was sent as a SHORT, and not as a STRING.

Since 1.20.2 the root compound also has no name anymore. The NBT data starts with one byte indicating the type, followed by the type-specific data.

See NBT for more information about the NBT format, and here for the contained information and its format. Note that tool durability is included in NBT, among other things.

Examples

  00                      | empty slot
  01 01 01 00             | a stone block
  01 01 01 03 12 34 56 78 | a stone block with (made-up) NBT data