TechbloxModdingAPI/GamecraftModdingAPI/BlockGroup.cs

62 lines
No EOL
1.9 KiB
C#

using Gamecraft.Blocks.BlockGroups;
using Unity.Mathematics;
using UnityEngine;
using GamecraftModdingAPI.Blocks;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI
{
/// <summary>
/// A group of blocks that can be selected together. The placed version of blueprints.
/// </summary>
public class BlockGroup
{
internal static BlueprintEngine _engine = new BlueprintEngine();
public int Id { get; }
private readonly Block sourceBlock;
internal BlockGroup(int id, Block block)
{
if (id == BlockGroupUtility.GROUP_UNASSIGNED)
throw new BlockException("Cannot create a block group for blocks without a group!");
Id = id;
sourceBlock = block;
}
/// <summary>
/// The position of the block group. Calculated when GetBlocks() is used.
/// </summary>
public float3 Position { get; private set; }
/// <summary>
/// The rotation of the block group. Calculated when GetBlocks() is used.
/// </summary>
public float3 Rotation { get; private set; }
/// <summary>
/// Collects each block that is a part of this group. Also sets the position and rotation.
/// </summary>
/// <returns>An array of blocks</returns>
public Block[] GetBlocks()
{
var ret = _engine.GetBlocksFromGroup(sourceBlock.Id, out var pos, out var rot);
Position = pos;
Rotation = ((Quaternion) rot).eulerAngles;
return ret;
}
/// <summary>
/// Removes all of the blocks in this group from the world.
/// </summary>
public void Remove()
{
_engine.RemoveBlockGroup(Id);
}
public static void Init()
{
GameEngineManager.AddGameEngine(_engine);
}
}
}