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.

BlockEngine.cs 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System.Collections.Generic;
  2. using RobocraftX.Blocks;
  3. using RobocraftX.Common;
  4. using Svelto.DataStructures;
  5. using Svelto.ECS;
  6. using GamecraftModdingAPI.Engines;
  7. namespace GamecraftModdingAPI.Blocks
  8. {
  9. public class BlockEngine : IApiEngine
  10. {
  11. public string Name { get; } = "GamecraftModdingAPIBlockGameEngine";
  12. public EntitiesDB entitiesDB { set; private get; }
  13. public bool isRemovable => false;
  14. public void Dispose()
  15. {
  16. }
  17. public void Ready()
  18. {
  19. }
  20. public Block[] GetConnectedBlocks(EGID blockID)
  21. {
  22. if (!BlockExists(blockID)) return new Block[0];
  23. Stack<uint> cubeStack = new Stack<uint>();
  24. FasterList<uint> cubesToProcess = new FasterList<uint>();
  25. ConnectedCubesUtility.TreeTraversal.GetConnectedCubes(entitiesDB, blockID.entityID, cubeStack, cubesToProcess, (in GridConnectionsEntityStruct g) => { return false; });
  26. var ret = new Block[cubesToProcess.count];
  27. for (int i = 0; i < cubesToProcess.count; i++)
  28. ret[i] = new Block(cubesToProcess[i]);
  29. return ret;
  30. }
  31. /// <summary>
  32. /// Get a struct of a block. Can be used to set properties.
  33. /// When only querying parameters, use the other overload for convenience.
  34. /// </summary>
  35. /// <param name="blockID"></param>
  36. /// <param name="def"></param>
  37. /// <typeparam name="T"></typeparam>
  38. /// <returns></returns>
  39. public ref T GetBlockInfo<T>(EGID blockID, ref T def) where T : struct, IEntityComponent
  40. {
  41. if (entitiesDB.Exists<T>(blockID))
  42. return ref entitiesDB.QueryEntity<T>(blockID);
  43. return ref def;
  44. }
  45. /// <summary>
  46. /// Get a struct of a block. Can only be used to retrieve information.
  47. /// Use the overload with a default parameter to get the struct by reference to set values.
  48. /// </summary>
  49. /// <param name="blockID">The block's EGID</param>
  50. /// <typeparam name="T">The struct's type to get</typeparam>
  51. /// <returns>A copy of the struct or null</returns>
  52. public T? GetBlockInfo<T>(EGID blockID) where T : struct, IEntityComponent
  53. {
  54. if (entitiesDB.Exists<T>(blockID))
  55. return entitiesDB.QueryEntity<T>(blockID);
  56. return null;
  57. }
  58. public bool BlockExists(EGID id)
  59. {
  60. return entitiesDB.Exists<DBEntityStruct>(id);
  61. }
  62. }
  63. }