Difference between revisions of "Entity metadata"

From wiki.vg
Jump to navigation Jump to search
Line 328: Line 328:
 
! class="col0" | ID
 
! class="col0" | ID
 
! class="col1" | Name
 
! class="col1" | Name
! class="col2" | Width
+
! class="col2" | x, z
! class="col3" | Height
+
! class="col3" | y
 
|- class="row1"
 
|- class="row1"
 
| class="col0" | 1
 
| class="col0" | 1

Revision as of 21:35, 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 x, z y
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.