using Gamecraft.Blocks.BlockGroups; using Unity.Mathematics; using UnityEngine; using GamecraftModdingAPI.Blocks; using GamecraftModdingAPI.Utility; namespace GamecraftModdingAPI { /// /// A group of blocks that can be selected together. The placed version of blueprints. /// 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; } /// /// The position of the block group. Calculated when GetBlocks() is used. /// public float3 Position { get; private set; } /// /// The rotation of the block group. Calculated when GetBlocks() is used. /// public float3 Rotation { get; private set; } /// /// Collects each block that is a part of this group. Also sets the position and rotation. /// /// An array of blocks public Block[] GetBlocks() { var ret = _engine.GetBlocksFromGroup(sourceBlock.Id, out var pos, out var rot); Position = pos; Rotation = ((Quaternion) rot).eulerAngles; return ret; } /// /// Removes all of the blocks in this group from the world. /// public void Remove() { _engine.RemoveBlockGroup(Id); } public static void Init() { GameEngineManager.AddGameEngine(_engine); } } }