Difference between revisions of "Entity metadata"
(Oops) |
Barneygale (talk | contribs) |
||
Line 91: | Line 91: | ||
Players and most (all?) mobs send metadata with index <code>8</code>. This specifies the colour of the bubbling effects around the player. | Players and most (all?) mobs send metadata with index <code>8</code>. This specifies the colour of the bubbling effects around the player. | ||
− | The value is an int, that should be decomposed into four | + | The value is an int, that should be decomposed into four bytes, representing <code>0x00RRGGBB</code> |
If the value is 0, no potion effects currently apply to the entity. | If the value is 0, no potion effects currently apply to the entity. | ||
− | |||
=== Index 12, int: Animals === | === Index 12, int: Animals === |
Revision as of 05:10, 7 March 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: 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 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. This needs to be confirmed by someone!
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 | ||
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.
Spider
- Index 16 (byte): Unknown - possibly aggression.
Slime / Magma Cube
- Index 16 (byte): Size. Randomly-generated.
0
,1
,2
or4
.
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.
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 |
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 Sand | 0.98 | 0.98 |
71 | Falling Gravel | 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.