TechbloxModdingAPI/GamecraftModdingAPI/Blueprint.cs

64 lines
2.2 KiB
C#
Raw Normal View History

using System;
using Unity.Mathematics;
namespace GamecraftModdingAPI
{
/// <summary>
/// Represents a blueprint in the inventory. When placed it becomes a block group.
/// </summary>
public class Blueprint : IDisposable
{
public uint Id { get; }
internal Blueprint(uint id)
{
Id = id;
BlockGroup._engine.InitBlueprint(id);
}
/*public static void SelectBlueprint(Blueprint blueprint)
{
BlueprintUtil.SelectBlueprint(null, new BlueprintInventoryItemEntityStruct
{
blueprintResourceId = blueprint.Id
});
}*/
/// <summary>
/// Creates a new, empty blueprint. It will be deleted on disposal unless the game holds a reference to it.
/// </summary>
/// <returns>A blueprint that doesn't have any blocks</returns>
public static Blueprint Create()
{
return new Blueprint(BlockGroup._engine.CreateBlueprint());
}
/// <summary>
/// Set the blocks that the blueprint contains.
/// </summary>
/// <param name="blocks">The array of blocks to use</param>
/// <param name="position">The anchor position of the blueprint</param>
/// <param name="rotation">The rotation of the blueprint</param>
public void SetStoredBlocks(Block[] blocks, float3 position = default, float3 rotation = default)
{
BlockGroup._engine.ReplaceBlueprint(Player.LocalPlayer.Id, Id, blocks, position,
quaternion.Euler(rotation));
}
/// <summary>
/// Places the blocks the blueprint contains at the specified position and rotation.
/// </summary>
/// <param name="position">The position of the blueprint</param>
/// <param name="rotation">The rotation of the blueprint</param>
/// <returns>An array of the placed blocks</returns>
public Block[] PlaceBlocks(float3 position, float3 rotation)
{
return BlockGroup._engine.PlaceBlueprintBlocks(Id, Player.LocalPlayer.Id, position, rotation);
}
public void Dispose()
{
BlockGroup._engine.DisposeBlueprint(Id);
}
}
}