Port NBT impl from LibAC Dart
This commit is contained in:
parent
0a022634c1
commit
ad7b619706
55 changed files with 3226 additions and 2983 deletions
43
NBT/API/NbtUUID.cs
Normal file
43
NBT/API/NbtUUID.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
using System;
|
||||
using LibAC.Utilities;
|
||||
|
||||
namespace LibAC.NBT.API
|
||||
{
|
||||
public class NbtUUID
|
||||
{
|
||||
public long MSB { get; }
|
||||
public long LSB { get; }
|
||||
|
||||
public static readonly NbtUUID ZERO = new NbtUUID(UUID.ZERO);
|
||||
|
||||
public NbtUUID(long msb, long lsb)
|
||||
{
|
||||
MSB = msb;
|
||||
LSB = lsb;
|
||||
}
|
||||
|
||||
public NbtUUID(UUID uuid)
|
||||
{
|
||||
byte[] uuidBytes = uuid.GetBytes();
|
||||
MSB = BitConverter.ToInt64(uuidBytes, 0);
|
||||
LSB = BitConverter.ToInt64(uuidBytes, 8);
|
||||
}
|
||||
|
||||
public long GetMostSignificantBits() => MSB;
|
||||
|
||||
public long GetLeastSignificantBits() => LSB;
|
||||
|
||||
public UUID ToUUID()
|
||||
{
|
||||
byte[] bytes = new byte[16];
|
||||
BitConverter.GetBytes(MSB).CopyTo(bytes, 0);
|
||||
BitConverter.GetBytes(LSB).CopyTo(bytes, 8);
|
||||
return new UUID(bytes);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ToUUID().ToString();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue