diff --git a/Obsidian.Nbt/NbtTag.cs b/Obsidian.Nbt/NbtTag.cs index fe940ea07..92f8f2a39 100644 --- a/Obsidian.Nbt/NbtTag.cs +++ b/Obsidian.Nbt/NbtTag.cs @@ -1,6 +1,6 @@ namespace Obsidian.Nbt; -public class NbtTag : INbtTag +public sealed class NbtTag : INbtTag { public NbtTagType Type { get; } @@ -11,13 +11,18 @@ public class NbtTag : INbtTag /// public INbtTag Parent { get; set; } - public T Value { get; } + public T? Value { get; } - public NbtTag(string name, T value, INbtTag parent = null) + public NbtTag(string name, T? value, INbtTag parent = null) { this.Name = name; this.Parent = parent; this.Value = value; + + //Some structure files from minecraft have properties with names but null values??? + if (value is null) + return; + this.Type = value switch { bool => NbtTagType.Byte, @@ -45,7 +50,7 @@ public override string ToString() case NbtTagType.String: return $"TAG_{this.Type}('{this.Name}'): {this.Value}"; default: - throw new NotSupportedException("Only generic types are supported."); + return string.Empty; } } @@ -65,7 +70,7 @@ public string PrettyString(int depth = 2, int addBraceDepth = 1) return name.PadLeft(name.Length + depth); } default: - throw new NotSupportedException("Only generic types are supported."); + return string.Empty; } } } diff --git a/Obsidian.Nbt/Obsidian.Nbt.csproj b/Obsidian.Nbt/Obsidian.Nbt.csproj index 615a9af8c..83ef39f8d 100644 --- a/Obsidian.Nbt/Obsidian.Nbt.csproj +++ b/Obsidian.Nbt/Obsidian.Nbt.csproj @@ -1,22 +1,23 @@  - - net8.0 - + + net8.0 + annotations + - - true - + + true + - - true - + + true + - - - - - - - + + + + + + +