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.

84 lines
2.5KB

  1. using System;
  2. using RobocraftX.Blocks;
  3. using Svelto.ECS;
  4. using Unity.Mathematics;
  5. using GamecraftModdingAPI.Utility;
  6. using RobocraftX.Common;
  7. namespace GamecraftModdingAPI.Blocks
  8. {
  9. public class Piston : Block
  10. {
  11. /// <summary>
  12. /// Places a new piston.
  13. /// Any valid piston type is accepted.
  14. /// This re-implements Block.PlaceNew(...)
  15. /// </summary>
  16. public static new Piston 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.ServoPiston || block == BlockIDs.StepperPiston || block == BlockIDs.PneumaticPiston))
  21. {
  22. throw new BlockTypeException($"Block is not a {typeof(Piston).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 Piston(id);
  29. }
  30. return null;
  31. }
  32. public Piston(EGID id) : base(id)
  33. {
  34. if (!BlockEngine.GetBlockInfoExists<PistonReadOnlyStruct>(this.Id))
  35. {
  36. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  37. }
  38. }
  39. public Piston(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_PISTON_BLOCK_GROUP))
  40. {
  41. if (!BlockEngine.GetBlockInfoExists<PistonReadOnlyStruct>(this.Id))
  42. {
  43. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  44. }
  45. }
  46. // custom piston properties
  47. /// <summary>
  48. /// The piston's max extension distance.
  49. /// </summary>
  50. public float MaximumExtension
  51. {
  52. get => BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(Id).maxDeviation;
  53. set
  54. {
  55. ref PistonReadOnlyStruct piston = ref BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(Id);
  56. piston.maxDeviation = value;
  57. }
  58. }
  59. /// <summary>
  60. /// The piston's max extension force.
  61. /// </summary>
  62. public float MaximumForce
  63. {
  64. get => BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(Id).maxForce;
  65. set
  66. {
  67. ref PistonReadOnlyStruct piston = ref BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(Id);
  68. piston.maxForce = value;
  69. }
  70. }
  71. }
  72. }