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.

114 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 Motor : Block
  9. {
  10. /// <summary>
  11. /// Places a new motor.
  12. /// Any valid motor type is accepted.
  13. /// This re-implements Block.PlaceNew(...)
  14. /// </summary>
  15. public static new Motor 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.MotorS || block == BlockIDs.MotorM))
  20. {
  21. throw new BlockTypeException($"Block is not a {typeof(Motor).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. Sync();
  30. return new Motor(id);
  31. }
  32. catch (Exception e)
  33. {
  34. Logging.MetaDebugLog(e);
  35. }
  36. }
  37. return null;
  38. }
  39. public Motor(EGID id) : base(id)
  40. {
  41. if (!BlockEngine.GetBlockInfoExists<MotorReadOnlyStruct>(this.Id))
  42. {
  43. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  44. }
  45. }
  46. public Motor(uint id) : base(id)
  47. {
  48. if (!BlockEngine.GetBlockInfoExists<MotorReadOnlyStruct>(this.Id))
  49. {
  50. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  51. }
  52. }
  53. // custom motor properties
  54. /// <summary>
  55. /// The motor's maximum rotational velocity.
  56. /// </summary>
  57. public float TopSpeed
  58. {
  59. get
  60. {
  61. return BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id).maxVelocity;
  62. }
  63. set
  64. {
  65. ref MotorReadOnlyStruct motor = ref BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id);
  66. motor.maxVelocity = value;
  67. }
  68. }
  69. /// <summary>
  70. /// The motor's maximum rotational force.
  71. /// </summary>
  72. public float Torque
  73. {
  74. get
  75. {
  76. return BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id).maxForce;
  77. }
  78. set
  79. {
  80. ref MotorReadOnlyStruct motor = ref BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id);
  81. motor.maxForce = value;
  82. }
  83. }
  84. /// <summary>
  85. /// The motor's direction.
  86. /// </summary>
  87. public bool Reverse
  88. {
  89. get
  90. {
  91. return BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id).reverse;
  92. }
  93. set
  94. {
  95. ref MotorReadOnlyStruct motor = ref BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id);
  96. motor.reverse = value;
  97. }
  98. }
  99. }
  100. }