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.

106 lines
2.9KB

  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. EGID id = PlacementEngine.PlaceBlock(block, color, darkness,
  26. position, uscale, scale, player, rotation);
  27. return new Motor(id);
  28. }
  29. return null;
  30. }
  31. public Motor(EGID id) : base(id)
  32. {
  33. if (!BlockEngine.GetBlockInfoExists<MotorReadOnlyStruct>(this.Id))
  34. {
  35. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  36. }
  37. }
  38. public Motor(uint id) : base(id)
  39. {
  40. if (!BlockEngine.GetBlockInfoExists<MotorReadOnlyStruct>(this.Id))
  41. {
  42. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  43. }
  44. }
  45. // custom motor properties
  46. /// <summary>
  47. /// The motor's maximum rotational velocity.
  48. /// </summary>
  49. public float TopSpeed
  50. {
  51. get
  52. {
  53. return BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id).maxVelocity;
  54. }
  55. set
  56. {
  57. ref MotorReadOnlyStruct motor = ref BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id);
  58. motor.maxVelocity = value;
  59. }
  60. }
  61. /// <summary>
  62. /// The motor's maximum rotational force.
  63. /// </summary>
  64. public float Torque
  65. {
  66. get
  67. {
  68. return BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id).maxForce;
  69. }
  70. set
  71. {
  72. ref MotorReadOnlyStruct motor = ref BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id);
  73. motor.maxForce = value;
  74. }
  75. }
  76. /// <summary>
  77. /// The motor's direction.
  78. /// </summary>
  79. public bool Reverse
  80. {
  81. get
  82. {
  83. return BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id).reverse;
  84. }
  85. set
  86. {
  87. ref MotorReadOnlyStruct motor = ref BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id);
  88. motor.reverse = value;
  89. }
  90. }
  91. }
  92. }