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.

Servo.cs 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 {typeof(Servo).Name} block");
  22. }
  23. if (PlacementEngine.IsInGame && GameState.IsBuildMode())
  24. {
  25. try
  26. {
  27. EGID id = PlacementEngine.PlaceBlock(block, color, darkness,
  28. position, uscale, scale, player, rotation);
  29. return new Servo(id);
  30. }
  31. catch (Exception e)
  32. {
  33. Logging.MetaDebugLog(e);
  34. }
  35. }
  36. return null;
  37. }
  38. public Servo(EGID 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. public Servo(uint id) : base(id)
  46. {
  47. if (!BlockEngine.GetBlockInfoExists<ServoReadOnlyStruct>(this.Id))
  48. {
  49. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  50. }
  51. }
  52. // custom servo properties
  53. /// <summary>
  54. /// The servo's minimum angle.
  55. /// </summary>
  56. public float MinimumAngle
  57. {
  58. get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).minDeviation;
  59. set
  60. {
  61. ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
  62. servo.minDeviation = value;
  63. }
  64. }
  65. /// <summary>
  66. /// The servo's maximum angle.
  67. /// </summary>
  68. public float MaximumAngle
  69. {
  70. get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).maxDeviation;
  71. set
  72. {
  73. ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
  74. servo.maxDeviation = value;
  75. }
  76. }
  77. /// <summary>
  78. /// The servo's maximum force.
  79. /// </summary>
  80. public float MaximumForce
  81. {
  82. get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).maxForce;
  83. set
  84. {
  85. ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
  86. servo.maxForce = value;
  87. }
  88. }
  89. /// <summary>
  90. /// The servo's direction.
  91. /// </summary>
  92. public bool Reverse
  93. {
  94. get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).reverse;
  95. set
  96. {
  97. ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
  98. servo.reverse = value;
  99. }
  100. }
  101. }
  102. }