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

Fix an edge case for NbtReader #414

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions Obsidian.Nbt/NbtTag.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Obsidian.Nbt;

public class NbtTag<T> : INbtTag
public sealed class NbtTag<T> : INbtTag
{
public NbtTagType Type { get; }

Expand All @@ -11,13 +11,18 @@ public class NbtTag<T> : INbtTag
/// </summary>
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,
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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;
}
}
}
Expand Down
33 changes: 17 additions & 16 deletions Obsidian.Nbt/Obsidian.Nbt.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>annotations</Nullable>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<None Include="..\.editorconfig" Link=".editorconfig" />
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<ItemGroup>
<None Include="..\.editorconfig" Link=".editorconfig" />
</ItemGroup>

<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
</Project>
Loading