NBTExplorer

Posted on  by 



The Named Binary Tag (NBT) file format is an extremely simple, albeit annoying (did we really need yet another format?)[See Discussion] structured binary format used by the Minecraft game 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.

Mojang has also released a reference implementation along with their Anvil conversion tool, available from https://web.archive.org/web/20190710093131/https://mojang.com/2012/02/new-minecraft-map-format-anvil/

The default filename for the program's installer is NBTExplorer.exe. The following versions: 2.8, 2.7 and 2.6 are the most frequently downloaded ones by the program users. The program lies within Games, more precisely Utilities. Navigate to in NBTExplorer your world save and then to the sub-category of “playerdata.” Change the value in “playerGame Type” using the same 0-4 values outlined in the previous section. To switch our player mode to creative without having to use the in-game work around, we need to edit the “playerGame Type” value to 1. Open NBTExplorer (found here), and open the folder that you've been working in. It should recognize your index.dat and player ID.dat files automatically, and give you a tree-view of their contents. In the level.dat file, it's possible to adjust the time on the map, turn rain on and off, adjust the spawn point for new players, or check the. NBTExplorer is a low-level graphical NBT (Named Binary Tag) data editor for Minecraft. With a directory-tree interface for easily exploring multiple worlds, and support for the latest NBT standard, NBTExplorer is built on top of Substrate.

  • 1Current Uses
  • 2Specification
    • 2.1Bedrock edition
    • 2.2Examples

Current Uses

The NBT format is currently used in several places, chiefly:

  • In the Protocol as part of Slot Data
  • Multiplayer saved server list (servers.dat).
  • Player data (both single player and multiplayer, one file per player). This includes such things as inventory and location.
  • Saved worlds (both single player and multiplayer).
    • World index file (level.dat) that contains general information (spawn point, time of day, etc...)
    • Chunk data (see Region Files)

Nbtexplorer 1.7.10

Unfortunately, the NBT files you can encounter as a developer will be stored in three different ways, just to make things interesting.

  • Uncompressed,
  • gzip'd,
  • zlib'd (aka DEFLATE with a few bytes extra)
NBTExplorer

Libraries

There are many, many libraries for manipulating NBT, written in several languages, and often several per language. For example,

  • C,
  • C++20,
  • C#,
  • D,
  • Go (New),
  • Go (Old, without TagLongArray),
  • Java (Old, without TagLongArray),
  • Javascript,
  • PHP,
  • Python,
  • Ruby,
  • Rust,
  • Scala,
  • Kotlin (Streams, ByteBuffer, NIO, Endianness, Zlib, Gzip, Any Input/Output, Examples in Comments),
  • Kotlin (with a builder DSL and type-safety),
  • Kotlin Multiplatform,
  • You get the idea…

Unless you have specific goals or licence requirements, it is extremely recommended to go with one of the existing libraries.

