Skip to main content

NbtChunk

Creating an NbtChunk

Most like you will be getting chunks through an NbtRegion, but you can also create them separately.

const file = NbtFile.create()
const chunk = NbtChunk.create(3, 4, file)

Properties

NameType
xnumber
znumber
compressionnumber
timestampnumber

Methods

getCompression()

Returns the string representation of the compression. Throws if the chunk has an invalid compression mode.

NumberString
1gzip
2zlib
3none

setCompression(compression)

Sets this chunk's compression number corresponding to the the passed string. See the table above for the conversion. Throws if compression is an invalid compression mode.

getFile()

Returns the NbtFile. If this is the first time, it reads it from the raw data.

getRoot()

Returns the root NbtCompound from the file. Equivalent to chunk.getFile().root.

setRoot(root)

Sets the file's root and marks this chunk as dirty.

markDirty()

Marks this chunk as dirty. You need to call this whenever you make changes to the chunk's root.

getRaw()

Returns the raw Uint8Array data of the chunk. If the chunk is dirt, the file will be written first, and then the file will be marked as not dirty.

toJson()

Serializes the chunk to a format which can be represented by JSON. This can be necessary when using workers.

const json = chunk.toJson()
// send the data to a different worker
const chunk2 = NbtChunk.fromJson(json, chunkResolver)
info

For performance reasons, the serialized data does not contain the raw chunk data. The chunk obtained from NbtChunk.fromJson returns an NbtChunk.Ref. chunkResolver is necessary to asynchronously request the data of a chunk.

NbtChunk.Ref

Properties

NameType
xnumber
znumber
compressionnumber
timestampnumber
sizenumber
resolver(x: number, z: number) => Promise<NbtFile>

Methods

getFile()

Returns the NbtFile or undefined if the chunk hasn't been resolved yet.

getRoot()

Returns the root NbtCompound of the file or undefined if the chunk hasn't been resolved yet.

getFileAsync()

Returns a promise to the NbtFile.

getRootAsync()

Returns a promise to the root NbtCompound of the file.

isResolved()

Returns a boolean indicating whether the ref is resolved yet.