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.

77 lines
2.5KB

  1. using System.Reflection;
  2. using HarmonyLib;
  3. using RobocraftX.Blocks;
  4. using RobocraftX.Blocks.Ghost;
  5. using RobocraftX.Character.Camera;
  6. using RobocraftX.Character.Factories;
  7. using RobocraftX.Common;
  8. using RobocraftX.Players;
  9. using Svelto.ECS;
  10. using uREPL;
  11. using GamecraftModdingAPI.Commands;
  12. using GamecraftModdingAPI.Utility;
  13. using GamecraftModdingAPI.Engines;
  14. namespace GamecraftModdingAPI.Blocks
  15. {
  16. public class RemovalEngine : IApiEngine
  17. {
  18. private static IEntityFunctions _entityFunctions;
  19. private static MachineGraphConnectionEntityFactory _connectionFactory;
  20. public bool RemoveBlock(EGID target)
  21. {
  22. if (!entitiesDB.Exists<MachineGraphConnectionsEntityStruct>(target))
  23. return false;
  24. var connections = entitiesDB.QueryEntity<MachineGraphConnectionsEntityStruct>(target);
  25. for (int i = connections.connections.Length - 1; i >= 0; i--)
  26. _connectionFactory.RemoveConnection(connections, i, entitiesDB);
  27. _entityFunctions.RemoveEntity<BlockEntityDescriptor>(target);
  28. return true;
  29. }
  30. public void Ready()
  31. {
  32. /*CommandManager.AddCommand(new SimpleCustomCommandEngine(() =>
  33. {
  34. var block = BlockUtility.GetBlockLookedAt(LocalPlayerIDUtility.GetLocalPlayerID(entitiesDB), entitiesDB);
  35. if (block.HasValue)
  36. {
  37. RemoveBlock(block.Value);
  38. Log.Output("Removed block.");
  39. }
  40. else
  41. Log.Output("No block found where you're looking at.");
  42. }, "removeCube", "Removes the cube you're looking at."));*/
  43. }
  44. public EntitiesDB entitiesDB { get; set; }
  45. public void Dispose()
  46. {
  47. }
  48. public string Name { get; } = "GamecraftModdingAPIRemovalGameEngine";
  49. public bool isRemovable => false;
  50. [HarmonyPatch]
  51. public class FactoryObtainerPatch
  52. {
  53. static void Postfix(IEntityFunctions entityFunctions,
  54. MachineGraphConnectionEntityFactory machineGraphConnectionEntityFactory)
  55. {
  56. _entityFunctions = entityFunctions;
  57. _connectionFactory = machineGraphConnectionEntityFactory;
  58. Logging.MetaDebugLog("Requirements injected.");
  59. }
  60. static MethodBase TargetMethod(Harmony instance)
  61. {
  62. return AccessTools.TypeByName("RobocraftX.CR.MachineEditing.RemoveBlockEngine").GetConstructors()[0];
  63. }
  64. }
  65. }
  66. }