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.

62 lines
1.9KB

  1. using Gamecraft.Blocks.BlockGroups;
  2. using Unity.Mathematics;
  3. using UnityEngine;
  4. using GamecraftModdingAPI.Blocks;
  5. using GamecraftModdingAPI.Utility;
  6. namespace GamecraftModdingAPI
  7. {
  8. /// <summary>
  9. /// A group of blocks that can be selected together. The placed version of blueprints.
  10. /// </summary>
  11. public class BlockGroup
  12. {
  13. internal static BlueprintEngine _engine = new BlueprintEngine();
  14. public int Id { get; }
  15. private readonly Block sourceBlock;
  16. internal BlockGroup(int id, Block block)
  17. {
  18. if (id == BlockGroupUtility.GROUP_UNASSIGNED)
  19. throw new BlockException("Cannot create a block group for blocks without a group!");
  20. Id = id;
  21. sourceBlock = block;
  22. }
  23. /// <summary>
  24. /// The position of the block group. Calculated when GetBlocks() is used.
  25. /// </summary>
  26. public float3 Position { get; private set; }
  27. /// <summary>
  28. /// The rotation of the block group. Calculated when GetBlocks() is used.
  29. /// </summary>
  30. public float3 Rotation { get; private set; }
  31. /// <summary>
  32. /// Collects each block that is a part of this group. Also sets the position and rotation.
  33. /// </summary>
  34. /// <returns>An array of blocks</returns>
  35. public Block[] GetBlocks()
  36. {
  37. var ret = _engine.GetBlocksFromGroup(sourceBlock.Id, out var pos, out var rot);
  38. Position = pos;
  39. Rotation = ((Quaternion) rot).eulerAngles;
  40. return ret;
  41. }
  42. /// <summary>
  43. /// Removes all of the blocks in this group from the world.
  44. /// </summary>
  45. public void Remove()
  46. {
  47. _engine.RemoveBlockGroup(Id);
  48. }
  49. public static void Init()
  50. {
  51. GameEngineManager.AddGameEngine(_engine);
  52. }
  53. }
  54. }