Tools for building games mainly focused on changing block properties. And noclip.
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.

95 lines
3.4KB

  1. using System;
  2. using Gamecraft.Wires;
  3. using TechbloxModdingAPI;
  4. using TechbloxModdingAPI.Commands;
  5. using TechbloxModdingAPI.Utility;
  6. namespace BuildingTools
  7. {
  8. public class CommandUtils
  9. {
  10. private readonly BlockSelections _blockSelections;
  11. public CommandUtils(BlockSelections blockSelections)
  12. {
  13. _blockSelections = blockSelections;
  14. }
  15. private void RegisterBlockCommandInternal(string name, string desc, Action<string, Block[], Block> action)
  16. {
  17. CommandBuilder.Builder(name, desc).Action<string>(a1 =>
  18. {
  19. action(a1, _blockSelections.blocks, _blockSelections.refBlock);
  20. }).Build();
  21. }
  22. public void RegisterBlockCommand(string name, string desc, Action<float, float, float, Block[], Block> action)
  23. {
  24. RegisterBlockCommandInternal(name, desc, (args, bs, b) =>
  25. {
  26. var argsa = args.Split(' ');
  27. if (argsa.Length < 3)
  28. {
  29. Logging.CommandLogError("Too few arguments. Needed arguments are: <x> <y> <z> and [id] is optional.");
  30. return;
  31. }
  32. if (!float.TryParse(argsa[0], out float x) || !float.TryParse(argsa[1], out float y) ||
  33. !float.TryParse(argsa[2], out float z))
  34. {
  35. Logging.CommandLogError("Could not parse arguments as floats.");
  36. return;
  37. }
  38. if (argsa.Length > 3)
  39. {
  40. if (argsa[3].Length == 0)
  41. {
  42. Logging.CommandLogError("Missing object ID.");
  43. return;
  44. }
  45. var blocks = _blockSelections.SelectBlocks(argsa[3][0]);
  46. if (_blockSelections.CheckNoBlocks(blocks)) return;
  47. action(x, y, z, blocks, blocks[0]);
  48. }
  49. else if (!_blockSelections.CheckNoBlocks(bs))
  50. action(x, y, z, bs, b);
  51. });
  52. }
  53. public void RegisterBlockCommand(string name, string desc, Action<string, byte, Block[], Block> action)
  54. {
  55. RegisterBlockCommandInternal(name, desc, (args, bs, b) =>
  56. {
  57. var argsa = args.Split(' ');
  58. if (argsa.Length < 2)
  59. {
  60. Logging.CommandLogError("Too few arguments. Needed arguments are: <color> <darkness> and [id] is optional.");
  61. return;
  62. }
  63. if (!byte.TryParse(argsa[1], out byte darkness))
  64. {
  65. Logging.CommandLogError("Could not parse color darkness.");
  66. return;
  67. }
  68. if (argsa.Length > 2)
  69. {
  70. if (argsa[2].Length == 0)
  71. {
  72. Logging.CommandLogError("Missing channel.");
  73. return;
  74. }
  75. var blocks = _blockSelections.SelectBlocks(argsa[2][0]);
  76. if (_blockSelections.CheckNoBlocks(blocks)) return;
  77. action(argsa[0], darkness, blocks, blocks[0]);
  78. }
  79. else if(!_blockSelections.CheckNoBlocks(bs))
  80. action(argsa[0], darkness, bs, b);
  81. });
  82. }
  83. }
  84. }