Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inhomogeneous values of Value::List when reading chunk data #55

Open
gcharnock opened this issue Jul 19, 2020 · 0 comments
Open

Inhomogeneous values of Value::List when reading chunk data #55

gcharnock opened this issue Jul 19, 2020 · 0 comments

Comments

@gcharnock
Copy link

When loading nbt data from a chunk, various lists of numbers such as BlockStates are returned as inhomogeneous lists of various integer sizes. This seems to cause problems when trying to save these values back and the result causes minecraft to reset the chunk.

Reading the "specification" for NBT, it seems like inhomogeneous lists shouldn't be representable as the tag that indicates the type of the values in the list is only given once for the entire list. I don't know if this is some undocumented feature or if it is what is causing the chuck resets, but it seemed weird to me.

I've attached an example of chunk nbt data that seems to have this problem.

original_bytes.nbt.txt

It's base64 encoded because github doesn't seem to want to let me upload a binary file. Decode with:

base64 -d original_bytes.nbt.txt > original_bytes.nbt

Here is code I used to check for inhomogeneous lists.

use nbt::Value;
use std::collections::HashMap;

pub fn check_value(value: &Value) {
    match value {
        Value::Byte(b) => return,
        Value::Short(s) => return,
        Value::Int(i) => return,
        Value::Long(l) => return,
        Value::Float(f) => return,
        Value::Double(d) => return,
        Value::String(s) => return,
        Value::List(l) => check_list(l),
        Value::Compound(c) => check_compound(c),
        Value::ByteArray(ba) => return,
        Value::IntArray(ia) => return,
        Value::LongArray(la) => return 
    }
}

pub fn check_compound(c: &HashMap<String, Value>) {
    for (key, value) in c.iter() {
        println!("KEY: {} => {}", key, value.tag_name());
        check_value(value);
    }
}

fn check_list(l: &Vec<Value>) {
    match l.first() {
        Some(first) => {
            let tag = first.id();
            for v in l.iter() {
                if v.id() != tag {
                    panic!("NBT lists cannot be inhomogenious");
                }
            }
        }
        None => return
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants