File tree 1 file changed +22
-0
lines changed
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -92,3 +92,25 @@ $writer = (new \Aternos\Nbt\IO\Writer\StringWriter())->setFormat(\Aternos\Nbt\Nb
92
92
$tag->write($writer);
93
93
file_put_contents("data.nbt", $writer->getStringData());
94
94
```
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
+ ```
You can’t perform that action at this time.
0 commit comments