Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix direct palettes #232

Merged
merged 13 commits into from
Aug 26, 2023
Binary file added test/1.12/chunk_hypixel.dump
Binary file not shown.
1 change: 1 addition & 0 deletions test/1.12/chunk_hypixel.meta

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/1.12/chunk_hypixel.world
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"minY":0,"worldHeight":256}
Binary file added test/1.16.1/chunk_hypixel.dump
Binary file not shown.
1 change: 1 addition & 0 deletions test/1.16.1/chunk_hypixel.meta

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/1.16.1/chunk_hypixel.world
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"minY":0,"worldHeight":256}
Binary file added test/1.16.1/chunk_light_hypixel.dump
Binary file not shown.
1 change: 1 addition & 0 deletions test/1.16.1/chunk_light_hypixel.meta

Large diffs are not rendered by default.

Binary file added test/1.17/chunk_hypixel.dump
Binary file not shown.
1 change: 1 addition & 0 deletions test/1.17/chunk_hypixel.meta

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/1.17/chunk_hypixel.world
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"minY":0,"worldHeight":256}
1 change: 1 addition & 0 deletions test/1.17/chunk_light_hypixel.meta

Large diffs are not rendered by default.

Binary file added test/1.18/chunk_hypixel.dump
Binary file not shown.
1 change: 1 addition & 0 deletions test/1.18/chunk_hypixel.meta

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/1.18/chunk_hypixel.world
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"minY":0,"worldHeight":256}
Binary file added test/1.19/chunk_hypixel.dump
Binary file not shown.
1 change: 1 addition & 0 deletions test/1.19/chunk_hypixel.meta

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/1.19/chunk_hypixel.world
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"minY":0,"worldHeight":256}
Binary file added test/1.20/chunk_hypixel.dump
Binary file not shown.
1 change: 1 addition & 0 deletions test/1.20/chunk_hypixel.meta

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/1.20/chunk_hypixel.world
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"minY":0,"worldHeight":256}
Binary file added test/1.8/chunk_hypixel.dump
Binary file not shown.
1 change: 1 addition & 0 deletions test/1.8/chunk_hypixel.meta

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/1.8/chunk_hypixel.world
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"minY":0,"worldHeight":256}
84 changes: 50 additions & 34 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ versions.forEach((version) => describe(`Chunk implementation for minecraft ${ver
const files = fs.readdirSync(folder)
const chunkFiles = files.filter(file => file.includes('.dump') && !file.includes('light'))
const dataFiles = files.filter(file => file.includes('.meta') && !file.includes('light'))
const worldFiles = files.filter(file => file.includes('.world'))

chunkFiles.forEach(chunkDump => {
const name = chunkDump.substring(0, chunkDump.length - 5)
Expand All @@ -237,6 +238,19 @@ versions.forEach((version) => describe(`Chunk implementation for minecraft ${ver
const data = JSON.parse(
fs.readFileSync(path.join(folder, packetData)).toString()
)
const worldFile = worldFiles.find(worldFile => worldFile.includes(name))
const chunkOptions = {
minY: tallWorld ? -64 : 0,
worldHeight: tallWorld ? 384 : 256
}
if (worldFile) {
const worldData = JSON.parse(
fs.readFileSync(path.join(folder, worldFile)).toString()
)
chunkOptions.minY = worldData.minY
chunkOptions.worldHeight = worldData.worldHeight
}

data.skylightSent = !packetData.includes('nether') && !packetData.includes('end')

let lightData, lightDump
Expand All @@ -262,43 +276,45 @@ versions.forEach((version) => describe(`Chunk implementation for minecraft ${ver
}
})

it('Loads chunk buffers and histogram looks ok ' + chunkDump, () => {
const chunk = new Chunk(chunkOptions)
chunk.load(dump, data.bitMap, data.skyLightSent)
if (serializesLightingDataSeparately) {
if (newLightingDataFormat) {
chunk.loadParsedLight(lightData.skyLight, lightData.blockLight, lightData.skyLightMask, lightData.blockLightMask, lightData.emptySkyLightMask, lightData.emptyBlockLightMask)
} else {
chunk.loadLight(lightDump, lightData.skyLightMask, lightData.blockLightMask, lightData.emptySkyLightMask, lightData.emptyBlockLightMask)
if(!chunkDump.includes('hypixel')) {
it('Loads chunk buffers and histogram looks ok ' + chunkDump, () => {
const chunk = new Chunk(chunkOptions)
chunk.load(dump, data.bitMap, data.skyLightSent)
if (serializesLightingDataSeparately) {
if (newLightingDataFormat) {
chunk.loadParsedLight(lightData.skyLight, lightData.blockLight, lightData.skyLightMask, lightData.blockLightMask, lightData.emptySkyLightMask, lightData.emptyBlockLightMask)
} else {
chunk.loadLight(lightDump, lightData.skyLightMask, lightData.blockLightMask, lightData.emptySkyLightMask, lightData.emptyBlockLightMask)
}
}
}

const histogram = {}
const p = new Vec3(0, chunkOptions.minY, 0)
const maxHeight = chunkOptions.worldHeight + chunkOptions.minY
let total = 0
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)
histogram[b.name] = histogram[b.name] === undefined ? 1 : histogram[b.name] + 1
total += 1
const histogram = {}
const p = new Vec3(0, chunkOptions.minY, 0)
const maxHeight = chunkOptions.worldHeight + chunkOptions.minY
let total = 0
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)
histogram[b.name] = histogram[b.name] === undefined ? 1 : histogram[b.name] + 1
total += 1
}
}
}
}
Object.keys(histogram).forEach(k => { histogram[k] = histogram[k] / total })
// console.log(histogram)
const checkBlockKind = (name, value) => assert(histogram[name] > value, `${name} ${histogram[name]} <= ${value}`)
const checkBlockKindSome = (thresholds) => assert(
Object.keys(thresholds).some(name => histogram[name] > thresholds[name]),
Object.keys(thresholds).map(name => `${name} ${histogram[name]} <= ${thresholds[name]}`).join(' && '))
if (!chunkDump.includes('end') && !chunkDump.includes('nether')) {
checkBlockKind('stone', 0.01)
checkBlockKindSome({ dirt: 0.001, granite: 0.001, lava: 0.001 })
checkBlockKindSome({ coal_ore: 0.0001, iron_ore: 0.0001, diamond_ore: 0.0001 })
}
checkBlockKind('air', 0.5)
})
Object.keys(histogram).forEach(k => { histogram[k] = histogram[k] / total })
// console.log(histogram)
const checkBlockKind = (name, value) => assert(histogram[name] > value, `${name} ${histogram[name]} <= ${value}`)
const checkBlockKindSome = (thresholds) => assert(
Object.keys(thresholds).some(name => histogram[name] > thresholds[name]),
Object.keys(thresholds).map(name => `${name} ${histogram[name]} <= ${thresholds[name]}`).join(' && '))
if (!chunkDump.includes('end') && !chunkDump.includes('nether')) {
checkBlockKind('stone', 0.01)
checkBlockKindSome({ dirt: 0.001, granite: 0.001, lava: 0.001 })
checkBlockKindSome({ coal_ore: 0.0001, iron_ore: 0.0001, diamond_ore: 0.0001 })
}
checkBlockKind('air', 0.5)
})
}

it('Correctly cycles through chunks ' + chunkDump, () => {
const chunk = new Chunk(chunkOptions)
Expand Down Expand Up @@ -376,7 +392,7 @@ versions.forEach((version) => describe(`Chunk implementation for minecraft ${ver
}
}

if (!version.startsWith('1.8')) {
if (!version.startsWith('1.8') && !chunkDump.includes('hypixel')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which are hypixel chunks not the same after dumping?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because hypixel provides excess data which is dropped by pchunk (per this PR). See my comment here #232 (comment)

Since the test already iterates over all blocks and palettes in the chunk, it means the two chunks are still functionally the same if the test passes

assert(Buffer.compare(dump.slice(0, dump.length - num), buffer) === 0, 'chunk buffers are not equal')
}
})
Expand Down
Loading