Difference between revisions of "Entity metadata"

From wiki.vg
Jump to navigation Jump to search
Line 90: Line 90:
 
Mobs are spawned via [[Protocol#Mob_Spawn_.280x18.29|0x18 Mob Spawn]]
 
Mobs are spawned via [[Protocol#Mob_Spawn_.280x18.29|0x18 Mob Spawn]]
  
=== 50: Creeper ===
+
{| class="wikitable"
 
+
|- class="row0"
* <div class="li">Dimensions: 0.6 * 1.8
+
! class="col0" | Type
* '''Index 16''' (byte): Status. Depends on the fuse
+
! class="col1" | Name
* '''Index 17''' (byte): Charged. <code>1</code> if the creeper has been hit by lightning, <code>0</code> otherwise.
+
! class="col2" | x, z
 
+
! class="col3" | y
=== 51: Skeleton ===
+
|- class="row1"
 
+
| class="col0" | 50
* <div class="li">Dimensions: 0.6 * 1.8
+
| class="col1" | Creeper
* No extra metadata
+
| class="col2" | 0.6
 
+
| class="col3" | 1.8
=== 52: Spider ===
+
|- class="row2"
 
+
| class="col0" | 51
* <div class="li">Dimensions: 1.4 * 0.9 (note: has this changed?)
+
| class="col1" | Skeleton
* No extra metadata
+
| class="col2" | 0.6
 
+
| class="col3" | 1.8
=== 53: Giant Zombie ===
+
|- class="row3"
 
+
| class="col0" | 52
* <div class="li">Dimensions: 3.6 * 10.8
+
| class="col1" | Spider
* No extra metadata
+
| class="col2" | 1.4
 
+
| class="col3" | 0.9
=== 54: Zombie ===
+
|- class="row4"
 
+
| class="col0" | 53
* <div class="li">Dimensions: 0.6 * 1.8
+
| class="col1" | Giant Zombie
* No extra metadata
+
| class="col2" | 3.6
 +
| class="col3" | 10.8
 +
|- class="row5"
 +
| class="col0" | 54
 +
| class="col1" | Zombie
 +
| class="col2" | 0.6
 +
| class="col3" | 1.8
 +
|- class="row6"
 +
| class="col0" | 55
 +
| class="col1" | Slime
 +
| class="col2" | 0.6 * size
 +
| class="col3" | 0.6 * size
 +
|- class="row7"
 +
| class="col0" | 56
 +
| class="col1" | Ghast
 +
| class="col2" | 4
 +
| class="col3" | 4
 +
|- class="row8"
 +
| class="col0" | 57
 +
| class="col1" | Zombie Pigman
 +
| class="col2" | 0.6
 +
| class="col3" | 1.8
 +
|- class="row9"
 +
| class="col0" | 58
 +
| class="col1" | Enderman
 +
| class="col2" |
 +
| class="col3" |
 +
|- class="row10"
 +
| class="col0" | 59
 +
| class="col1" | Cave Spider
 +
| class="col2" |
 +
| class="col3" |
 +
|- class="row11"
 +
| class="col0" | 60
 +
| class="col1" | Silverfish
 +
| class="col2" |
 +
| class="col3" |
 +
|- class="row12"
 +
| class="col0" | 61
 +
| class="col1" | Blaze
 +
| class="col2" |
 +
| class="col3" |
 +
|- class="row13"
 +
| class="col0" | 62
 +
| class="col1" | Magma Cube
 +
| class="col2" | 0.6 * size
 +
| class="col3" | 0.6 * size
 +
|- class="row14"
 +
| class="col0" | 63
 +
| class="col1" | Ender Dragon
 +
| class="col2" |
 +
| class="col3" |
 +
|- class="row15"
 +
| class="col0" | 90
 +
| class="col1" | Pig
 +
| class="col2" | 0.9
 +
| class="col3" | 0.9
 +
|- class="row16"
 +
| class="col0" | 91
 +
| class="col1" | Sheep
 +
| class="col2" | 0.6
 +
| class="col3" | 1.3
 +
|- class="row17"
 +
| class="col0" | 92
 +
| class="col1" | Cow
 +
| class="col2" | 0.9
 +
| class="col3" | 1.3
 +
|- class="row18"
 +
| class="col0" | 93
 +
| class="col1" | Duck
 +
| class="col2" | 0.3
 +
| class="col3" | 0.4
 +
|- class="row19"
 +
| class="col0" | 94
 +
| class="col1" | Squid
 +
| class="col2" | 0.95
 +
| class="col3" | 0.95
 +
|- class="row20"
 +
| class="col0" | 95
 +
| class="col1" | Wolf
 +
| class="col2" | 0.6
 +
| class="col3" | 1.8
 +
|- class="row21"
 +
| class="col0" | 96
 +
| class="col1" | Mooshroom?
 +
| class="col2" |
 +
| class="col3" |
 +
|- class="row22"
 +
| class="col0" | 97
 +
| class="col1" | Snowman
 +
| class="col2" |
 +
| class="col3" |
 +
|- class="row23"
 +
| class="col0" | 120
 +
| class="col1" | Villager
 +
| class="col2" |
 +
| class="col3" |
 +
|}
  
=== 55: Slime ===
+
=== Extra Metadata ===
  
* <div class="li">Dimensions: 0.6*size * 0.6*size
+
==== Creeper ====
* '''Index 16''' (byte): Size. Randomly-generated. <code>0</code>, <code>1</code>, <code>2</code> or <code>4</code>.
 
  
=== 56: Ghast ===
+
* Index '''16''' (byte): Status. Depends on the fuse
 +
* Index '''17''' (byte): Charged. <code>1</code> if the creeper has been hit by lightning, <code>0</code> otherwise.
  
* <div class="li">Dimensions: 4 * 4
+
==== Slime / Magma Cube ====
* '''Index 16''' (byte): Aggression. <code>1</code> for aggressive (red eyes), <code>0</code> otherwise.
 
  
=== 57: Zombie Pigman ===
+
* Index '''16''' (byte): Size. Randomly-generated. <code>0</code>, <code>1</code>, <code>2</code> or <code>4</code>.
  
* <div class="li">Dimensions: 0.6 * 1.8
+
==== Ghast ====
* No extra metadata
 
  
=== 58: Enderman ===
+
* Index '''16''' (byte): Aggression. <code>1</code> for aggressive (red eyes), <code>0</code> otherwise.
  
* <div class="li">Dimensions: Unknown
+
==== Enderman ====
* '''Index 16''' (byte): Item in hand
 
* '''Index 17''' (byte): Aggression. <code>1</code> for aggressive, <code>0</code> otherwise.
 
  
=== 59: Cave Spider ===
+
* Index '''16''' (byte): Item in hand
 +
* Index '''17''' (byte): Aggression. <code>1</code> for aggressive, <code>0</code> otherwise.
  
* <div class="li">Dimensions: Unknown
+
==== Pig ====
* No extra metadata
 
  
=== 60: Silverfish ===
+
* Index '''16''' (byte): Saddled. <code>1</code> if the pig is wearing a saddle, <code>0</code> otherwise.
  
* <div class="li">Dimensions: Unknown
+
==== Sheep ====
* No extra metadata
 
  
=== 61: Blaze ===
+
* Index '''16''' (byte): bit 0x10 indicates shearedness. bits 0x0F indicate color (see below).
 
 
* <div class="li">Dimensions: Unknown
 
* No extra metadata
 
 
 
=== 62: Magma Cube ===
 
 
 
* <div class="li">Dimensions: 0.6*size * 0.6*size
 
* '''Index 16''' (byte): Size. Randomly-generated. <code>0</code>, <code>1</code>, <code>2</code> or <code>4</code>.
 
 
 
=== 63: Ender Dragon ===
 
 
 
* <div class="li">Dimensions: Unknown
 
* No extra metadata
 
 
 
=== 90: Pig ===
 
 
 
* <div class="li">Dimensions: 0.9 * 0.9
 
* '''Index 16''' (byte): Saddled. <code>1</code> if the pig is wearing a saddle, <code>0</code> otherwise.
 
 
 
=== 91: Sheep ===
 
 
 
* <div class="li">Dimensions: 0.9 * 1.3
 
* '''Index 16''' (byte): bit 0x10 indicates shearedness. bits 0x0F indicate color (see below).
 
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 226: Line 295:
 
|}
 
|}
  
 +
==== Wolf ====
  
=== 92: Cow ===
+
* <div class="li">Index '''16''' (byte): Flags (see below).
 
+
* Index '''17''' (string): Name of player that tamed wolf.
* <div class="li">Dimensions: 0.9 * 1.3
+
* Index '''18''' (int): Health.
* No extra metadata
 
 
 
=== 93: Duck ===
 
 
 
* <div class="li">Dimensions: 0.3 * 0.4
 
* No extra metadata
 
 
 
=== 94: Squid ===
 
 
 
* <div class="li">Dimensions: 0.95 * 0.95
 
* No extra metadata
 
 
 
=== 95: Wolf ===
 
 
 
* <div class="li">Dimensions: Unknown
 
* '''Index 16''' (byte): Flags (see below).
 
* '''Index 17''' (string): Name of player that tamed wolf.
 
* '''Index 18''' (int): Health.
 
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 261: Line 313:
 
| class="col0" | 1
 
| class="col0" | 1
 
| class="col1" | 0x02
 
| class="col1" | 0x02
| class="col2" | Agressive (red eyes)
+
| class="col2" | Aggressive (red eyes)
 
|- class="row3"
 
|- class="row3"
 
| class="col0" | 2
 
| class="col0" | 2
Line 267: Line 319:
 
| class="col2" | Tamed
 
| class="col2" | Tamed
 
|}
 
|}
 
