Port NBT impl from LibAC Dart
This commit is contained in:
parent
0a022634c1
commit
ad7b619706
55 changed files with 3226 additions and 2983 deletions
65
NBT/ShortTag.cs
Normal file
65
NBT/ShortTag.cs
Normal file
|
@ -0,0 +1,65 @@
|
|||
using System;
|
||||
using LibAC.NBT.API;
|
||||
|
||||
namespace LibAC.NBT
|
||||
{
|
||||
public class ShortTag : Tag
|
||||
{
|
||||
public short value { get; private set; }
|
||||
= 0;
|
||||
public ShortTag() { }
|
||||
|
||||
public ShortTag(short value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static ShortTag ValueOf(short value)
|
||||
{
|
||||
return new ShortTag(value);
|
||||
}
|
||||
|
||||
public override void ReadValue(ByteLayer data)
|
||||
{
|
||||
value = data.ReadShort();
|
||||
}
|
||||
|
||||
public override void WriteValue(ByteLayer data)
|
||||
{
|
||||
data.WriteShort(value);
|
||||
}
|
||||
|
||||
public override TagType GetTagType()
|
||||
{
|
||||
return TagType.Short;
|
||||
}
|
||||
|
||||
public override void SetValue(dynamic val)
|
||||
{
|
||||
if (val is short) value = val;
|
||||
}
|
||||
|
||||
public override dynamic GetValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
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($"{(isList ? new string('\t', indent) : "")}{value}S");
|
||||
}
|
||||
|
||||
public override void ReadStringifiedValue(StringReader reader)
|
||||
{
|
||||
short val = short.Parse(reader.ReadNumber());
|
||||
value = val;
|
||||
|
||||
reader.Expect('s');
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue