Port NBT impl from LibAC Dart
This commit is contained in:
parent
0a022634c1
commit
ad7b619706
55 changed files with 3226 additions and 2983 deletions
66
NBT/FloatTag.cs
Normal file
66
NBT/FloatTag.cs
Normal file
|
@ -0,0 +1,66 @@
|
|||
using System;
|
||||
using LibAC.NBT.API;
|
||||
|
||||
namespace LibAC.NBT
|
||||
{
|
||||
public class FloatTag : Tag
|
||||
{
|
||||
public float value { get; private set; } = 0.0f;
|
||||
|
||||
public FloatTag() { }
|
||||
|
||||
private FloatTag(float value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static FloatTag ValueOf(float value)
|
||||
{
|
||||
return new FloatTag(value);
|
||||
}
|
||||
|
||||
public override void ReadValue(ByteLayer data)
|
||||
{
|
||||
value = data.ReadFloat();
|
||||
}
|
||||
|
||||
public override void WriteValue(ByteLayer data)
|
||||
{
|
||||
data.WriteFloat(value);
|
||||
}
|
||||
|
||||
public override TagType GetTagType()
|
||||
{
|
||||
return TagType.Float;
|
||||
}
|
||||
|
||||
public override object GetValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
public override void SetValue(object val)
|
||||
{
|
||||
if (val is float)
|
||||
{
|
||||
value = (float)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}f");
|
||||
}
|
||||
|
||||
public override void ReadStringifiedValue(StringReader reader)
|
||||
{
|
||||
value = float.Parse(reader.ReadNumber());
|
||||
reader.Expect('f');
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue