Skip to content

Commit 95050da

Browse files
committed
explain Bedrock Edition level.dat in README
1 parent 20b5eee commit 95050da

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,25 @@ $writer = (new \Aternos\Nbt\IO\Writer\StringWriter())->setFormat(\Aternos\Nbt\Nb
9292
$tag->write($writer);
9393
file_put_contents("data.nbt", $writer->getStringData());
9494
```
95+
96+
### Bedrock Edition level.dat
97+
While the Bedrock Edition level.dat file is an uncompressed NBT file,
98+
its NBT data is prepended by two 32-bit little endian integers.
99+
100+
The first one seems to be the version of the Bedrock Edition Storage Tool,
101+
which is also stored in the `StorageVersion` tag of the NBT structure.
102+
103+
The second number is the size of the file's NBT structure (not including the two prepending integers).
104+
105+
A Bedrock Edition level.dat file could be read like this:
106+
```php
107+
$data = file_get_contents("level.dat");
108+
109+
$version = unpack("V", $data)[1];
110+
$dataLength = unpack("V", $data, 4)[1];
111+
112+
if($dataLength !== strlen($data) - 8) {
113+
throw new Exception("Invalid level.dat data length");
114+
}
115+
$tag = \Aternos\Nbt\Tag\Tag::load(new StringReader(substr($data, 8), \Aternos\Nbt\NbtFormat::BEDROCK_EDITION));
116+
```

0 commit comments

Comments
 (0)