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.

BlockEventsEngine.cs 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using RobocraftX.Common;
  3. using Svelto.ECS;
  4. using GamecraftModdingAPI.Engines;
  5. using GamecraftModdingAPI.Utility;
  6. namespace GamecraftModdingAPI.Blocks
  7. {
  8. public class BlockEventsEngine : IReactionaryEngine<DBEntityStruct>
  9. {
  10. public event EventHandler<BlockPlacedRemovedEventArgs> Placed;
  11. public event EventHandler<BlockPlacedRemovedEventArgs> Removed;
  12. public BlockEventsEngine()
  13. {
  14. //Console.WriteLine("Creating BlockEventsEngine\n" + Environment.StackTrace);
  15. }
  16. public void Ready()
  17. {
  18. //Console.WriteLine("BlockEventsEngine registered");
  19. }
  20. public EntitiesDB entitiesDB { get; set; }
  21. public void Dispose()
  22. {
  23. }
  24. public string Name { get; } = "GamecraftModdingAPIBlockEventsEngine";
  25. public bool isRemovable { get; } = false;
  26. private bool shouldAddRemove;
  27. public void Add(ref DBEntityStruct entityComponent, EGID egid)
  28. {
  29. if (!(shouldAddRemove = !shouldAddRemove))
  30. return;
  31. ExceptionUtil.InvokeEvent(Placed, this,
  32. new BlockPlacedRemovedEventArgs {ID = egid, Type = (BlockIDs) entityComponent.DBID});
  33. }
  34. public void Remove(ref DBEntityStruct entityComponent, EGID egid)
  35. {
  36. if (!(shouldAddRemove = !shouldAddRemove))
  37. return;
  38. ExceptionUtil.InvokeEvent(Removed, this,
  39. new BlockPlacedRemovedEventArgs {ID = egid, Type = (BlockIDs) entityComponent.DBID});
  40. }
  41. }
  42. /*[HarmonyPatch]
  43. public static class TestPatch
  44. {
  45. public static void Postfix(FasterDictionary<RefWrapper<Type>, FasterList<IEngine>> engines,
  46. ExclusiveGroupStruct? previousGroup, in PlatformProfiler profiler, EGID egid)
  47. {
  48. if (!engines.TryGetValue(new RefWrapper<Type>(TypeSafeDictionary<TValue>._type), out result))
  49. return;
  50. }
  51. public static MethodBase TargetMethod()
  52. {
  53. return AccessTools.Method("Svelto.ECS.Internal.TypeSafeDictionary:AddEntityComponentToEngines");
  54. }
  55. }*/
  56. /*[HarmonyPatch]
  57. public static class TestPatch
  58. {
  59. public static void Postfix(EGID basePartEGID)
  60. {
  61. Console.WriteLine("Patched Add method: " + basePartEGID);
  62. }
  63. public static MethodBase TargetMethod()
  64. {
  65. return AccessTools.Method("RobocraftX.CR.MachineEditing.BuildBlockAdditionalPartEngine:Add");
  66. }
  67. }*/
  68. public struct BlockPlacedRemovedEventArgs
  69. {
  70. public EGID ID;
  71. public BlockIDs Type;
  72. }
  73. }