=== 96: Mooshroom? ===
 
 
Suspected to be mooshroom, but currently undocumented
 
 
=== 97: Snowman ===
 
 
* <div class="li">Dimensions: Unknown
 
* No extra metadata
 
 
=== 120: Villager ===
 
 
* <div class="li">Dimensions: Unknown
 
* No extra metadata
 
  
 
== Objects ==
 
== Objects ==

Revision as of 21:33, 28 October 2011

Entity Metadata Format

The entity metadata format is quirky dictionary format, where the key and the value's type are packed in a single byte.

To parse, repeat the following procedure:

1) Read an unsigned byte
2) If this byte == 127, stop reading
3) Decompose the byte. 
   The bottom 5 bytes (0x1F) serve as an identifier (key) for the data to follow. 
   The top 3 bits (0xE0) serve as a type:
    0: byte
    1: short
    2: int
    3: float
    4: string16,
    5: short, byte, short (slot type)
    6: int, int, int
4) Read and unpack based on the type (above)

In python:

   #socket is positioned at the beginning of the metadata array
   metadata = {}
   x = socket.unpack('byte')
   while x != 127:
       index = x & 0x1F # Lower 5 bits
       ty    = x >> 5   # Upper 3 bites
       if ty == 0: val = socket.unpack('byte') 
       if ty == 1: val = socket.unpack('short') 
       if ty == 2: val = socket.unpack('int') 
       if ty == 3: val = socket.unpack('float') 
       if ty == 4: val = socket.unpack('string16')
       if ty == 5:
           val = {}
           val["id"]     = socket.unpack('short')
           val["count"]  = socket.unpack('byte')
           val["damage"] = socket.unpack('short')
       if ty == 6:
           val = []
           for i in range(3):
               val.append(socket.unpack('int'))
       metadata[index] = (ty, val)
       x = socket.unpack('byte')
   return metadata

