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.

Piston.cs 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 Piston : Block
  9. {
  10. /// <summary>
  11. /// Places a new piston.
  12. /// Any valid piston type is accepted.
  13. /// This re-implements Block.PlaceNew(...)
  14. /// </summary>
  15. public static new Piston 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.ServoPiston || block == BlockIDs.StepperPiston || block == BlockIDs.PneumaticPiston))
  20. {
  21. throw new BlockTypeException($"Block is not a {typeof(Piston).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 Piston(id);
  30. }
  31. catch (Exception e)
  32. {
  33. Logging.MetaDebugLog(e);
  34. }
  35. }
  36. return null;
  37. }
  38. public Piston(EGID id) : base(id)
  39. {
  40. if (!BlockEngine.GetBlockInfoExists<PistonReadOnlyStruct>(this.Id))
  41. {
  42. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  43. }
  44. }
  45. public Piston(uint id) : base(id)
  46. {
  47. if (!BlockEngine.GetBlockInfoExists<PistonReadOnlyStruct>(this.Id))
  48. {
  49. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  50. }
  51. }
  52. // custom piston properties
  53. /// <summary>
  54. /// The piston's max extension distance.
  55. /// </summary>
  56. public float MaximumExtension
  57. {
  58. get => BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(Id).maxDeviation;
  59. set
  60. {
  61. ref PistonReadOnlyStruct piston = ref BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(Id);
  62. piston.maxDeviation = value;
  63. }
  64. }
  65. /// <summary>
  66. /// The piston's max extension force.
  67. /// </summary>
  68. public float MaximumForce
  69. {
  70. get => BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(Id).maxForce;
  71. set
  72. {
  73. ref PistonReadOnlyStruct piston = ref BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(Id);
  74. piston.maxForce = value;
  75. }
  76. }
  77. }
  78. }