Voxelum / minecraft-launcher-core-node

Provide packages to install Minecraft, launch Minecraft and more to build launcher with NodeJs/Electron!
https://docs.xmcl.app/en/core/
MIT License
174 stars 25 forks source link

@xmcl/world chunk section corruption #247

Closed John-Dean closed 1 year ago

John-Dean commented 1 year ago

Hello,

When loading certain chunks there is corruption present on the output data: image

If you expand it out to a larger scale you can see quite a few chunks are corrupted: image

This is taken from a world on Minecraft 1.18.1 and in game this corruption is not present: image

Tested also on 1.17.1: image

And 1.16.5: image

I've created a code example here: https://github.com/John-Dean/MCGame/tree/e218a1fe5cd5cd3867db810f3b9b4b888ed8e948 that just needs to be hosted as a webserver and index.html opened. Corruption is happening at this stage: https://github.com/John-Dean/MCGame/blob/e218a1fe5cd5cd3867db810f3b9b4b888ed8e948/modules/chunk-data/main.js#L75 and I've added some console logs to show the outputs.

Impacted 1.18.1 .mca file: https://github.com/John-Dean/MCGame/blob/master/assets/Sample%20World/region/r.-1.-1.mca (Chunk X: -1, Z: -1) Impacted 1.17.1 .mca file: https://github.com/John-Dean/MCGame/blob/master/assets/Sample%20World%202/region/r.0.0.mca (Chunk X: 0, Z: 0)

If I had to speculate, valid chunks are showing as a 256 element Array of Longs, whereas invalid chunks are showing as >256 (342 in my testing). Forcibly cutting the array at 256 elements does not solve the issue

John-Dean commented 1 year ago

Have done some digging into this, it appears to happen frequently when the palette for a section gets too large.

John-Dean commented 1 year ago

After testing it happens when the palette length >16

John-Dean commented 1 year ago

I did some googling, found this forum post here: https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-tools/3020703-changes-to-the-chunk-format

Which lead me to here: https://github.com/spoutn1k/mcmap

Which lead me to: https://github.com/spoutn1k/mcmap/blob/fec14647c600244bc7808b242b99331e7ee0ec38/src/chunk_format_versions/section_format.cpp#L6

I'm unsure how to modify the existing JS code in this repo here: https://github.com/Voxelum/minecraft-launcher-core-node/blob/master/packages/world/index.ts to correct for this

John-Dean commented 1 year ago

Nevermind, I didn't realise a bunch of helper functions were already implemented. PR to fix this here: https://github.com/Voxelum/minecraft-launcher-core-node/pull/250