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.

111 lines
3.1KB

  1. using System;
  2. using RobocraftX.Blocks;
  3. using Svelto.ECS;
  4. using Unity.Mathematics;
  5. using GamecraftModdingAPI.Utility;
  6. namespace GamecraftModdingAPI.Blocks
  7. {
  8. public class Servo : Block
  9. {
  10. /// <summary>
  11. /// Places a new servo.
  12. /// Any valid servo type is accepted.
  13. /// This re-implements Block.PlaceNew(...)
  14. /// </summary>
  15. public static new Servo PlaceNew(BlockIDs block, float3 position,
  16. float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
  17. int uscale = 1, float3 scale = default, Player player = null)
  18. {
  19. if (!(block == BlockIDs.ServoAxle || block == BlockIDs.ServoHinge || block == BlockIDs.ServoPiston))
  20. {
  21. throw new BlockTypeException($"Block is not a {nameof(Servo)} block");
  22. }
  23. if (PlacementEngine.IsInGame && GameState.IsBuildMode())
  24. {
  25. EGID id = PlacementEngine.PlaceBlock(block, color, darkness,
  26. position, uscale, scale, player, rotation);
  27. return new Servo(id);
  28. }
  29. return null;
  30. }
  31. public Servo(EGID id) : base(id)
  32. {
  33. if (!BlockEngine.GetBlockInfoExists<ServoReadOnlyStruct>(this.Id))
  34. {
  35. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  36. }
  37. }
  38. public Servo(uint id) : base(id)
  39. {
  40. if (!BlockEngine.GetBlockInfoExists<ServoReadOnlyStruct>(this.Id))
  41. {
  42. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  43. }
  44. }
  45. // custom servo properties
  46. /// <summary>
  47. /// The servo's minimum angle.
  48. /// </summary>
  49. public float MinimumAngle
  50. {
  51. get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).minDeviation;
  52. set
  53. {
  54. ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
  55. servo.minDeviation = value;
  56. }
  57. }
  58. /// <summary>
  59. /// The servo's maximum angle.
  60. /// </summary>
  61. public float MaximumAngle
  62. {
  63. get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).maxDeviation;
  64. set
  65. {
  66. ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
  67. servo.maxDeviation = value;
  68. }
  69. }
  70. /// <summary>
  71. /// The servo's maximum force.
  72. /// </summary>
  73. public float MaximumForce
  74. {
  75. get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).maxForce;
  76. set
  77. {
  78. ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
  79. servo.maxForce = value;
  80. }
  81. }
  82. /// <summary>
  83. /// The servo's direction.
  84. /// </summary>
  85. public bool Reverse
  86. {
  87. get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).reverse;
  88. set
  89. {
  90. ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
  91. servo.reverse = value;
  92. }
  93. }
  94. }
  95. }