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.

ConsoleBlock.cs 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using RobocraftX.Blocks;
  3. using Svelto.ECS;
  4. using Unity.Mathematics;
  5. using GamecraftModdingAPI;
  6. using GamecraftModdingAPI.Utility;
  7. namespace GamecraftModdingAPI.Blocks
  8. {
  9. public class ConsoleBlock : Block
  10. {
  11. public static ConsoleBlock PlaceNew(float3 position,
  12. float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
  13. int uscale = 1, float3 scale = default, Player player = null)
  14. {
  15. if (PlacementEngine.IsInGame && GameState.IsBuildMode())
  16. {
  17. try
  18. {
  19. EGID id = PlacementEngine.PlaceBlock(BlockIDs.ConsoleBlock, color, darkness,
  20. position, uscale, scale, player, rotation);
  21. Sync();
  22. return new ConsoleBlock(id);
  23. }
  24. catch (Exception e)
  25. {
  26. Logging.MetaDebugLog(e);
  27. }
  28. }
  29. return null;
  30. }
  31. public ConsoleBlock(EGID id): base(id)
  32. {
  33. if (!BlockEngine.GetBlockInfoExists<ConsoleBlockEntityStruct>(this.Id))
  34. {
  35. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  36. }
  37. }
  38. public ConsoleBlock(uint id): base(id)
  39. {
  40. if (!BlockEngine.GetBlockInfoExists<ConsoleBlockEntityStruct>(this.Id))
  41. {
  42. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  43. }
  44. }
  45. // custom console block properties
  46. public string Command
  47. {
  48. get
  49. {
  50. return BlockEngine.GetBlockInfo<ConsoleBlockEntityStruct>(Id).commandName;
  51. }
  52. set
  53. {
  54. BlockEngine.GetBlockInfo<ConsoleBlockEntityStruct>(Id).commandName.Set(value);
  55. }
  56. }
  57. public string Arg1
  58. {
  59. get => BlockEngine.GetBlockInfo<ConsoleBlockEntityStruct>(Id).arg1;
  60. set
  61. {
  62. BlockEngine.GetBlockInfo<ConsoleBlockEntityStruct>(Id).arg1.Set(value);
  63. }
  64. }
  65. public string Arg2
  66. {
  67. get => BlockEngine.GetBlockInfo<ConsoleBlockEntityStruct>(Id).arg2;
  68. set
  69. {
  70. BlockEngine.GetBlockInfo<ConsoleBlockEntityStruct>(Id).arg2.Set(value);
  71. }
  72. }
  73. public string Arg3
  74. {
  75. get => BlockEngine.GetBlockInfo<ConsoleBlockEntityStruct>(Id).arg3;
  76. set
  77. {
  78. BlockEngine.GetBlockInfo<ConsoleBlockEntityStruct>(Id).arg3.Set(value);
  79. }
  80. }
  81. }
  82. }