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.

55 lines
1.5KB

  1. using System;
  2. using RobocraftX.Common;
  3. using Svelto.ECS;
  4. using RobocraftX.Blocks;
  5. using TechbloxModdingAPI.Engines;
  6. using TechbloxModdingAPI.Utility;
  7. namespace TechbloxModdingAPI.Blocks
  8. {
  9. public class BlockEventsEngine : IReactionaryEngine<BlockTagEntityStruct>
  10. {
  11. public event EventHandler<BlockPlacedRemovedEventArgs> Placed;
  12. public event EventHandler<BlockPlacedRemovedEventArgs> Removed;
  13. public void Ready()
  14. {
  15. }
  16. public EntitiesDB entitiesDB { get; set; }
  17. public void Dispose()
  18. {
  19. }
  20. public string Name { get; } = "TechbloxModdingAPIBlockEventsEngine";
  21. public bool isRemovable { get; } = false;
  22. private bool shouldAddRemove;
  23. public void Add(ref BlockTagEntityStruct entityComponent, EGID egid)
  24. {
  25. if (!(shouldAddRemove = !shouldAddRemove))
  26. return;
  27. ExceptionUtil.InvokeEvent(Placed, this,
  28. new BlockPlacedRemovedEventArgs {ID = egid});
  29. }
  30. public void Remove(ref BlockTagEntityStruct entityComponent, EGID egid)
  31. {
  32. if (!(shouldAddRemove = !shouldAddRemove))
  33. return;
  34. ExceptionUtil.InvokeEvent(Removed, this,
  35. new BlockPlacedRemovedEventArgs {ID = egid});
  36. }
  37. }
  38. public struct BlockPlacedRemovedEventArgs
  39. {
  40. public EGID ID;
  41. public BlockIDs Type;
  42. private Block block;
  43. public Block Block => block ?? (block = new Block(ID));
  44. }
  45. }