Rusty-Quartz / quartz_nbt

Provides support for encoding and decoding Minecraft's NBT format. This crate supports both zlib and gz compression, and also provides tools for converting NBT data to stringified NBT (SNBT) and vice versa.
https://crates.io/crates/quartz_nbt
MIT License
25 stars 10 forks source link

Reading Bedrock level.dat/.mcstructure files #3

Open BJTMastermind opened 2 years ago

BJTMastermind commented 2 years ago

I am trying to use quartz_nbt to read nbt data from Bedrock files but I can't seem to get it to work. Im getting an Error: TagTypeMismatch { expected: 10, found: 8 } with this code:

use std::fs::File;
use quartz_nbt::io::{self, Flavor, NbtIoError};

fn main() -> Result<(), NbtIoError> {
    let mut bedrock_test = File::open("assets/bedrock/level.dat")?;
    //let mut java_test = File::open("assets/java/level.dat")?;

    let nbt = io::read_nbt(&mut bedrock_test, Flavor::Uncompressed)?;

    println!("uncompressed: {:?}", nbt);

    Ok(())
}

this works fine with the java files though when the "Flavor" is also set to GzCompressed. Any help? I do know Bedrock nbt files are Uncompressed I believe.

I can also provide the nbt files if they are needed.

Thank you.

BJTMastermind commented 2 years ago

After looking through the source files of quartz_nbt I think the reason for this is because quartz_nbt currently does not support little-endian byte order. If this were added I believe it will work with minor changes to the code I showed.

Cassy343 commented 2 years ago

Bedrock edition actually makes quite a few changes to NBT format. They store some integers and longs as variable-length integers using zig-zag encoding; there are different variations of the format for disk storage vs. network traffic; root tags can be compounds or lists; and as you mentioned, they also use little-endian byte order. Supporting this would require a fairly substantial overhaul of the current code base and require changing several of the APIs, so I'm inclined to say it's unlikely that we'll support encoding/decoding of bedrock's NBT format for the foreseeable future.

BJTMastermind commented 2 years ago

oh ok, didn't think it had that many differences. I was hoping that it could be added so there could be a good rust crate to use for both versions of the game. Do you know of any rust crates that support the bedrock format that I could use because I'm not aware of any? If not could you give me a link to bedrock nbt documentation so I could try to make my own?

Cassy343 commented 2 years ago

I do not know of any rust NBT libraries which support bedrock unfortunately. This wiki explains the Java format as well as how bedrock differs from it. I will be leaving this issue open however so that it can be revisited in the future.