Common Metadata

Index 0: Flags

All mobs, objects and players send metadata with index 0. The value is a byte representing 8 boolean flags:

Bit index Bit mask Meaning
0 0x01 Entity on fire
1 0x02 Entity crouched
2 0x04 Entity riding
3 0x08 Sprinting
4 0x10 Eating/Drinking

Index 8: Potion effects

Players and most (all?) mobs send metadata with index 8. This specifies the colour of the bubbling effects around the player.

The value is an int, that should be decomposed into four 4-bit nibbles, representing 0x00RRGGBB

If the value is 0, no potion effects currently apply to the entity.

Mobs

Mobs are spawned via 0x18 Mob Spawn

Type Name x, z y
50 Creeper 0.6 1.8
51 Skeleton 0.6 1.8
52 Spider 1.4 0.9
53 Giant Zombie 3.6 10.8
54 Zombie 0.6 1.8
55 Slime 0.6 * size 0.6 * size
56 Ghast 4 4
57 Zombie Pigman 0.6 1.8
58 Enderman
59 Cave Spider
60 Silverfish
61 Blaze
62 Magma Cube 0.6 * size 0.6 * size
63 Ender Dragon
90 Pig 0.9 0.9
91 Sheep 0.6 1.3
92 Cow 0.9 1.3
93 Duck 0.3 0.4
94 Squid 0.95 0.95
95 Wolf 0.6 1.8
96 Mooshroom?
97 Snowman
120 Villager

Extra Metadata

Creeper

  • Index 16 (byte): Status. Depends on the fuse
  • Index 17 (byte): Charged. 1 if the creeper has been hit by lightning, 0 otherwise.

Slime / Magma Cube

  • Index 16 (byte): Size. Randomly-generated. 0, 1, 2 or 4.

Ghast

  • Index 16 (byte): Aggression. 1 for aggressive (red eyes), 0 otherwise.

Enderman

  • Index 16 (byte): Item in hand
  • Index 17 (byte): Aggression. 1 for aggressive, 0 otherwise.

Pig

  • Index 16 (byte): Saddled. 1 if the pig is wearing a saddle, 0 otherwise.

Sheep

  • Index 16 (byte): bit 0x10 indicates shearedness. bits 0x0F indicate color (see below).
Index Wool Color
0 White
1 Orange
2 Magenta
3 LightBlue
4 Yellow
5 Lime
6 Pink
7 Gray
8 Silver
9 Cyan
10 Purple
11 Blue
12 Brown
13 Green
14 Red
15 Black

Wolf

  • Index 16 (byte): Flags (see below).
  • Index 17 (string): Name of player that tamed wolf.
  • Index 18 (int): Health.
Bit index Bit mask Meaning
0 0x01 Sitting down
1 0x02 Aggressive (red eyes)
2 0x04 Tamed

Objects

Objects are spawned via 0x17 Add Object/Vehicle

ID Name Width Height
1 Boat 1.5 0.6
10 Minecart 0.98 0.7
11 Minecart (storage) 0.98 0.7
12 Minecart (powered) 0.98 0.7
50 Activated TNT 0.98 0.98
60 Arrow (projectile) 0.5 0.5
61 Snowball (projectile) 0.25 0.25
62 Egg (projectile) 0.25 0.25
70 Falling Sand 0.98 0.98
71 Falling Gravel 0.98 0.98
90 Fishing Float 0.25? 0.25?

Other

Players are spawned via 0x14 Named Entity Spawn. They have dimensions 0.6 * 1.8.

Pickups are spawned via 0x15 Pickup Spawn. They have dimensions 0.25 * 0.25.