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.

83 lines
2.5KB

  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. EGID id = PlacementEngine.PlaceBlock(block, color, darkness,
  26. position, uscale, scale, player, rotation);
  27. return new Piston(id);
  28. }
  29. return null;
  30. }
  31. public Piston(EGID id) : base(id)
  32. {
  33. if (!BlockEngine.GetBlockInfoExists<PistonReadOnlyStruct>(this.Id))
  34. {
  35. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  36. }
  37. }
  38. public Piston(uint 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. // custom piston properties
  46. /// <summary>
  47. /// The piston's max extension distance.
  48. /// </summary>
  49. public float MaximumExtension
  50. {
  51. get => BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(Id).maxDeviation;
  52. set
  53. {
  54. ref PistonReadOnlyStruct piston = ref BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(Id);
  55. piston.maxDeviation = value;
  56. }
  57. }
  58. /// <summary>
  59. /// The piston's max extension force.
  60. /// </summary>
  61. public float MaximumForce
  62. {
  63. get => BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(Id).maxForce;
  64. set
  65. {
  66. ref PistonReadOnlyStruct piston = ref BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(Id);
  67. piston.maxForce = value;
  68. }
  69. }
  70. }
  71. }