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.

52 lines
1.4KB

  1. using System;
  2. using RobocraftX.Blocks;
  3. using Svelto.ECS;
  4. using TechbloxModdingAPI.Engines;
  5. using TechbloxModdingAPI.Utility;
  6. namespace TechbloxModdingAPI.Blocks.Engines
  7. {
  8. public class BlockEventsEngine : IReactionaryEngine<BlockTagEntityStruct>
  9. {
  10. public WrappedHandler<BlockPlacedRemovedEventArgs> Placed;
  11. public WrappedHandler<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; } = "TechbloxModdingAPIBlockEventsEngine";
  20. public bool isRemovable { get; } = false;
  21. private bool shouldAddRemove;
  22. public void Add(ref BlockTagEntityStruct entityComponent, EGID egid)
  23. {
  24. if (!(shouldAddRemove = !shouldAddRemove))
  25. return;
  26. Placed.Invoke(this, new BlockPlacedRemovedEventArgs {ID = egid});
  27. }
  28. public void Remove(ref BlockTagEntityStruct entityComponent, EGID egid)
  29. {
  30. if (!(shouldAddRemove = !shouldAddRemove))
  31. return;
  32. Removed.Invoke(this, new BlockPlacedRemovedEventArgs {ID = egid});
  33. }
  34. }
  35. public struct BlockPlacedRemovedEventArgs
  36. {
  37. public EGID ID;
  38. private Block block;
  39. public Block Block => block ??= Block.New(ID);
  40. }
  41. }