Utilities

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:

  • NBTExplorer (C#) NBT Directory-tree interface that fully supports the Minecraft .mcr/.mca region files.
  • NEINedit (Obj-C), an OS X specific editor.
  • nbt2yaml (Python), provides command-line editing of NBT via the YAML format, as well as a fast and minimalist NBT parsing/rendering API.
  • nbted (Rust; CC0), provides command-line editing of NBT files via your $EDITOR
  • nbt2json (Golang; MIT) Command-line utility for NBT to JSON/YAML conversion and back. MCPE-NBT support. Can be used as library.

Specification

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.


Type IDType NamePayload Size (Bytes)Description
0TAG_End0Signifies the end of a TAG_Compound. It is only ever used inside a TAG_Compound, and is not named despite being in a TAG_Compound
1TAG_Byte1A single signed byte
2TAG_Short2A single signed, big endian 16 bit integer
3TAG_Int4A single signed, big endian 32 bit integer
4TAG_Long8A single signed, big endian 64 bit integer
5TAG_Float4A single, big endian IEEE-754 single-precision floating point number (NaN possible)
6TAG_Double8A single, big endian IEEE-754 double-precision floating point number (NaN possible)
7TAG_Byte_Array...A length-prefixed array of signed bytes. The prefix is a signed integer (thus 4 bytes)
8TAG_String...A length-prefixed modified UTF-8 string. The prefix is an unsigned short (thus 2 bytes) signifying the length of the string in bytes
9TAG_List...A list of nameless tags, all of the same type. The list is prefixed with the Type ID of the items it contains (thus 1 byte), and the length of the list as a signed integer (a further 4 bytes). If the length of the list is 0 or negative, the type may be 0 (TAG_End) but otherwise it must be any other type. (The notchian implementation uses TAG_End in that situation, but another reference implementation by Mojang uses 1 instead; parsers should accept any type if the length is <= 0).
10TAG_Compound...Effectively a list of a named tags. Order is not guaranteed.
11TAG_Int_Array...A length-prefixed array of signed integers. The prefix is a signed integer (thus 4 bytes) and indicates the number of 4 byte integers.
12TAG_Long_Array...A length-prefixed array of signed longs. The prefix is a signed integer (thus 4 bytes) and indicates the number of 8 byte longs.

There are a couple of simple things to remember:

  • The datatypes representing numbers are in big-endian in Java edition, but Bedrock edition changes things up a bit. See the below section on Bedrock edition
  • Every NBT file will always implicitly be inside a tag compound, and also begin with a TAG_Compound (except in Bedrock edition, see below)
  • The structure of a NBT file is defined by the TAG_List and TAG_Compound types, as such a tag itself will only contain the payload, but depending on what the tag is contained within may contain additional headers. I.e. if it's inside a Compound, then each tag will begin with the TAG_id, and then a string (the tag's name), and finally the payload. While in a list it will be only the payload, as there is no name and the tag type is given in the beginning of the list.

For example, here's the example layout of a TAG_Short on disk:

Type IDLength of NameNamePayload
Decoded29shortTest32767
On Disk (in hex)0200 0973 68 6F 72 74 54 65 73 747F FF

If this TAG_Short had been in a TAG_List, it would have been nothing more than the payload, since the type is implied and tags within the first level of a list are nameless.

Bedrock edition

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.

Little-endian

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.

Nbtexplorer Linux

VarInt

This format is a bit more complex than the others. The differences from Java edition's big-endian format are as follows:

  • TAG_Short, TAG_Float and TAG_Double values are encoded as their little-endian counterparts
  • TAG_Int values and the length prefixes for TAG_List, TAG_Byte_Array, TAG_Int_Array and TAG_Long_Array are encoded as VarInts with ZigZag encoding
  • TAG_Long values are encoded as VarLongs with ZigZag encoding
  • All strings (Tag names and TAG_String values) are length-prefixed with a normal VarInt

Examples

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.

test.nbt

This first example is an uncompressed 'Hello World' NBT example. Should you parse it correctly, you will get a structure similar to the following:

Here is the example explained:

(The entire thing is implicitly inside a compound)Type ID (first element in the implicit compound)Length of name of the root compoundName of the root compoundType ID of first element in root compoundLength of name of first element in rootName of first elementLength of stringStringTag end (of root compound)
DecodedCompound11hello worldString4name9Bananrama
On Disk (in hex)0a00 0b68 65 6c 6c 6f 20 77 6f 72 6c 640800 046e 61 6d 6500 0942 61 6e 61 6e 72 61 6d 6100

bigtest.nbt

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.

servers.dat

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.

level.dat

Nbtexplorer Minecraft

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.

Download

  • test.nbt/hello_world.nbt (uncompressed),
  • bigtest.nbt (gzip compressed)
  • NaN-value-double.dat (compressed, origin version unknown)
  • NBT.txt (original NBT specification)

Nbtexplorer Mac

Retrieved from 'https://wiki.vg/index.php?title=NBT&oldid=16096'




Coments are closed