ForeverZer0 / SharpNBT

A pure CLS-compliant C# implementation of the Named Binary Tag (NBT) format specification commonly used with Minecraft applications, allowing easy reading/writing streams and serialization to other formats.
MIT License
25 stars 9 forks source link

Cant get a nested tag #30

Open Awire9966 opened 5 months ago

Awire9966 commented 5 months ago

Hi. I am trying to read from the Minecraft level.dat file for a project i am working on. This is my code:

CompoundTag WorldData = NbtFile.Read(WorldFolder + @".\level.dat", FormatOptions.Java, CompressionType.AutoDetect);
var seed = WorldData["Data"]["WorldGenSettings"]["Seed"];

It is giving me the error stating that I cant use [] on the Array.

ForeverZer0 commented 5 months ago

I am uncertain why you would be getting an array-related error based on the given example. According to the wiki, the key for the seed should be "seed", and not "Seed", though I assume that would cause an error related to the key, not an indexing error for an Array.

Would you be able to separate these out to see which accessor specifically is causing the error, and confirming that each tag is being deserialized correctly?

var data = WorldData["Data"];
var gen = data["WorldGenSettings"];
var seed =  gen["seed"];

On another note, not likely related to your problem, is the leading dot in WorldFolder + @".\level.dat" intended?