Difference between revisions of "Slot Data"

From wiki.vg
Jump to navigation Jump to search
 
(Improved formatting, correct if necessary)
(19 intermediate revisions by 12 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 ==
 
 
 
* [[Protocol#Player_Block_Placement_.280x0F.29|0x0F player block placement]]
 
* [[Protocol#Window_click_.280x66.29|0x66 window click]]
 
* [[Protocol#Set_slot_.280x67.29|0x67 set slot]]
 
* [[Protocol#Window_items_.280x68.29|0x68 window items]] (as an array)
 
* [[Protocol#Creative_inventory_action_.280x6B.29|0x6B creative inventory action]]
 
  
 
== Format ==
 
== Format ==
  
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.
+
{| class="wikitable"
 
+
! Name
For non-empty slots, at least two further fields follow. These fields are a byte (item count) and a short (damage/block metadata)
+
! Type
 +
! Meaning
 +
|-
 +
| Block ID
 +
| Short
 +
| The {{Minecraft Wiki|Data values#Block IDs|item/block ID}}. A value of <code>-1</code> signifies that the slot is empty, and no further data follows.
 +
|-
 +
| Item Count
 +
| Optional Byte
 +
| Not present if Block ID is <code>-1</code>.
 +
|-
 +
| Item Damage
 +
| Optional Short
 +
| Not present if Block ID is <code>-1</code>.
 +
|-
 +
| NBT
 +
| Optional NBT
 +
| Not present if Block ID is <code>-1</code>. If 0, there is no NBT data, and no further data follows. Otherwise the byte is the start of an NBT blob as shown below:
 +
|}
  
For certain block IDs, [[#Enchantable_items|given below]], further data follows. First, a short gives the length of a proceeding byte array. A value of <code>-1</code> signifies no further data.
+
<pre>
 
+
   COMPOUND <nowiki>''</nowiki>
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:
+
     LIST 'StoredEnchantments'
 
 
<code>
 
   COMPOUND: <nowiki>''</nowiki>
 
     LIST: 'ench'
 
 
       COMPOUND
 
       COMPOUND
         SHORT: 'id'
+
         SHORT 'id'
         SHORT: 'lvl'
+
         SHORT 'lvl'
 
       END
 
       END
 
       COMPOUND
 
       COMPOUND
         ...etc
+
         ...
 
       END
 
       END
 +
      ...
 +
    END
 +
    INT 'Unbreakable'
 +
    ...
 
   END
 
   END
</code>
+
</pre>
 
 
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.
 
 
 
== Enchantable items ==
 
  
Every item that has a "damage bar" in-game is considered enchantable by the protocol, though the notchian server/client do not support enchantment of some items. These include: hoes, flint and steel, bows, fishing rods and shears.
+
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.
  
<code>
+
== Examples ==
  0x103, #Flint and steel
 
  0x105, #Bow
 
  0x15A, #Fishing rod
 
  0x167, #Shears
 
 
 
  #TOOLS
 
  #sword, shovel, pickaxe, axe, hoe
 
  0x10C, 0x10D, 0x10E, 0x10F, 0x122, #WOOD
 
  0x110, 0x111, 0x112, 0x113, 0x123, #STONE
 
  0x10B, 0x100, 0x101, 0x102, 0x124, #IRON
 
  0x114, 0x115, 0x116, 0x117, 0x125, #DIAMOND
 
  0x11B, 0x11C, 0x11D, 0x11E, 0x126, #GOLD
 
 
 
  #ARMOUR
 
  #helmet, chestplate, leggings, boots
 
  0x12A, 0x12B, 0x12C, 0x12D, #LEATHER
 
  0x12E, 0x12F, 0x130, 0x131, #CHAIN
 
  0x132, 0x133, 0x134, 0x135, #IRON
 
  0x136, 0x137, 0x138, 0x139, #DIAMOND
 
  0x13A, 0x13B, 0x13C, 0x13D  #GOLD
 
</code>
 
  
Or, more simply:
+
<pre>
 +
  ff ff                            | empty slot
 +
  01 16 01 00 00 00                | a diamond pickaxe
 +
  01 16 01 00 00 01 04 CA FE BA BE | a diamond pickaxe with (made-up) NBT data
 +
</pre>
  
<code>
+
[[Category:Protocol Details]]
        private static bool CanEnchant(short value)
+
[[Category:Minecraft Modern]]
        {
 
            return  (256 <= value && value <= 259) ||
 
                    (267 <= value && value <= 279) ||
 
                    (283 <= value && value <= 286) ||
 
                    (290 <= value && value <= 294) ||
 
                    (298 <= value && value <= 317) ||
 
                    value == 261 || value == 359 ||
 
                    value == 346;
 
        }
 
</code>
 

Revision as of 17:55, 16 May 2016

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

Format

Name Type Meaning
Block ID Short The item/block ID. A value of -1 signifies that the slot is empty, and no further data follows.
Item Count Optional Byte Not present if Block ID is -1.
Item Damage Optional Short Not present if Block ID is -1.
NBT Optional NBT Not present if Block ID is -1. If 0, 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
        SHORT 'id'
        SHORT 'lvl'
      END
      COMPOUND
        ...
      END
      ...
    END
    INT 'Unbreakable'
    ...
  END

See NBT for more information about the NBT format, and here for the contained information and its format.

Examples

  ff ff                            | empty slot
  01 16 01 00 00 00                | a diamond pickaxe
  01 16 01 00 00 01 04 CA FE BA BE | a diamond pickaxe with (made-up) NBT data