NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

Building an Command Line Tool to View Minecraft Data

This week's blog post is about building an application that can be run from command line to display Minecraft NBT files. You will learn:



Named Binary Tag (NBT), files store information about Minecraft using a simple binary format. These documents provide more information about the NBT format.
Just Another Blog


"NBT format" via Minecraft Wiki. "NBT" via Minecraft.vg. "Named Binary Tag specification” via Minecraft.net (WebArchive).



Script source code



view-nbt



Using the script to display an NBT file



I have a NBT file called level.dat. It contains details about the Minecraft level I play on.



I use view-nbt to display the data in a readable format:



(level.dat files can be compressed, so I use --gzip.



How the script functions



NBT files can contain tags of a variety of types. I used an Enum.Enum, Tag to represent them.



To aid in the parsing process, I created several auxiliary data structures:



Scalar_fmt is a method to map certain Tag objects to form strings that can be used by the struct module. This is applicable to simple tags such as Tag.Int and Tag.Byte. array_fmt is an array that maps some Tag objects into format strings that can be used by the struct module (but missing a length prefix). This is for simple array tags, such as Tag.Int_Array. The dictionary byte tag maps bytes to the appropriate tags. This information was derived from the NBT file format specification.



The struct module is utilized by the parser to decompress binary data into various numbers (like short double, short, and int).



The parser is recursive.



It directly parses Tag.String along with tags in array_fmt and scalar_fmt. It parses Tag.List, Tag.Compound recursively.



The parsing creates a Node object, which is a collections.namedtuple that holds:



The tag's type. - The tag name (optional). - The tag value.



To improve the readability of the data I have a function called the json_friendly function, which transforms Node objects into data structures that, in my opinion, make the JSON easier to read.



I employ Python's gzip module to support compressed NBT files.



To convert JSON-friendly data into a string I use JSON function from Python.



Let's end...



This week's blog post will teach you how to develop a command-line tool that can view Minecraft NBT files. You learned:



How to unpack binary data using the struct module. How to build a recursive Parser for NBT file format. How can you convert the parsed data into JSON-friendly file format



My challenge to you:



Create an application called view-region that converts Region files into JSON that is readable.



If you enjoyed this week's post, share it with your friends and be sure to check back for next week's post. We'll see you next week!


Here's my website: https://twitsoc.com/
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.