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.

Motor.cs 3.1KB

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