@createlumina/nbt
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Nbt Module

Version made for Lumina projects. Original credits goes to Voxelum/minecraft-launcher-core-node

npm version Downloads Install size npm Build Status

Provide function to read NBT binary format to json.

Usage

Read and Write NBT

You can simply deserialize/serialize nbt.

import { serialize, deserialize } from '@createlumina/nbt';
const fileData: Buffer;
// compressed = undefined will not perform compress algorithm
// compressed = true will use gzip algorithm
const compressed: true | 'gzip' | 'deflate' | undefined;
const readed: any = await deserialize(fileData, { compressed });
// The deserialize return object contain NBTPrototype property which define its nbt type
// After you do the modification on it, you can serialize it back to NBT
const buf: Buffer = await serialize(readed, { compressed });

You can use class with annotation (decorator) to serialize/deserialize the type consistently.

Suppose you are reading the servers.dat. You can have:

import { serialize, deserialize, TagType } from '@createlumina/nbt';

class ServerInfo {
    @TagType(TagType.String)
    icon: string = '';
    @TagType(TagType.String)
    ip: string = '';
    @TagType(TagType.String)
    name: string = '';
    @TagType(TagType.Byte)
    acceptTextures: number = 0;
}

class Servers {
    @TagType([ServerInfo])
    servers: ServerInfo[] = [];
}

// read
// explict tell the function to deserialize into the type Servers
const servers = await deserialize(data, { type: Servers });
const infos: ServerInfo[] = servers.servers;

// write
const servers: Servers;
const binary = await serialize(servers);

Package Sidebar

Install

npm i @createlumina/nbt

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

480 kB

Total Files

18

Last publish

Collaborators

  • padowyt2