diff --git a/.gitignore b/.gitignore index 441967e..4462372 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,4 @@ dist/ distTest/ world/testRegion/* package-lock.json -test/fixtures/* test/world/ \ No newline at end of file diff --git a/README.md b/README.md index f7d0777..e351015 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![NPM version](https://img.shields.io/npm/v/prismarine-provider-anvil.svg)](http://npmjs.com/package/prismarine-provider-anvil) [![Build Status](https://github.com/PrismarineJS/prismarine-provider-anvil/workflows/CI/badge.svg)](https://github.com/PrismarineJS/prismarine-provider-anvil/actions?query=workflow%3A%22CI%22) -Anvil Storage Provider implementation. Support minecraft pc 1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17 and 1.18 +Anvil Storage Provider implementation. Support minecraft pc 1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17, 1.18, 1.19, 1.20 and 1.21 ## Usage diff --git a/src/1.18/chunk.js b/src/1.18/chunk.js index fa1a6ac..e6b11e5 100644 --- a/src/1.18/chunk.js +++ b/src/1.18/chunk.js @@ -34,8 +34,6 @@ module.exports = (ChunkColumn, registry) => { if (!bitsPerBlock) { blockStates = nbt.comp({ palette: nbt.list(nbt.comp(blockPalette)) }) } else { - assert.strictEqual(bitsPerBlock, section.data.data.bitsPerValue, `Computed bits per block for palette size of ${blockPalette.length} (${bitsPerBlock}) does not match bits per block in section, ${section.data.data.bitsPerValue}`) - const data = section.data.data.toLongArray() blockStates = nbt.comp({ palette: nbt.list(nbt.comp(blockPalette)), data: nbt.longArray(data) }) } @@ -112,8 +110,6 @@ module.exports = (ChunkColumn, registry) => { function fromNBT (tag) { const data = nbt.simplify(tag) const column = new ChunkColumn({ minY: -64, worldHeight: 384 }) - assert(data.Status === 'full', 'Chunk is not full') - column.x = data.xPos column.z = data.zPos column.lastUpdate = data.LastUpdate.valueOf() diff --git a/src/chunk.js b/src/chunk.js index 5c07785..56bbe7a 100644 --- a/src/chunk.js +++ b/src/chunk.js @@ -15,7 +15,10 @@ module.exports = (registryOrVersion) => { 1.15: () => require('./1.14/chunk')('1.15', 2230), 1.16: () => require('./1.14/chunk')('1.16', 2567, true), 1.17: () => require('./1.14/chunk')('1.17', 2730, true), - 1.18: () => require('./1.18/chunk') + 1.18: () => require('./1.18/chunk'), + 1.19: () => require('./1.18/chunk'), + '1.20': () => require('./1.18/chunk'), + 1.21: () => require('./1.18/chunk') } const loadVersion = registry.version.majorVersion diff --git a/src/version.js b/src/version.js index e37a465..eaaad26 100644 --- a/src/version.js +++ b/src/version.js @@ -1,4 +1,4 @@ -const testedVersions = ['1.8.9', '1.9', '1.11.2', '1.12.2', '1.13.2', '1.14.4', '1.16', '1.17.1'] +const testedVersions = ['1.8.9', '1.9', '1.11.2', '1.12.2', '1.13.2', '1.14.4', '1.16', '1.17.1', '1.18.2', '1.19.4', '1.20.6', '1.21.1'] module.exports = { testedVersions, latestSupportedVersion: testedVersions[testedVersions.length - 1], diff --git a/test/chunkToNbt.js b/test/chunkToNbt.js index b9c1828..cc0c724 100644 --- a/test/chunkToNbt.js +++ b/test/chunkToNbt.js @@ -4,12 +4,17 @@ const { Vec3 } = require('vec3') const assert = require('assert') const nbt = require('prismarine-nbt') const prismarineProviderAnvil = require('prismarine-provider-anvil') +const compareChunks = require('./common').compareChunks const testedVersions = prismarineProviderAnvil.testedVersions for (const version of testedVersions) { const registry = require('prismarine-registry')(version) const Chunk = require('prismarine-chunk')(registry) + const chunkOptions = { + minY: registry.supportFeature('tallWorld') ? -64 : 0, + worldHeight: registry.supportFeature('tallWorld') ? 384 : 256 + } const chunk = new Chunk() for (let x = 0; x < 16; x++) { @@ -66,7 +71,7 @@ for (const version of testedVersions) { const reChunk = nbtChunkToPrismarineChunk(tag) assert.strictEqual(reChunk.getBlockType(new Vec3(0, 50, 0)), 2, 'wrong block type at 0,50,0') assert.strictEqual(reChunk.getSkyLight(new Vec3(0, 50, 0)), 15) - assert(reChunk.dump().equals(chunk.dump())) + compareChunks(chunk, reChunk, chunkOptions) }) }) } diff --git a/test/common.js b/test/common.js new file mode 100644 index 0000000..16b51ca --- /dev/null +++ b/test/common.js @@ -0,0 +1,29 @@ +const assert = require('assert') +const { Vec3 } = require('vec3') + +function compareChunks (chunk, chunk2, chunkOptions) { + const p = new Vec3(0, chunkOptions.minY, 0) + const maxHeight = chunkOptions.worldHeight + chunkOptions.minY + for (p.y = chunkOptions.minY; p.y < maxHeight; p.y++) { + for (p.z = 0; p.z < 16; p.z++) { + for (p.x = 0; p.x < 16; p.x++) { + const b = chunk.getBlock(p) + const b2 = chunk2.getBlock(p) + assert.notStrictEqual( + b.name, + '', + ' block state: ' + + b.stateId + + ' type: ' + + b.type + + " read, which doesn't exist" + ) + assert.strictEqual(JSON.stringify(b), JSON.stringify(b2), 'blocks at ' + p + + ' differ, first block is ' + JSON.stringify(b, null, 2) + + ' second block is ' + JSON.stringify(b2, null, 2)) + } + } + } +} + +module.exports.compareChunks = compareChunks diff --git a/test/fixtures/1.18.2/r.0.0.mca b/test/fixtures/1.18.2/r.0.0.mca new file mode 100644 index 0000000..582dd52 Binary files /dev/null and b/test/fixtures/1.18.2/r.0.0.mca differ diff --git a/test/fixtures/1.19.4/r.0.0.mca b/test/fixtures/1.19.4/r.0.0.mca new file mode 100644 index 0000000..3645f1f Binary files /dev/null and b/test/fixtures/1.19.4/r.0.0.mca differ diff --git a/test/fixtures/1.20.6/r.0.0.mca b/test/fixtures/1.20.6/r.0.0.mca new file mode 100644 index 0000000..3683ea5 Binary files /dev/null and b/test/fixtures/1.20.6/r.0.0.mca differ diff --git a/test/fixtures/1.21.1/r.0.0.mca b/test/fixtures/1.21.1/r.0.0.mca new file mode 100644 index 0000000..bb1d59d Binary files /dev/null and b/test/fixtures/1.21.1/r.0.0.mca differ diff --git a/test/savingLoading.js b/test/savingLoading.js index 7b5ac3b..95c0a3b 100644 --- a/test/savingLoading.js +++ b/test/savingLoading.js @@ -7,6 +7,7 @@ const range = require('range').range const { Vec3 } = require('vec3') const assert = require('assert') const prismarineProviderAnvil = require('prismarine-provider-anvil') +const compareChunks = require('./common').compareChunks const testedVersions = prismarineProviderAnvil.testedVersions @@ -49,48 +50,6 @@ for (const version of testedVersions) { chunks = generateCube(size).map(({ chunkX, chunkZ }) => ({ chunkX, chunkZ, chunk: generateRandomChunk(chunkX, chunkZ) })) }) - function compareChunks (chunk, chunk2) { - function eqSet (as, bs) { - if (as.size !== bs.size) return false - for (const a of as) if (!bs.has(a)) return false - return true - } - - if (chunk.sections) { - assert.strictEqual(chunk.sections.length, chunk2.sections.length) - for (let i = 0; i < chunk.sections.length; i++) { - if (chunk.sections[i] !== null && chunk2.sections[i].palette !== undefined) { - const s1 = new Set(chunk.sections[i].palette) - const s2 = new Set(chunk2.sections[i].palette) - assert(eqSet(s1, s2), `palettes are not equal ${[...s1]} != ${[...s2]}`) - } - } - } - - const p = new Vec3(0, chunkOptions.minY, 0) - const maxHeight = chunkOptions.worldHeight + chunkOptions.minY - for (p.y = chunkOptions.minY; p.y < maxHeight; p.y++) { - for (p.z = 0; p.z < 16; p.z++) { - for (p.x = 0; p.x < 16; p.x++) { - const b = chunk.getBlock(p) - const b2 = chunk2.getBlock(p) - assert.notStrictEqual( - b.name, - '', - ' block state: ' + - b.stateId + - ' type: ' + - b.type + - " read, which doesn't exist" - ) - assert.strictEqual(JSON.stringify(b), JSON.stringify(b2), 'blocks at ' + p + - ' differ, first block is ' + JSON.stringify(b, null, 2) + - ' second block is ' + JSON.stringify(b2, null, 2)) - } - } - } - } - async function loadInParallel () { const anvil = new Anvil(regionPath) await Promise.all( @@ -102,7 +61,7 @@ for (const version of testedVersions) { const blockB = loadedChunk.getBlock(new Vec3(0, 50, 0)) assert.strictEqual( blockA.stateId, blockB.stateId, 'wrong block type at 0,50,0 at chunk ' + chunkX + ', ' + chunkZ) - compareChunks(originalChunk, loadedChunk) + compareChunks(originalChunk, loadedChunk, chunkOptions) }) ) await anvil.close()