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.0KB

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