bedrock-provider
Minecraft Bedrock level provider for saves and network serialization
Install
npm i bedrock-provider
Usage
Writing example:
const fs = require('fs')
const { LevelDB } = require('leveldb-zlib')
const { WorldProvider } = require('bedrock-provider')
const ChunkColumn = require('bedrock-provider').chunk('bedrock_1.17.10')
const Block = require('prismarine-block')('bedrock_1.17.10')
async function main() {
let cc = new ChunkColumn(0, 0)
for (var x = 0; x < 4; x++) {
for (var y = 0; y < 4; y++) {
for (var z = 0; z < 4; z++) {
const id = Math.floor(Math.random() * 1000)
let block = Block.fromStateId(id)
cc.setBlock({ x, y, z }, block)
}
}
}
const db = new LevelDB('./__sample', { createIfMissing: true })
await db.open()
const world = new WorldProvider(db, { dimension: 0 })
world.save(cc)
await db.close()
}
See tests/ for more usage examples.
API
WorldProvider
constructor(db: LevelDB, options?: { dimension: number; version: string; });
The exported WorldProvider
class allows you to load a save file from a LevelDB database. The
first parameter is the db (leveldb-zlib instance), and the
second is an options object. The options argument takes a dimension ID (overworld or nether or end are 1, 2 and 3).
The options argument also takes a version, which if not specified will default to the latest version. When you
access APIs like getBlock or setBlock, this is the version which will be assumed.
load(x: number, z: number, full: boolean): Promise;
This returns a ChunkColumn at the specified x
and z
coordinates. full
if we should load biomes,
entities, tiles, and other related data ontop of chunks.
save(column: ChunkColumn): Promise;
Saves a ChunkColumn into the database.
ChunkColumn
constructor(version: Version, x: any, z: any);
getBlock(vec4: { l, x, y, z }): Block;
setBlock(vec4: { l, x, y, z }, block: Block): void;
addSection(section: SubChunk): void;
networkEncodeNoCache(): Promise<Buffer>;
networkEncodeBlobs(blobStore: BlobStore): Promise<CCHash[]>;
networkEncode(blobStore: BlobStore): Promise<{
blobs: CCHash[];
payload: Buffer;
}>;
networkDecodeNoCache(buffer: Buffer, sectionCount: number): Promise<void>;
networkDecode(blobs: CCHash[], blobStore: BlobStore, payload: any): Promise<CCHash[]>;