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 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 void Ready()
  13. {
  14. }
  15. public EntitiesDB entitiesDB { get; set; }
  16. public void Dispose()
  17. {
  18. }
  19. public string Name { get; } = "GamecraftModdingAPIBlockEventsEngine";
  20. public bool isRemovable { get; } = false;
  21. private bool shouldAddRemove;
  22. public void Add(ref DBEntityStruct entityComponent, EGID egid)
  23. {
  24. if (!(shouldAddRemove = !shouldAddRemove))
  25. return;
  26. ExceptionUtil.InvokeEvent(Placed, this,
  27. new BlockPlacedRemovedEventArgs {ID = egid, Type = (BlockIDs) entityComponent.DBID});
  28. }
  29. public void Remove(ref DBEntityStruct entityComponent, EGID egid)
  30. {
  31. if (!(shouldAddRemove = !shouldAddRemove))
  32. return;
  33. ExceptionUtil.InvokeEvent(Removed, this,
  34. new BlockPlacedRemovedEventArgs {ID = egid, Type = (BlockIDs) entityComponent.DBID});
  35. }
  36. }
  37. public struct BlockPlacedRemovedEventArgs
  38. {
  39. public EGID ID;
  40. public BlockIDs Type;
  41. private Block block;
  42. public Block Block => block ?? (block = new Block(ID));
  43. }
  44. }