Port NBT impl from LibAC Dart
This commit is contained in:
parent
0a022634c1
commit
ad7b619706
55 changed files with 3226 additions and 2983 deletions
84
NBT/LongArrayTag.cs
Normal file
84
NBT/LongArrayTag.cs
Normal file
|
@ -0,0 +1,84 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using LibAC.NBT.API;
|
||||
|
||||
namespace LibAC.NBT
|
||||
{
|
||||
public class LongArrayTag : Tag
|
||||
{
|
||||
public List<long> value { get; private set; } = new List<long>();
|
||||
|
||||
public LongArrayTag() { }
|
||||
|
||||
public LongArrayTag(List<long> lst)
|
||||
{
|
||||
value.AddRange(lst);
|
||||
}
|
||||
|
||||
public static LongArrayTag ValueOf(List<long> value)
|
||||
{
|
||||
return new LongArrayTag(value);
|
||||
}
|
||||
|
||||
public override void ReadValue(ByteLayer data)
|
||||
{
|
||||
int count = data.ReadInt();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
value.Add(data.ReadLong());
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteValue(ByteLayer data)
|
||||
{
|
||||
data.WriteInt(Size());
|
||||
foreach (long val in value)
|
||||
{
|
||||
data.WriteLong(val);
|
||||
}
|
||||
}
|
||||
|
||||
public int Size()
|
||||
{
|
||||
return value.Count;
|
||||
}
|
||||
|
||||
public override TagType GetTagType()
|
||||
{
|
||||
return TagType.LongArray;
|
||||
}
|
||||
|
||||
public override void SetValue(dynamic val) { }
|
||||
|
||||
public override dynamic GetValue()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void PrettyPrint(int indent, bool recurse)
|
||||
{
|
||||
string array = string.Join(", ", value);
|
||||
Console.WriteLine($"{new string('\t', indent)}{Tag.GetCanonicalName(GetTagType())}: [{array}]");
|
||||
}
|
||||
|
||||
public override void WriteStringifiedValue(StringBuilder builder, int indent, bool isList)
|
||||
{
|
||||
builder.Append($"{(isList ? new string('\t', indent) : "")}[L; {string.Join("L, ", value)}L]");
|
||||
}
|
||||
|
||||
public override void ReadStringifiedValue(StringReader reader)
|
||||
{
|
||||
reader.Expect('[');
|
||||
reader.Expect('L');
|
||||
reader.Expect(';');
|
||||
while (reader.Peek() != ']')
|
||||
{
|
||||
value.Add(long.Parse(reader.ReadNumber()));
|
||||
reader.Expect('l');
|
||||
|
||||
if (reader.Peek() == ',') reader.Next();
|
||||
}
|
||||
reader.Expect(']');
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue