-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bedrock edition level.dat #4
Comments
https://minecraft.gamepedia.com/Bedrock_Edition_level_format sounds like bedrock uses zlib-compressed nbt (which should be supported.) I don't have bedrock edition and have never tested with it, are you able to post a failing level.dat and then myself or somebody else may be able to debug it. |
Thanks for the quick response. Here's a zipped copy |
Documented here https://wiki.vg/NBT#Bedrock_edition are (hopefully all) changes to the nbt format with the Bedrock edition. |
I'm finding it hard to find a canonical description of the level.dat data format - but the the leveldb_mcpe repository also seems to support the snappy compression format. Could this be what the header is indicating? |
Actually I think the file may be uncompressed:
Which seems to conform to 4 bytes (LE) of a version (8) followed by 4 bytes LE which correspond to the size of the file - 8. Assuming the tags are 2 byte LE you then get a TAG_Compound, TAG_String, 13 byte length and the first string starting with 'B'. |
Confirmed. With a quick and dirty hack to https://github.com/chmod222/cNBT to skip 8 bytes and byte swap everything (including the strings) I was able to parse a valid set of NBT tags:
So it looks like all (?) that needs doing is a) recognise a Bedrock header and b) read LE bytes for most of the tag data. |
Fantastic work! Thanks @stsquad |
@richbirch well the hack was the easy bit. The reason I hacked it in the C library was it was the quickest way for me to test the theory. The real fix requires doing a bit of re-factoring to nbted so the low level tag accessors can take the endianess required. However my rust is very much beginner level at the moment so it will have to wait until I get a decent free weekend to work on it. |
Thanks for looking at this @stsquad. I've actually dived in and coded a parser for this file myself in my preferred language, Scala. It only took a couple of hours thanks to the hints you gave above. My next step is to convert parsed data back to the level.dat format so I can update values as required. The exciting thing is that this opens up the possibility of doing things like creating a flat world on a server without having to first create it locally and then upload the world to the server. |
Changes: - A few more changes to what I've been working on for the last few days. This commit makes the tag reading methods for the Reader more consistent, and de-abstracts the logic for reading the bytes from the data buffer. It was challenging for me to find where the function calls were when I first looked into the original NBT.js library, so while a bit repetitive, I took those function calls out of the extra `read()` method and moved their logic directly into their own tag methods, to better show what they were doing to get the byte data using the `DataView`. - I also renamed some of the Reader attributes, just to make them a little more readable too. I have nothing against camelcase haha, but it's sometimes easier to just have to remember one word for a variable in some spots. - Simplified the header checking functions! Took out a few extra steps that get you to the same place. Got some inspiration and help from a few different places for these last few commits: https://github.com/janispritzkau/nbt-ts https://gist.github.com/jonathanlurie/04fa6343e64f750d03072ac92584b5df (Will be using this soon, thought I'd add it now just in case I lose track of it) C4K3/nbted#4 https://stackoverflow.com/questions/30229522/how-can-i-join-an-array-of-numbers-into-1-concatenated-number https://stackoverflow.com/questions/54019143/issue-with-combining-large-array-of-numbers-into-one-single-number
Changes: - A few more changes to what I've been working on for the last few days. This commit makes the tag reading methods for the Reader more consistent, and de-abstracts the logic for reading the bytes from the data buffer. It was challenging for me to find where the function calls were when I first looked into the original NBT.js library, so while a bit repetitive, I took those function calls out of the extra `read()` method and moved their logic directly into their own tag methods, to better show what they were doing to get the byte data using the `DataView`. - I also renamed some of the Reader attributes, just to make them a little more readable too. I have nothing against camelcase haha, but it's sometimes easier to just have to remember one word for a variable in some spots. - Simplified the header checking functions! Took out a few extra steps that get you to the same place. Got some inspiration and help from a few different places for these last few commits: https://github.com/janispritzkau/nbt-ts https://gist.github.com/jonathanlurie/04fa6343e64f750d03072ac92584b5df (Will be using this soon, thought I'd add it now just in case I lose track of it) C4K3/nbted#4 https://stackoverflow.com/questions/30229522/how-can-i-join-an-array-of-numbers-into-1-concatenated-number https://stackoverflow.com/questions/54019143/issue-with-combining-large-array-of-numbers-into-one-single-number
Changes: - A few more changes to what I've been working on for the last few days. This commit makes the tag reading methods for the Reader more consistent, and de-abstracts the logic for reading the bytes from the data buffer. It was challenging for me to find where the function calls were when I first looked into the original NBT.js library, so while a bit repetitive, I took those function calls out of the extra `read()` method and moved their logic directly into their own tag methods, to better show what they were doing to get the byte data using the `DataView`. - I also renamed some of the Reader attributes, just to make them a little more readable too. I have nothing against camelcase haha, but it's sometimes easier to just have to remember one word for a variable in some spots. - Simplified the header checking functions! Took out a few extra steps that get you to the same place. Got some inspiration and help from a few different places for these last few commits: https://github.com/janispritzkau/nbt-ts https://gist.github.com/jonathanlurie/04fa6343e64f750d03072ac92584b5df (Will be using this soon, thought I'd add it now just in case I lose track of it) C4K3/nbted#4 https://stackoverflow.com/questions/30229522/how-can-i-join-an-array-of-numbers-into-1-concatenated-number https://stackoverflow.com/questions/54019143/issue-with-combining-large-array-of-numbers-into-one-single-number
For those just wanting to edit NBT files for MC Bedrock, I found a working NBT editor as of 27/10/24 for MCB 1.21 |
Hi
Do you plan to support bedrock edition level.dat files? Currently when I try to open them I get:
It'd be awesome to be able to change settings via a command line tool
Thanks
Rich
The text was updated successfully, but these errors were encountered: