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.

60 lines
1.8KB

  1. using System.Reflection;
  2. using HarmonyLib;
  3. using RobocraftX.Blocks;
  4. using RobocraftX.Common;
  5. using Svelto.ECS;
  6. using GamecraftModdingAPI.Utility;
  7. using GamecraftModdingAPI.Engines;
  8. namespace GamecraftModdingAPI.Blocks
  9. {
  10. public class RemovalEngine : IApiEngine
  11. {
  12. private static IEntityFunctions _entityFunctions;
  13. private static MachineGraphConnectionEntityFactory _connectionFactory;
  14. public bool RemoveBlock(EGID target)
  15. {
  16. if (!entitiesDB.Exists<MachineGraphConnectionsEntityStruct>(target))
  17. return false;
  18. var connections = entitiesDB.QueryEntity<MachineGraphConnectionsEntityStruct>(target);
  19. for (int i = connections.connections.Length - 1; i >= 0; i--)
  20. _connectionFactory.RemoveConnection(connections, i, entitiesDB);
  21. _entityFunctions.RemoveEntity<BlockEntityDescriptor>(target);
  22. return true;
  23. }
  24. public void Ready()
  25. {
  26. }
  27. public EntitiesDB entitiesDB { get; set; }
  28. public void Dispose()
  29. {
  30. }
  31. public string Name { get; } = "GamecraftModdingAPIRemovalGameEngine";
  32. public bool isRemovable => false;
  33. [HarmonyPatch]
  34. public class FactoryObtainerPatch
  35. {
  36. static void Postfix(IEntityFunctions entityFunctions,
  37. MachineGraphConnectionEntityFactory machineGraphConnectionEntityFactory)
  38. {
  39. _entityFunctions = entityFunctions;
  40. _connectionFactory = machineGraphConnectionEntityFactory;
  41. Logging.MetaDebugLog("Requirements injected.");
  42. }
  43. static MethodBase TargetMethod(Harmony instance)
  44. {
  45. return AccessTools.TypeByName("RobocraftX.CR.MachineEditing.RemoveBlockEngine").GetConstructors()[0];
  46. }
  47. }
  48. }
  49. }