1
0

Initial sync

This commit is contained in:
2024-03-15 14:44:21 +01:00
commit d2a1cabe35
59 changed files with 3783 additions and 0 deletions

68
Nbt/Tag/NbtTag.cs Executable file
View File

@@ -0,0 +1,68 @@
namespace Nbt.Tag;
public interface INbtTag : IEquatable<INbtTag>
{
NbtTagType Type { get; }
INbtTag this[string tagName] { get => throw new NotSupportedException(); set => throw new NotSupportedException(); }
INbtTag this[int tagIndex] { get => throw new NotSupportedException(); set => throw new NotSupportedException(); }
INbtTag this[INbtPathElement tagPath] { get => throw new NotSupportedException(); set => throw new NotSupportedException(); }
INbtTag this[INbtPath tagPath]
{
get
{
var count = tagPath.Count;
if (count == 0)
{
return this;
}
var pathElt = tagPath.PopFirst(out var pathRest);
var childTag = this[pathElt];
return childTag[pathRest];
}
set
{
var count = tagPath.Count;
if (count == 0)
{
throw new ArgumentException("Path cannot be empty", nameof(value));
}
var pathElt = tagPath.PopFirst(out var pathRest);
if (count == 1)
{
this[pathElt] = value;
}
else
{
var childTag = this[pathElt];
childTag[pathRest] = value;
}
}
}
INbtList AsList() => (INbtList)this;
INbtCompound AsCompound() => (INbtCompound)this;
INbtValue AsValue() => (INbtValue)this;
INbtValue<T> AsValue<T>() where T : notnull => (INbtValue<T>)this;
INbtArray AsArray() => (INbtArray)this;
INbtArray<T> AsArray<T>() where T : notnull => (INbtArray<T>)this;
T As<T>() where T : INbtTag => (T)this;
INbtTag Copy();
}