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
Name | Type |
---|---|
x | number |
z | number |
compression | number |
timestamp | number |
Methods
getCompression()
Returns the string representation of the compression. Throws if the chunk has an invalid compression mode.
Number | String |
---|---|
1 | gzip |
2 | zlib |
3 | none |
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)
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
Name | Type |
---|---|
x | number |
z | number |
compression | number |
timestamp | number |
size | number |
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.