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.

63 lines
2.1KB

  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. var groups = entitiesDB.FindGroups<MachineGraphConnectionsEntityStruct>();
  20. var connStructMapper =
  21. entitiesDB.QueryNativeMappedEntities<MachineGraphConnectionsEntityStruct>(groups);
  22. for (int i = connections.connections.Count<MachineConnectionStruct>() - 1; i >= 0; i--)
  23. _connectionFactory.RemoveConnection(connections, i, connStructMapper);
  24. _entityFunctions.RemoveEntity<BlockEntityDescriptor>(target);
  25. return true;
  26. }
  27. public void Ready()
  28. {
  29. }
  30. public EntitiesDB entitiesDB { get; set; }
  31. public void Dispose()
  32. {
  33. }
  34. public string Name { get; } = "GamecraftModdingAPIRemovalGameEngine";
  35. public bool isRemovable => false;
  36. [HarmonyPatch]
  37. public class FactoryObtainerPatch
  38. {
  39. static void Postfix(IEntityFunctions entityFunctions,
  40. MachineGraphConnectionEntityFactory machineGraphConnectionEntityFactory)
  41. {
  42. _entityFunctions = entityFunctions;
  43. _connectionFactory = machineGraphConnectionEntityFactory;
  44. Logging.MetaDebugLog("Requirements injected.");
  45. }
  46. static MethodBase TargetMethod(Harmony instance)
  47. {
  48. return AccessTools.TypeByName("RobocraftX.CR.MachineEditing.RemoveBlockEngine").GetConstructors()[0];
  49. }
  50. }
  51. }
  52. }