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/DoubleTag.cs
Normal file
67
NBT/DoubleTag.cs
Normal file
|
@ -0,0 +1,67 @@
|
|||
using System;
|
||||
using LibAC.NBT.API;
|
||||
|
||||
namespace LibAC.NBT
|
||||
{
|
||||
public class DoubleTag : Tag
|
||||
{
|
||||
public double Value { get; private set; } = 0.0;
|
||||
|
||||
public DoubleTag() { }
|
||||
|
||||
private DoubleTag(double value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public static DoubleTag ValueOf(double value)
|
||||
{
|
||||
return new DoubleTag(value);
|
||||
}
|
||||
|
||||
public override void ReadValue(ByteLayer data)
|
||||
{
|
||||
Value = data.ReadDouble();
|
||||
}
|
||||
|
||||
public override void WriteValue(ByteLayer data)
|
||||
{
|
||||
data.WriteDouble(Value);
|
||||
}
|
||||
|
||||
public override TagType GetTagType()
|
||||
{
|
||||
return TagType.Double;
|
||||
}
|
||||
|
||||
public override dynamic GetValue()
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
|
||||
public override void SetValue(dynamic val)
|
||||
{
|
||||
if (val is double)
|
||||
{
|
||||
Value = (double)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($"{(isList ? new string('\t', indent) : "")}{Value}d");
|
||||
}
|
||||
|
||||
public override void ReadStringifiedValue(StringReader reader)
|
||||
{
|
||||
double val = double.Parse(reader.ReadNumber());
|
||||
Value = val;
|
||||
reader.Expect('d');
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue