Bedrock Level.dat Editor

3 views
Skip to first unread message

Aide Broeckel

unread,
Aug 4, 2024, 2:33:07 PM8/4/24
to chuckmobisu
NBTeditors (all current ones able to be found via google, and alternate coding tools like wordpad, notepad++, wordpress, adobe, etc...) such editors cannot modify the level.dat file, let alone analyze the player data.

I've run into a brick wall, a user has finally come across a bug i cannot figure out on my own, The level.dat is inaccessable, world still works fine, but a corrupted user or client identity profile cannot be wiped or reset. Does anyone have any suggestions on what will work? Im able to upload a working copy or mimic of the server 100% file integrity so you can basically unzip to android, iphone, or win10 Minecraft Directory and get the server to load on your end, but i need to figure out how to resolve this, this is one of those bugs that if a solution can be found it would be pretty helpful. At least for me and those who are trying to host minecraft pe, or win10 servers (vanilla, or with mods)


On player end, edit their clientid.txt to a new number for them to purge their old profile (But this conflicts for them on any servers they may use with that old clientid #) meaning if i cant wipe it on my end, the player must go through hassle to fix only their client ID, but on my end the corrupted user id still remains within the level.dat


Can a mod please move this thread into the bugs or support section generalized, as this is a bug the relates to Minecraft on Win10, PE, and Xbox Live versions of minecraft (on every scale for the 3 listed).


I'm looking to edit a Minecraft Windows 10 level.dat file in python. I've tried using the package nbt and pyanvil but get the error OSError: Not a gzipped file. If I print open("level.dat", "rb").read() I get a lot of nonsensical data. It seems like it needs to be decoded somehow, but I don't know what decoding it needs. How can I open (and ideally edit) one of these files?


It looks like Mojang doesn't use the same formatting for Java and bedrock, as bedrock's level.dat file is stored in little endian format and uses non-compressed UTF-8.As an alternative, Amulet-Nbt is supposed to be a Python library written in Cython for reading and editing NBT files (supposedly works with Bedrock too).Nbtlib also seems to work, as long as you set byteorder="little when loading the file.


NBT (Named Binary Tag) is a name for data encoding format at the binary level, you certainly know format JSON which is based on the text level. Therefore, we will be able to use the JSON format for some examples, you may also notice that minecraft itself uses JSON to represent NBT in commands such as java commands or simplified bedrock commands ( /give, /replaceitem). See NBT Commands . In this article, we will show NBT in much more detail than you will ever expect, because what you could see in the commands is far from NBT, and we will show you how NBT works and how to read it, also how Minecraft BE itself uses it as well.


NBT, just like JSON, has given types and knows how to read them, for example JSON knows that a compound object starts with the symbol and ends with , it also knows that when it has to read a string, the string always starts with the symbol ", this means that we want to learn to read and understand NBT so you need to know when a composite object starts, and how to read individual types. Now let's look at the table of NBT tags for NBT types and how they are marked in NBT. As it was said, NBT works on a binary level, so you need to know that the smallest data type is a byte, which is 8 bits in size. And individual types can contain multiple bytes, but they can never be 1/2 byte extra or less, not possible! : ) We also cannot say how the tags should be named, because everyone can call NBT tags differently, but they must always have the same binary base (id), id is represented by one byte.


The same reading method applies to all numbers, read as many bytes as the number tag type is large, such as: Int16 (short) is 2 bytes in size, so I will read 2 bytes, but you need to know that Minecraft BE uses the little-endian, unlike Java, it uses big-endian. Little-endian is a way to write or read bytes of numbers.


When reading a number, it is necessary to know what type of number we are reading, we can find out by reading the type (Reading types). Then when we know what type of number we have to read, we read it, for example, if we know that we want type 3, then we look in the table and we know that type 3 is a number of 4-bytes size, so we read 4 bytes. All numbers BE reads/writes with little-endian method.


When reading a string, you need to know its length in bytes, this string length is always written with Int16 (short) 2 bytes (how to read numbers) before the string, i.e. first we read the number, then we read the number of bytes of the number we read before, after we know the bytes we can stuff them through UTF-8 encoding and we get text from them.


When reading a list, we must first read the list (type), whether this list contains numbers or other lists or strings, etc. So first we read the type of this list, then we read the number of elements which is written as an Int32 (int) number, so we read 4 bytes, now we know the type of our elements and their count, so we read this type as many times as we know from the readed number before. Reading the size of a list is not the same as reading the size of a string! Should read Int32 no Int16! This solution does not apply to Byte-List, Int-List, Long-List!


Compound has all properties named so when reading an property it is always necessary to read its name as well. The procedure for reading Compoud is rather simple. First, we read the type, the type can be anything, but if it is equal to an empty byte, then it is the end of the compound and then we jut stop reading, but if the type is not equal to the Compoud Ending tag, then the significant type of the property that we will read. The read property is always followed by the name (key), which needs to be read as a string, and after the string is read, then we can read value.


When reading Minecraft NBT files, it is always important to be careful if there is no Bedrock Header at the beginning of the file, see Bedrock NBT Header, but not all MCBE NBT files contain this header, for example .mcstructure also does not contain a Bedrock NBT header, unlike level.dat. You also need to pay attention to the root element in the file, i.e. the list or compoud, The root element also looks like a property, so you need to read the name of this root property, although Bedrock does not use these names, so these names are empty, but they are there. Here is how .mcstructure looks like where JSON represents NBT.


There is no certain procedure for writing, because it is the same mothods as when reading, but backwards. That's why we recommend first understanding NBT and learning to read it correctly, then it won't be difficult to write NBT.


The NBT bedrock Header is indicated by two 4-byte numbers, the first is always 8 and the second indicates the size of the nbt structure in bytes. E.g. - 08 00 00 00 - bf 00 00 00 -


Little-Endian is the common method of writing numbers in bytes to streams or files. It's not a science and it's easy to understand. So if Int16 (short) of value 0x5a72 then we convert it to bytes [0x5a, 0x72] and then reverse their order that means [0x72, 0x5a] and write d file: 72 5a. It may seem illogical, but little-endian is almost always used when writing and reading from files. A single byte is the same in both methods because it is one byte in size. For example:


The Named Binary Tag (NBT) file format is an extremely simple and efficient structured binary format used by Minecraft for a variety of things. Due to this, several third-party utilities now also utilize the format. You may find example files at the bottom of this article.


Almost every 3rd-party Minecraft application uses NBT on some level. There also exist several dedicated NBT editors, which will likely be useful to you if you are developing an NBT library of your own. These include:


The NBT file format is extremely simple, and writing a library capable of reading/writing it is a simple affair. There are 13 datatypes supported by this format, one of which is used to close compound tags. It is strongly advised to read this entire section or you may run into issues.


Bedrock edition makes a couple of significant changes to the NBT format. First of all, first tag in an NBT file can sometimes be a TAG_List instead of a TAG_Compound. Additionally, NBT data is encoded in one of two different formats, a little-endian version intended for writing to disk, and a VarInt version intended for transport over the network.


Identical to the big-endian format used by Java edition, but all numbers are encoded in little-endian. This includes the 16-bit length prefix before tag names and TAG_String values, as well as TAG_Float and TAG_Double values.


There are two defacto example files used for testing your implementation (test.nbt & bigtest.nbt), originally provided by Markus. The example output provided below was generated using PyNBT's debug-nbt tool.


This second example is a gzip compressed test of every available tag. If your program can successfully parse this file, then you've done well. Note that the tags under TAG_List do not have a name, as mentioned above.


The servers.dat file contains a list of multiplayer servers you've added to the game. To mix things up a bit, this file will always be uncompressed. Below is an example of the structure seen in servers.dat.


This final example is of a single player level.dat, which is compressed using gzip. Notice the player's inventory and general world details such as spawn position, world name, and the game seed.


When you create a Minecraft world, you select your game mode, and that mode is fixed for the lifetime of the world. Or is it? Read on as we show you how to sidestep the game mode lock to temporarily or permanently change your game's mode.

3a8082e126
Reply all
Reply to author
Forward
0 new messages