Skip to main content

Read and write Minecraft NBT files using Yaml.

Project description

nbt2yaml presents a command line interface for reading and editing Minecraft NBT files using a custom YAML format. It also includes a Python API for parsing and writing NBT files to/from a simple Python data structure.

The key tool is nbtedit, a command line utility that will shell out the YAML version of the target NBT file to your editor of choice, allowing relatively easy editing of NBT data. When the editing session is closed, the saved file is parsed back into NBT, and if changes have occurred, the original file is updated; a copy of the previous version is saved as well.

NBT format: http://wiki.vg/NBT

YAML: http://www.yaml.org/

Installation

First, be sure to read the disclaimer down below.

Install via pip:

pip install nbt2yaml

Once installed, the nbtedit, nbt2yaml, and yaml2nbt commands should be available, from the same place other Python utilities are installed.

Commands

Note that an nbt file is typically in gzip format. nbt2yaml commands will assume gzip format for all nbt files written and read, unless the --no-gzip flag is specified.

For the nbt2yaml and yaml2nbt commands, the filename can be specified as -, which indicates the data should be read from standard input.

nbtedit

Edits an nbt file in-place, allowing YAML format within the editor.

The script uses the standard EDITOR environment variable to determine which text editor should be invoked.

The program detects if changes were made when the editing session is closed; if so, the existing nbt file is copied to a backup unconditionally, and the new data is written to the file in place.

Synopsis:

usage: nbtedit [-h] [-n] filename

Edit an nbt file in-place in Yaml format.

positional arguments:
  filename       filename

optional arguments:
  -h, --help     show this help message and exit
  -n, --no-gzip  Don't use gzip

nbt2yaml

Dumps an nbt file as YAML to standard output:

usage: nbt2yaml [-h] [-n] filename

Dump an nbt file or stream to yaml.

positional arguments:
  filename       Filename. Specify as '-' to read from stdin.

optional arguments:
  -h, --help     show this help message and exit
  -n, --no-gzip  Don't use gzip

yaml2nbt

Dumps a YAML file generated by nbt2yaml as nbt to standard output:

usage: yaml2nbt [-h] [-n] filename

Dump a yaml file or stream to nbt.

positional arguments:
  filename       Filename. Specify as '-' to read from stdin.

optional arguments:
  -h, --help     show this help message and exit
  -n, --no-gzip  Don't use gzip

Example Use

Suppose we want to switch the “GameMode” from “0” (survival) to “1” (creative).

First, ensure that Minecraft itself is not running. Then, navigate to where your Minecraft save files are. Here’s how it looks on a mac:

$ cd ~/Library/Application\ Support/minecraft/saves/

Once there, edit the level.dat file for any selected world:

nbtedit myworld/level.dat

Assuming you have your EDITOR variable set, an editor like vim, nano, emacs, or something else should pop up. Window based editors can be used if they present a command line command that doesn’t exit until the file is saved (such as, I can use mate -w here to use TextMate).

Then navigate down to the “GameType” value:

  - foodSaturationLevel: 0.0
  - FallDistance: 0.0
  - XpTotal: 0
  - Rotation:
    - -476.3782043457031
    - 28.349964141845703
  - Xp: 0
- RandomSeed: !long "1201953322384967445"
- GameType: 0
- MapFeatures: !byte "0"
- version: 19132
- Time: !long "5601373"
- raining: !byte "0"
- thunderTime: 19527

Change it from “0” (survival) to “1” (creative):

- RandomSeed: !long "1201953322384967445"
- GameType: 1
- MapFeatures: !byte "0"

Save the file. nbtedit reports that it saved a copy of the old file and wrote the changes to the existing file. Now you can build some castles !

Format

The specifics of how NBT is mapped to YAML is of course a decision this program has to make, as there are any number of ways to do it. The goal here is to have a YAML format that is as minimal and readable as possible, while still maintaining the ability to write the identical nbt file as the one parsed; for this reason, many datatypes have explicit directives (i.e. short, long, double, byte) which will result in the appropriate nbt tag (i.e. TAG_Short, TAG_Long, TAG_Double, TAG_Byte). The default for int, str and float Python types are TAG_Int, TAG_String, and TAG_Float, respectively.

When editing a YAML file, it’s important to keep the formatting exactly the same! nbt2yaml can only handle structures that are in the form in which it generates; see the example below to see all of these forms.

While nbt2yaml can handle any kind of data provided the format is correct, it’s expected that the normal use of this tool is just to change individual values without changing the document structure.

A current dump of the Minecraft reference file bigtest.nbt in YAML format is below. Suggestions on improving this format are welcome !

