A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Blueprint.cs 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using Unity.Mathematics;
  3. using UnityEngine;
  4. namespace GamecraftModdingAPI
  5. {
  6. /// <summary>
  7. /// Represents a blueprint in the inventory. When placed it becomes a block group.
  8. /// </summary>
  9. public class Blueprint : IDisposable
  10. {
  11. public uint Id { get; }
  12. internal Blueprint(uint id)
  13. {
  14. Id = id;
  15. BlockGroup._engine.InitBlueprint(id);
  16. }
  17. /*public static void SelectBlueprint(Blueprint blueprint)
  18. {
  19. BlueprintUtil.SelectBlueprint(null, new BlueprintInventoryItemEntityStruct
  20. {
  21. blueprintResourceId = blueprint.Id
  22. });
  23. }*/
  24. /// <summary>
  25. /// Creates a new, empty blueprint. It will be deleted on disposal unless the game holds a reference to it.
  26. /// </summary>
  27. /// <returns>A blueprint that doesn't have any blocks</returns>
  28. public static Blueprint Create()
  29. {
  30. return new Blueprint(BlockGroup._engine.CreateBlueprint());
  31. }
  32. /// <summary>
  33. /// Set the blocks that the blueprint contains.
  34. /// Use the BlockGroup overload for automatically calculated position and rotation.
  35. /// </summary>
  36. /// <param name="blocks">The array of blocks to use</param>
  37. /// <param name="position">The anchor position of the blueprint</param>
  38. /// <param name="rotation">The base rotation of the blueprint</param>
  39. public void StoreBlocks(Block[] blocks, float3 position, float3 rotation)
  40. {
  41. BlockGroup._engine.ReplaceBlueprint(Player.LocalPlayer.Id, Id, blocks, position,
  42. quaternion.Euler(rotation));
  43. }
  44. /// <summary>
  45. /// Store the blocks from the given group in the blueprint with correct position and rotation for the blueprint.
  46. /// </summary>
  47. /// <param name="group">The block group to store</param>
  48. public void StoreBlocks(BlockGroup group)
  49. {
  50. BlockGroup._engine.ReplaceBlueprint(Player.LocalPlayer.Id, Id, group, group.Position,
  51. Quaternion.Euler(group.Rotation));
  52. }
  53. /// <summary>
  54. /// Places the blocks the blueprint contains at the specified position and rotation.
  55. /// </summary>
  56. /// <param name="position">The position of the blueprint</param>
  57. /// <param name="rotation">The rotation of the blueprint</param>
  58. /// <returns>An array of the placed blocks</returns>
  59. public Block[] PlaceBlocks(float3 position, float3 rotation)
  60. {
  61. return BlockGroup._engine.PlaceBlueprintBlocks(Id, Player.LocalPlayer.Id, position, rotation);
  62. }
  63. public void Dispose()
  64. {
  65. BlockGroup._engine.DisposeBlueprint(Id);
  66. }
  67. }
  68. }