twoolie / NBT

Python Parser/Writer for the NBT file format, and it's container the RegionFile.
MIT License
361 stars 74 forks source link

Add 1.16+ support to chunk.py #152

Closed underscoren closed 2 years ago

underscoren commented 3 years ago

Since 1.16 (DataVersion 2566) block indexes are now packed with padding when the number of elements doesn't fit in exactly 64 bits (thank god someone at mojang finally realised the slight storage inefficiency was not worth the performance drop). I added support for reading this updated format, meaning all versions between 1.12.2 to 1.17.1 (and probably 1.18 when it comes out) should work.

In order to do so, I renamed the _init_index method in AnvilSection to _init_index_unpadded and made a new method _init_index_padded for reading the new format.

Total list of changes are as follows:

I only tested 1.15.2, 1.16, and 1.17.1 (and modded 1.16.5). From what I can find on various wikis there doesn't seem to be breaking changes between 1.12.2 and 1.15.2 in the format, but it would be a good idea to explicitly test all versions.

donno commented 2 years ago

Thanks for this, without it I would have drop back to using an early version of Minecraft.

I had however missed the automatic removal of the minecraft: namespace from block names, that was a bit of a gotcha. I hadn't expected it in a PR that was adding support for a new version.

underscoren commented 2 years ago

Yeah sorry about that, but it was just really bugging me lol. it just doesn't make sense in the context of a library that reads chunk data. Imo, you should hand off the handling of namespaces and the choice of whether or not to keep them to the application that is using the library rather than deciding to remove them before the user even sees them.

If this is somehow important functionality that I'm messing up, it can always be reverted though.

donno commented 2 years ago

Yeah, I think it is best if the package doesn't remove it. So I don't really mind that it doesn't remove it as you said I can always do that myself.

After all it is intended to be a generic package rather than specifically a Minecraft world reader/writer.

If something did have names that didn't have any namespace, so more like a global namespace then stripping minecraft: would make them look he same as being in the global namespace.

macfreek commented 2 years ago

@twoolie I'm currently not actively using the NBT library, and don't use the Minecraft-specific parts in chunk.py. Given the conversation, I propose to merge the pull request as is. Unless you have another plan, I'll do so in a few days.