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 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using RobocraftX.Common;
  3. using Svelto.ECS;
  4. using GamecraftModdingAPI.Engines;
  5. using GamecraftModdingAPI.Utility;
  6. using RobocraftX.Blocks;
  7. namespace GamecraftModdingAPI.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; } = "GamecraftModdingAPIBlockEventsEngine";
  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. }