quartz_nbt icon indicating copy to clipboard operation
quartz_nbt copied to clipboard

Reading Bedrock level.dat/.mcstructure files

Open BJTMastermind opened this issue 4 years ago • 5 comments

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 avatar Oct 12 '21 22:10 BJTMastermind

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.

BJTMastermind avatar Oct 12 '21 23:10 BJTMastermind

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.

Cassy343 avatar Oct 14 '21 05:10 Cassy343

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?

BJTMastermind avatar Oct 14 '21 16:10 BJTMastermind

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.

Cassy343 avatar Oct 15 '21 14:10 Cassy343