Level:
- longTest: !long "9223372036854775807"
- shortTest: !short "32767"
- stringTest: !!python/str "HELLO WORLD THIS IS A TEST STRING \xC5\xC4\xD6!"
- floatTest: 0.4982314705848694
- intTest: 2147483647
- nested compound test:
  - ham:
    - name: Hampus
    - value: 0.75
  - egg:
    - name: Eggbert
    - value: 0.5
- listTest (long):
  - !long "11"
  - !long "12"
  - !long "13"
  - !long "14"
  - !long "15"
- listTest (compound):
  - - name: 'Compound tag #0'
    - created-on: !long "1264099775885"
  - - name: 'Compound tag #1'
    - created-on: !long "1264099775885"
- byteTest: !byte "127"
- byteArrayTest (the first 1000 values of (n*n*255+n*7)%100, starting with n=0 (0, 62, 34, 16, 8, ...)): !byte_array "00\
    \ 3E 22 10 08 0A 16 2C 4C 12 46 20 04 56 4E 50 5C 0E 2E 58 28 02 4A 38 30 32 3E\
    \ 54 10 3A 0A 48 2C 1A 12 14 20 36 56 1C 50 2A 0E 60 58 5A 02 18 38 62 32 0C 54\
    \ 42 3A 3C 48 5E 1A 44 14 52 36 24 1C 1E 2A 40 60 26 5A 34 18 06 62 00 0C 22 42\
    \ 08 3C 16 5E 4C 44 46 52 04 24 4E 1E 5C 40 2E 26 28 34 4A 06 30 00 3E 22 10 08\
    \ 0A 16 2C 4C 12 46 20 04 56 4E 50 5C 0E 2E 58 28 02 4A 38 30 32 3E 54 10 3A 0A\
    \ 48 2C 1A 12 14 20 36 56 1C 50 2A 0E 60 58 5A 02 18 38 62 32 0C 54 42 3A 3C 48\
    \ 5E 1A 44 14 52 36 24 1C 1E 2A 40 60 26 5A 34 18 06 62 00 0C 22 42 08 3C 16 5E\
    \ 4C 44 46 52 04 24 4E 1E 5C 40 2E 26 28 34 4A 06 30 00 3E 22 10 08 0A 16 2C 4C\
    \ 12 46 20 04 56 4E 50 5C 0E 2E 58 28 02 4A 38 30 32 3E 54 10 3A 0A 48 2C 1A 12\
    \ 14 20 36 56 1C 50 2A 0E 60 58 5A 02 18 38 62 32 0C 54 42 3A 3C 48 5E 1A 44 14\
    \ 52 36 24 1C 1E 2A 40 60 26 5A 34 18 06 62 00 0C 22 42 08 3C 16 5E 4C 44 46 52\
    \ 04 24 4E 1E 5C 40 2E 26 28 34 4A 06 30 00 3E 22 10 08 0A 16 2C 4C 12 46 20 04\
    \ 56 4E 50 5C 0E 2E 58 28 02 4A 38 30 32 3E 54 10 3A 0A 48 2C 1A 12 14 20 36 56\
    \ 1C 50 2A 0E 60 58 5A 02 18 38 62 32 0C 54 42 3A 3C 48 5E 1A 44 14 52 36 24 1C\
    \ 1E 2A 40 60 26 5A 34 18 06 62 00 0C 22 42 08 3C 16 5E 4C 44 46 52 04 24 4E 1E\
    \ 5C 40 2E 26 28 34 4A 06 30 00 3E 22 10 08 0A 16 2C 4C 12 46 20 04 56 4E 50 5C\
    \ 0E 2E 58 28 02 4A 38 30 32 3E 54 10 3A 0A 48 2C 1A 12 14 20 36 56 1C 50 2A 0E\
    \ 60 58 5A 02 18 38 62 32 0C 54 42 3A 3C 48 5E 1A 44 14 52 36 24 1C 1E 2A 40 60\
    \ 26 5A 34 18 06 62 00 0C 22 42 08 3C 16 5E 4C 44 46 52 04 24 4E 1E 5C 40 2E 26\
    \ 28 34 4A 06 30 00 3E 22 10 08 0A 16 2C 4C 12 46 20 04 56 4E 50 5C 0E 2E 58 28\
    \ 02 4A 38 30 32 3E 54 10 3A 0A 48 2C 1A 12 14 20 36 56 1C 50 2A 0E 60 58 5A 02\
    \ 18 38 62 32 0C 54 42 3A 3C 48 5E 1A 44 14 52 36 24 1C 1E 2A 40 60 26 5A 34 18\
    \ 06 62 00 0C 22 42 08 3C 16 5E 4C 44 46 52 04 24 4E 1E 5C 40 2E 26 28 34 4A 06\
    \ 30 00 3E 22 10 08 0A 16 2C 4C 12 46 20 04 56 4E 50 5C 0E 2E 58 28 02 4A 38 30\
    \ 32 3E 54 10 3A 0A 48 2C 1A 12 14 20 36 56 1C 50 2A 0E 60 58 5A 02 18 38 62 32\
    \ 0C 54 42 3A 3C 48 5E 1A 44 14 52 36 24 1C 1E 2A 40 60 26 5A 34 18 06 62 00 0C\
    \ 22 42 08 3C 16 5E 4C 44 46 52 04 24 4E 1E 5C 40 2E 26 28 34 4A 06 30 00 3E 22\
    \ 10 08 0A 16 2C 4C 12 46 20 04 56 4E 50 5C 0E 2E 58 28 02 4A 38 30 32 3E 54 10\
    \ 3A 0A 48 2C 1A 12 14 20 36 56 1C 50 2A 0E 60 58 5A 02 18 38 62 32 0C 54 42 3A\
    \ 3C 48 5E 1A 44 14 52 36 24 1C 1E 2A 40 60 26 5A 34 18 06 62 00 0C 22 42 08 3C\
    \ 16 5E 4C 44 46 52 04 24 4E 1E 5C 40 2E 26 28 34 4A 06 30 00 3E 22 10 08 0A 16\
    \ 2C 4C 12 46 20 04 56 4E 50 5C 0E 2E 58 28 02 4A 38 30 32 3E 54 10 3A 0A 48 2C\
    \ 1A 12 14 20 36 56 1C 50 2A 0E 60 58 5A 02 18 38 62 32 0C 54 42 3A 3C 48 5E 1A\
    \ 44 14 52 36 24 1C 1E 2A 40 60 26 5A 34 18 06 62 00 0C 22 42 08 3C 16 5E 4C 44\
    \ 46 52 04 24 4E 1E 5C 40 2E 26 28 34 4A 06 30 00 3E 22 10 08 0A 16 2C 4C 12 46\
    \ 20 04 56 4E 50 5C 0E 2E 58 28 02 4A 38 30 32 3E 54 10 3A 0A 48 2C 1A 12 14 20\
    \ 36 56 1C 50 2A 0E 60 58 5A 02 18 38 62 32 0C 54 42 3A 3C 48 5E 1A 44 14 52 36\
    \ 24 1C 1E 2A 40 60 26 5A 34 18 06 62 00 0C 22 42 08 3C 16 5E 4C 44 46 52 04 24\
    \ 4E 1E 5C 40 2E 26 28 34 4A 06 30"
