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.

91 lines
2.7KB

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