Skip to content

Commit

Permalink
Support 1.18.2, 1.19.4, 1.20.6, 1.21.1 (#81)
Browse files Browse the repository at this point in the history
* Support 1.18.2

* Support 1.19, 1.20, 1.21

* remove commented code

* add back full check

* remove full check
  • Loading branch information
rom1504 authored Oct 29, 2024
1 parent 6b0517e commit 19bb778
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 52 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ dist/
distTest/
world/testRegion/*
package-lock.json
test/fixtures/*
test/world/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 0 additions & 4 deletions src/1.18/chunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) })
}
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion src/chunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/version.js
Original file line number Diff line number Diff line change
@@ -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],
Expand Down
7 changes: 6 additions & 1 deletion test/chunkToNbt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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)
})
})
}
29 changes: 29 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
@@ -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
Binary file added test/fixtures/1.18.2/r.0.0.mca
Binary file not shown.
Binary file added test/fixtures/1.19.4/r.0.0.mca
Binary file not shown.
Binary file added test/fixtures/1.20.6/r.0.0.mca
Binary file not shown.
Binary file added test/fixtures/1.21.1/r.0.0.mca
Binary file not shown.
45 changes: 2 additions & 43 deletions test/savingLoading.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand 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()
Expand Down

0 comments on commit 19bb778

Please sign in to comment.