Port NBT impl from LibAC Dart
This commit is contained in:
parent
0a022634c1
commit
ad7b619706
55 changed files with 3226 additions and 2983 deletions
67
NBT/ByteTag.cs
Normal file
67
NBT/ByteTag.cs
Normal file
|
@ -0,0 +1,67 @@
|
|||
using System;
|
||||
using LibAC.NBT.API;
|
||||
|
||||
namespace LibAC.NBT
|
||||
{
|
||||
public class ByteTag : Tag
|
||||
{
|
||||
public byte Value { get; private set; } = 0;
|
||||
|
||||
public ByteTag() { }
|
||||
|
||||
private ByteTag(byte value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public static ByteTag ValueOf(byte value)
|
||||
{
|
||||
return new ByteTag(value);
|
||||
}
|
||||
|
||||
public override void ReadValue(ByteLayer data)
|
||||
{
|
||||
Value = data.ReadByte();
|
||||
}
|
||||
|
||||
public override void WriteValue(ByteLayer data)
|
||||
{
|
||||
data.WriteByte(Value);
|
||||
}
|
||||
|
||||
public override TagType GetTagType()
|
||||
{
|
||||
return TagType.Byte;
|
||||
}
|
||||
|
||||
public override dynamic GetValue()
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
|
||||
public override void SetValue(dynamic val)
|
||||
{
|
||||
if (val is byte)
|
||||
{
|
||||
Value = (byte)val;
|
||||
}
|
||||
}
|
||||
|
||||
public override void PrettyPrint(int indent, bool recurse)
|
||||
{
|
||||
Console.WriteLine($"{new string('\t', indent)}{Tag.GetCanonicalName(GetTagType())}: {Value}");
|
||||
}
|
||||
|
||||
public override void WriteStringifiedValue(StringBuilder builder, int indent, bool isList)
|
||||
{
|
||||
builder.Append($"{Value}b");
|
||||
}
|
||||
|
||||
public override void ReadStringifiedValue(StringReader reader)
|
||||
{
|
||||
string val = reader.ReadNumber();
|
||||
Value = byte.Parse(val);
|
||||
reader.Expect('b');
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue