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.

112 lines
3.2KB

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