Difference between revisions of "Entity metadata"

From wiki.vg
Jump to navigation Jump to search
(Updated to 1.3.1)
m (→‎Entity Metadata Format: update the "not currently used" gist for 1.3.1)
Line 40: Line 40:
 
|}
 
|}
  
<nowiki>*</nowiki>Not currently used (last checked in 1.2.5 [http://gist.github.com/0a1062c3b5c2d268f7e9])
+
<nowiki>*</nowiki>Not currently used (last checked in 1.3.1 [http://gist.github.com/0a1062c3b5c2d268f7e9])
  
  

Revision as of 05:48, 14 August 2012

Entity Metadata Format

Note that entity metadata is a totally distinct concept from block metadata.

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 bits (0x1F) serve as an identifier (key) for the data to follow.
    The top 3 bits (0xE0) serve as a type.
  4. Read and unpack based on the type (below)
Type Meaning
0 byte
1 short
2 int
3 float*
4 string16
5 short, byte, short (slot type)*
6 int, int, int (x, y, z)*

*Not currently used (last checked in 1.3.1 [1])


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 bits
    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, byte: 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/Blocking (any right click action?)

Index 1, short: Drowning counter

Initialized to 300 on entity spawn. When underwater, this is decremented by 3 every tick (and sent S->C with Entity Metadata (0x28)). If the value dips below -19, an Entity Status (0x26) is sent (i.e. the entity is hurt) and counter is reset to 0.

Seems to be sent for *at least* all mobs. Not sure about players.

Index 8, int: 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 bytes, representing 0x00RRGGBB

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

Index 12, int: Animals

0 for ordinary animals.

Baby animals have the value -23999. This corresponds to the number of ticks in a minecraft day, which is how long it takes for a baby animal to "grow up". It is therefore considered likely that this field determines the size of the animal, and that Entity Metadata will update it as the animal grows.

When an animal becomes a parent this value is set to 6000 and is then decreased over time. Probably a countdown until they can have a new baby.

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 Chicken 0.3 0.4
94 Squid 0.95 0.95
95 Wolf 0.6 1.8
96 Mooshroom
97 Snowman
98 Ocelot
99 Iron Golem
120 Villager

Extra Metadata

Creeper

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

Spider / Cave Spider

  • Index 16 (byte): Unknown, Values 0 and 1. Possibly aggression.

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.

Blaze

  • Index 16 (byte): Attacking. 1 sets the blaze on fire, and shortly after it will attack. 0 signals the end of the attack.#

Ender Dragon

  • Index 16 (short): Health. Full health = 200

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 Light Blue
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. Values from 8 to 0
Bit index Bit mask Meaning
0 0x01 Sitting down
1 0x02 Aggressive (red eyes)
2 0x04 Tamed

Ocelot

  • Index 16 (byte): Flags. Same as Wolf but without the Agressive flag.
  • Index 17 (string): Name of player that tamed the ocelot.
  • Index 18 (byte): Skin: 0 - ocelot, 3 - tamed cat, probably 1 and 2 too.


Villager

  • Index 16 (int): Unknown, example: 0


Iron Golem

  • Index 16 (byte): Unknown, example: 1

Objects

Objects are spawned via 0x17 Spawn 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
51 EnderCrystal 1.25? 2.25?
60 Arrow (projectile) 0.5 0.5
61 Snowball (projectile) 0.25 0.25
62 Egg (projectile) 0.25 0.25
70 Falling Objects - The object data field specifies the block id. in vanilla only used to spawn falling sand/falling gravel/falling dragon eggs 0.98 0.98
72 Eye of Ender
74 Falling Dragon Egg 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.

Paintings are spawned via 0x19 Entity: Painting. Their dimensions depend on their type.