diff --git a/PckStudio.Core/Extensions/TagCompoundExtensions.cs b/PckStudio.Core/Extensions/TagCompoundExtensions.cs new file mode 100644 index 00000000..3a9e890b --- /dev/null +++ b/PckStudio.Core/Extensions/TagCompoundExtensions.cs @@ -0,0 +1,26 @@ +using System.Numerics; +using Cyotek.Data.Nbt; + +namespace PckStudio.Core.Extensions +{ + static class TagCompoundExtensions + { + public static Vector3 GetVector3(this TagCompound tag, string name) => tag.TryGetVector3(name, out Vector3 vec3) ? vec3 : default; + + public static bool TryGetVector2(this TagCompound tag, string name, out Vector2 value) + { + (string x, string y) = (name + "X", name + "Y"); + bool hasValues = tag.Contains(x) && tag.Contains(y); + value = hasValues ? new Vector2((float)tag[x].GetValue(), (float)tag[y].GetValue()) : default; + return hasValues; + } + + public static bool TryGetVector3(this TagCompound tag, string name, out Vector3 value) + { + string z = name + "Z"; + bool hasValues = tag.TryGetVector2(name, out Vector2 vec2) && tag.Contains(z); + value = hasValues ? new Vector3(vec2, (float)tag[z].GetValue()) : default; + return hasValues; + } + } +} \ No newline at end of file diff --git a/PckStudio.Core/PckStudio.Core.csproj b/PckStudio.Core/PckStudio.Core.csproj index 44a712b3..3ffd9e16 100644 --- a/PckStudio.Core/PckStudio.Core.csproj +++ b/PckStudio.Core/PckStudio.Core.csproj @@ -171,6 +171,7 @@ True Resources.resx +