owengage / fastnbt

Fast serde serializer and deserializer for Minecraft's NBT and Anvil formats
MIT License
185 stars 35 forks source link

How to manualy deserialize .mca files? #100

Closed jotalanusse closed 7 months ago

jotalanusse commented 7 months ago

I would like to know if it is possible to manually deserialize .mca files, similar to what is done with the level.dat in these examples:

nbt-dump.rs simple-deserialize.rs

I know that level.dat files are compressed with Gzip, and .mca files with Zlib, but I don't know how I should approach the parsing process.

Any help is greatly appreciated!

owengage commented 7 months ago

Hi, you should check out the Region struct in fastanvil. That will let you extract chunks, which you can then read as NBT.

On Fri, 19 Jan 2024, 8:23 pm Jota Lanusse, @.***> wrote:

I would like to know if it is possible to manually deserialize .mca files, similar to what is done with the level.dat in these examples:

nbt-dump.rs https://github.com/owengage/fastnbt/blob/master/fastnbt/examples/nbt-dump.rs simple-deserialize.rs https://github.com/owengage/fastnbt/blob/master/fastnbt/examples/simple-deserialize.rs

I know that level.dat files are compressed with Gzip, and .mca files with Zlib, but I don't know how I should approach the parsing process.

Any help is greatly appreciated!

— Reply to this email directly, view it on GitHub https://github.com/owengage/fastnbt/issues/100, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB3SQS3N3FGC3RG5VC3D2NLYPLI2PAVCNFSM6AAAAABCCPRX3OVHI2DSMVQWIX3LMV43ASLTON2WKOZSGA4TCMZUGAYTCMQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

jotalanusse commented 7 months ago

There is a function region.read_chunk() that returns a Vec<u8>. Is this the raw NBT data?

owengage commented 7 months ago

Yes it is, uncompressed. You can see the docs here: https://docs.rs/fastanvil/latest/fastanvil/struct.Region.html#method.read_chunk