using System; using Unity.Mathematics; using UnityEngine; namespace TechbloxModdingAPI { /// /// Represents a blueprint in the inventory. When placed it becomes a block group. /// public class Blueprint : IDisposable { public uint Id { get; } internal Blueprint(uint id) { Id = id; BlockGroup._engine.InitBlueprint(id); Refresh(); } /// /// The center of the blueprint. Can only be set using the StoreBlocks() method. /// public float3 Position { get; private set; } /// /// The rotation of the blueprint. Can only be set using the StoreBlocks() method. /// public float3 Rotation { get; private set; } /// /// The amount of blocks in the blueprint. Gan only be set using the StoreBlocks() method. /// public uint BlockCount { get; private set; } /// /// Creates a new, empty blueprint. It will be deleted on disposal unless the game holds a reference to it. /// /// A blueprint that doesn't have any blocks public static Blueprint Create() { return new Blueprint(BlockGroup._engine.CreateBlueprint()); } /// /// Set the blocks that the blueprint contains. /// Use the BlockGroup overload for automatically calculated position and rotation. /// /// The array of blocks to use /// The anchor (center) position of the blueprint /// The base rotation of the blueprint public void StoreBlocks(Block[] blocks, float3 position, float3 rotation) { BlockGroup._engine.ReplaceBlueprint(Player.LocalPlayer.Id, Id, blocks, position, quaternion.Euler(rotation)); Refresh(); } /// /// Store the blocks from the given group in the blueprint with correct position and rotation for the blueprint. /// /// The block group to store public void StoreBlocks(BlockGroup group) { BlockGroup._engine.ReplaceBlueprint(Player.LocalPlayer.Id, Id, group, group.Position, Quaternion.Euler(group.Rotation)); Refresh(); } /// /// Places the blocks the blueprint contains at the specified position and rotation. /// /// The position of the blueprint /// The rotation of the blueprint /// An array of the placed blocks public Block[] PlaceBlocks(float3 position, float3 rotation) { return BlockGroup._engine.PlaceBlueprintBlocks(Id, Player.LocalPlayer.Id, position, rotation); } /// /// Updates the properties based on the blueprint data. Only necessary if the blueprint is changed from the game. /// public void Refresh() { BlockGroup._engine.GetBlueprintInfo(Id, out var pos, out var rot, out uint count); Position = pos; Rotation = ((Quaternion) rot).eulerAngles; BlockCount = count; } public void Dispose() { BlockGroup._engine.DisposeBlueprint(Id); } public override string ToString() { return $"{nameof(Id)}: {Id}, {nameof(Position)}: {Position}, {nameof(Rotation)}: {Rotation}, {nameof(BlockCount)}: {BlockCount}"; } } }