- doubleTest: !double "0.4931287132182315"

Disclaimer

nbtedit is very old now, but the last time I did anything with it, it was brand new. Back when it was September, 2011, you would have been one of the first people reading this README. But I am now writing this in February of 2021, so you are likely the.. one..two…. seventh, yes, likely the seventh, maybe eighth? person to read this, but nonetheless, this is not a widely used tool so you may very well be the person to find some new bugs! It’s also very possible that an incorrectly edited YAML file could save an NBT file that Minecraft no longer knows how to read.

Back EVERYTHING up before tinkering with your files !! nbtedit saves a backup of each file it edits, but don’t rely solely on that! Please note you are using this editor at your own risk. The code is unit tested, works great, but I’d hate to be the reason you screwed up your world so make copies of all files being edited first. Thanks!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nbt2yaml-0.4.2.tar.gz (26.8 kB view details)

Uploaded Source

Built Distribution

nbt2yaml-0.4.2-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file nbt2yaml-0.4.2.tar.gz.

File metadata

  • Download URL: nbt2yaml-0.4.2.tar.gz
  • Upload date:
  • Size: 26.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.9.1 pkginfo/1.7.0 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.7

File hashes

Hashes for nbt2yaml-0.4.2.tar.gz
Algorithm Hash digest
SHA256 6b576a37243f6395eed19bad41e3621cff2077aef84335031d70bac11db89bba
MD5 f80cdf77b7204f59a5361661bf17a356
BLAKE2b-256 2ef7b3a0d09f80fedf42e2359e53a360e4fdd7704ade3cde344148c36cbae284

See more details on using hashes here.

File details

Details for the file nbt2yaml-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: nbt2yaml-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.9.1 pkginfo/1.7.0 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.7

File hashes

Hashes for nbt2yaml-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 63f7b50f1b74f04c8f0579cc1d1a2726ddb43009f1f63fc1b49ff088aa316351
MD5 ffec6a255ef3ed78fd2e108d1c178db6
BLAKE2b-256 3f6bf08be9165f66bfa17dc52417c7a8783269e5dbc80d6df75e347d8a891b01

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page