misode / vscode-nbt

NBT extension for VSCode
https://marketplace.visualstudio.com/items?itemName=Misodee.vscode-nbt
MIT License
167 stars 12 forks source link

Block states decoding failing for arrays longer than 256 longs #49

Closed novitae closed 1 year ago

novitae commented 1 year ago

I am experiencing this issue where, when the bit length of the palette is longer than 4, and so the length of the block states array is higher than 256, the section of the anvil file completely bugs out and generated weird stuff. Here is are examples:

$ Bit length of palette's length == 4 Bit length of palette's length > 4
In game
In renderer
In section's data

I think it might come from the line: https://github.com/misode/vscode-nbt/blob/b868e5725171563d6b4ddd5f083dcb6ae0d58130/src/editor/ChunkEditor.ts#L57 Since it is the only real difference I see from a cython decoder I made that works well:

cdef int bits = max((len(palette) - 1).bit_length(), 4)
novitae commented 1 year ago

Big update: it comes from block stretching. You can learn more about this mechanic in the 20w17a snapshot post of mojang, at "BLOCK STORAGE". Your code doesn't implement stretching.

stretched not stretched

Here you have a python code that reads, and checks for the version to know if it will use stretching or not during decoding. It should only take you very few lines and would fix the issue.

https://github.com/0xTiger/anvil-parser/blob/670ba6989e9b5eb76e189c0105fc686c6e6371bb/anvil/chunk.py#L441-L482