A class to hold chunk data for Minecraft: PC 1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15 and 1.16 and Bedrock Edition 0.14 and 1.0, 1.16, 1.17, 1.18, 1.19 and 1.20
const registry = require('prismarine-registry')('1.8')
const ChunkColumn = require('prismarine-chunk')(registry)
const { Vec3 } = require("vec3")
const chunk = new ChunkColumn()
for (let x = 0; x < 16;x++) {
for (let z = 0; z < 16; z++) {
chunk.setBlockType(new Vec3(x, 50, z), 2)
for (let y = 0; y < 256; y++) {
chunk.setSkyLight(new Vec3(x, y, z), 15)
}
}
}
console.log(JSON.stringify(chunk.getBlock(new Vec3(3,50,3)),null,2))Test data can be generated with minecraftChunkDumper.
Install it globally with npm install minecraft-chunk-dumper -g then run :
minecraftChunkDumper saveChunks 1.20 "1_20" 10
Run tests in bedrock-provider (which loads chunks through a client as part of its tests) and copy the generated data from fixtures/$version/pchunk into tests/bedrock_$version.
For the version, copy one chunk column of level_chunk without caching, level_chunk with caching, level_chunk CacheMissResponse, subchunk without caching, subchunk cached and subchunk CacheMissResponse into the test/version folder.
Note: bedrock-provider tests network decoding and loading chunks from a save database. The tests in prismarine-chunk test other parts of the chunk API, such as setting and getting block light, type, biome, entity and block entity data.
Build a new chunk. initData is only for 1.18+, and if not given or null the world will default to an old-style 0-256 world.
Initialize a chunk.
iniFuncis a function(x,y,z) returning a prismarine-block.
That function is faster than iterating and calling the setBlock* manually. It is useful to generate a whole chunk and load a whole chunk.
returns the version the chunk loader was called with
returns ChunkSection class for version
.entity will have entity NBT data for this block, if it exists
Set .entity property with NBT data for this block to load block entity data for the block
Get the block type at pos
Get the block state id at pos
Get the block data (metadata) at pos
Get the block light at pos
Get the block sky light at pos
Get the block biome id at pos
Get the block biome color at pos. Does nothing for PC.
Set the block type stateId at pos
Set the block type id at pos
Set the block data (metadata) at pos
Set the block light at pos
Set the block sky light at pos
Set the block biome id at pos
Set the block biomeColor at pos. Does nothing for PC.
Returns the block entity data at position if it exists
Sets block entity data at position
Loads an array of NBT data into the chunk column
Returns the chunk as json
Load chunk from json
Available for pc chunk implementation. Array of y => section Can be used to identify whether a section is empty or not (will be null if it's the case) For version >= 1.9, contains a .palette property which contains all the stateId of this section, can be used to check quickly whether a given block is in this section.
Return the chunk bitmap 0b0000_0000_0000_0000(0x0000) means no chunks are set while 0b1111_1111_1111_1111(0xFFFF) means all chunks are set
Returns the chunk raw data
Load raw data into the chunk
Returns the chunk raw light data (starting from 1.14)
Load lights into the chunk (starting from 1.14)
Chunk.loadParsedLight (skyLight, blockLight, skyLightMask, blockLightMask, emptySkyLightMask, emptyBlockLightMask)
Load lights into the chunk (starting from 1.17)
Returns the biomes as an array (starting from 1.15)
Load biomes into the chunk (starting from 1.15)
See index.d.ts
See index.d.ts
Shrinks the size of the SubChunk if possible after setBlock operations are done
Returns a list of unique block states that make up the chunk section