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.5KB

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