From 83f0aff8b71df1e193efef840d394492f03ab8bf Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Wed, 19 Nov 2025 21:26:46 +0100 Subject: [PATCH] Core - Add TagCompoundExtensions.cs --- .../Extensions/TagCompoundExtensions.cs | 26 +++++++++++++++++++ PckStudio.Core/PckStudio.Core.csproj | 1 + 2 files changed, 27 insertions(+) create mode 100644 PckStudio.Core/Extensions/TagCompoundExtensions.cs 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 +