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.

RemovalEngine.cs 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. /*CommandManager.AddCommand(new SimpleCustomCommandEngine(() =>
  27. {
  28. var block = BlockUtility.GetBlockLookedAt(LocalPlayerIDUtility.GetLocalPlayerID(entitiesDB), entitiesDB);
  29. if (block.HasValue)
  30. {
  31. RemoveBlock(block.Value);
  32. Log.Output("Removed block.");
  33. }
  34. else
  35. Log.Output("No block found where you're looking at.");
  36. }, "removeCube", "Removes the cube you're looking at."));*/
  37. }
  38. public EntitiesDB entitiesDB { get; set; }
  39. public void Dispose()
  40. {
  41. }
  42. public string Name { get; } = "GamecraftModdingAPIRemovalGameEngine";
  43. public bool isRemovable => false;
  44. [HarmonyPatch]
  45. public class FactoryObtainerPatch
  46. {
  47. static void Postfix(IEntityFunctions entityFunctions,
  48. MachineGraphConnectionEntityFactory machineGraphConnectionEntityFactory)
  49. {
  50. _entityFunctions = entityFunctions;
  51. _connectionFactory = machineGraphConnectionEntityFactory;
  52. Logging.MetaDebugLog("Requirements injected.");
  53. }
  54. static MethodBase TargetMethod(Harmony instance)
  55. {
  56. return AccessTools.TypeByName("RobocraftX.CR.MachineEditing.RemoveBlockEngine").GetConstructors()[0];
  57. }
  58. }
  59. }
  60. }