1.1.0 • Published 4 years ago

prismarine-provider-raw v1.1.0

Weekly downloads
11
License
MIT
Repository
github
Last release
4 years ago

prismarine-provider-raw

NPM version Build Status Discord Gitter Irc Try it on gitpod

Raw (prismarine-chunk based) Storage Provider implementation. Supports all versions that prismarine-chunk supports thereby providing a stop-gap measure until prismarine-provider-anvil is updated.

Usage

const RawStorage = require('prismarine-provider-raw')('1.16.1')
const Chunk = require('prismarine-chunk')('1.16.1')

const storage = new RawStorage('./world/')

const chunk = new Chunk()
storage.save(0, 1, chunk).then(() => {
  console.log('saved!')
  storage.load(0, 1).then(c => {
    console.log('loaded!')
  }).catch(e => {
    console.error(e.stack)
  })
}).catch(e => {
  console.error(e.stack)
})

API

RawStorage

new RawStorage(path, compress = true)

Create a new RawStorage instance which uses the folder at path for storage (Optionally disable zlib compression with compress)

RawStorage.save(x, z, chunk)

Store a prismarine-chunk chunk at pos x, y. Returns a promise.

RawStorage.load(x, z)

Load the prismarine-chunk at pos x, y. Returns a promise.

RawStorage.defrag()

Load and defrag all region files (reduces wasted storage space)

NOTE: there is no need to run this regularly

Format

The format is loosely based on minecraft's Anvil Region format. The world is divided into 32*32 (1024) chunk sections, called 'regions'. The region a chunk belongs to can be found by dividing and then flooring the chunk coordinates by 32 (Bit-shift right by 5):

const regionX = chunkX >> 5
const regionY = chunkY >> 5

File Header

OffsetSize (Bytes)FieldPurpose
0x00x4Magic NumberCHNK (43 48 4e 4b) in ASCII
0x40x1Prismarine VersionPrismarine format version
0x50x2MC World VersionMinecraft protocol version for the chunks (e.g. 1.16.1 => 736)
0x70x4X PositionX Position of the region file
0xB0x4Y PositionY Position of the region file
0xF0x2000Chunk Info x1024Chunk locations and sizes in the file (see Chunk Info below)
0x200F-Chunk DataSparse chunk data, referenced by Chunk Info entries, variable size

Chunk Info

OffsetSize (Bytes)FieldPurpose
0x00x4OffsetChunk data offset, in bytes, after the File Header
0x40x4SizeChunk data size, in bytes

Chunk Data

OffsetSize (Bytes)FieldPurpose
0x00x1CompressionIf the rest of the data is GZip compressed or not
0x10x1FeaturesBitMask (0: Full Chunk (Ground Up), 1: Includes SkyLight, 2-7: Reserved)
0x20x2BitMaskSection Bitmask with bits set to 1 for every 16x16x16 chunk section whose data is included in Data
0x40x4Data LengthLength of the following Block Data
0x8-DataBlock Data
Unk+0x80x3SkyLight MaskOnly the first 18 bits are actually used (missing for versions 1.13 and below)
Unk+0xB0x3BlockLight MaskOnly the first 18 bits are actually used (missing for versions 1.13 and below)
Unk+0xE0x3Empty SkyLight MaskOnly the first 18 bits are actually used (missing for versions 1.13 and below)
Unk+0x110x3Empty BlockLight MaskOnly the first 18 bits are actually used (missing for versions 1.13 and below)
Unk+0x140x4Light Data LengthLength of the following Light Data (missing for versions 1.13 and below)
Unk+0x18-Light DataLight Data (missing for versions 1.13 and below)
Unk2+0x180x1000Biomes1024 Biome IDs (missing for versions 1.14 and below)