Skip to content

Instantly share code, notes, and snippets.

@maow-tty
Last active January 12, 2024 04:44
Show Gist options
  • Save maow-tty/28d0362d9459a49af714a6078ba44ee9 to your computer and use it in GitHub Desktop.
Save maow-tty/28d0362d9459a49af714a6078ba44ee9 to your computer and use it in GitHub Desktop.
Named Binary Tags 2

Block

The layout of a block NBT file (.nbt2)

struct Block {
  signature: u32
  root_tag: ...
}
  • signature should equal 0x4E425449
  • root_tag is either compound tag or array tag
  • Little-Endian

Inline

The layout of an inline NBT sequence.

struct Inline {
  length: var32
  tags: ...
}
  • length is the length of tags
  • tags is an array of any tag
  • Big-Endian

Wireframe

The layout of a NBT2 wireframe file.

struct Wireframe {
  length: var32
  names: String[]
  transformation: u8[] 
}
  • length is the length of names
  • transformation represents a set of wireframe bytecode instructions

String

The layout of a string.

struct String {
  length: var32
  characters: u8[]
}
  • length is the length of characters1
  • characters is an array of modified UTF-8 characters

Tag

The layout of a tag.

struct Tag {
  type: u8
  name_index: var32
  value: ...
}
  • type follows the bit flags specified under Type
  • name_index is an index into the name table
  • value is dependent on the bits set in type

Type

const FALSE = 0b0000_0000     ; no value
const TRUE  = 0b0000_0001     ; no value

const BYTE     = 0b0000_0010  ; signed 8-bit integer
const SHORT    = 0b0000_0011  ; signed 16-bit integer
const INT      = 0b0000_0100  ; signed 32-bit integer
const LONG     = 0b0000_0101  ; signed 64-bit integer
const FLOAT    = 0b0000_0110  ; single-precision floating point integer
const DOUBLE   = 0b0000_0111  ; double-precision floating point integer
const STRING   = 0b0000_1000  ; String
const COMPOUND = 0b0000_1001  ; length-prefixed sequence of NBT2 tags (prefix: var32)
const VARINT   = 0b0000_1010  ; variable-length 32-bit integer
const VARLONG  = 0b0000_1011  ; variable-length 64-bit integer

const ARRAY = 0b0001_0000

const UNSIGNED = 0b0010_0000

const RESERVED = 0b0100_0000
const RESERVED = 0b1000_0000

Footnotes

  1. All variable-length integers are encoded as "imperial varints," proposed as part of A better varint by Douglas Creager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment