mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-05-27 05:44:43 +00:00
Core - Add TagCompoundExtensions.cs
This commit is contained in:
26
PckStudio.Core/Extensions/TagCompoundExtensions.cs
Normal file
26
PckStudio.Core/Extensions/TagCompoundExtensions.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -171,6 +171,7 @@
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Extensions\TagCompoundExtensions.cs" />
|
||||
<Compile Include="Tiles.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user