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.

57 lines
2.1KB

  1. using System;
  2. using GamecraftModdingAPI.Engines;
  3. using GamecraftModdingAPI.Persistence;
  4. using GamecraftModdingAPI.Utility;
  5. using RobocraftX.Common;
  6. using Svelto.ECS;
  7. using Svelto.ECS.Experimental;
  8. using Svelto.ECS.Serialization;
  9. namespace GamecraftModdingAPI.Blocks
  10. {
  11. public class CustomBlockEngine : IFactoryEngine
  12. {
  13. public class CustomBlockEntityDescriptor : SerializableEntityDescriptor<
  14. CustomBlockEntityDescriptor._CustomBlockDescriptor>
  15. {
  16. [HashName("GamecraftModdingAPICustomBlockV0")]
  17. public class _CustomBlockDescriptor : IEntityDescriptor
  18. {
  19. public IComponentBuilder[] componentsToBuild { get; } =
  20. {
  21. new SerializableComponentBuilder<SerializationType, CustomBlock.DataStruct>(
  22. ((int) SerializationType.Network, new DefaultSerializer<CustomBlock.DataStruct>()),
  23. ((int) SerializationType.Storage, new DefaultSerializer<CustomBlock.DataStruct>()))
  24. };
  25. }
  26. }
  27. public void Ready()
  28. {
  29. SerializerManager.AddSerializer<CustomBlockEntityDescriptor>(new SimpleEntitySerializer<CustomBlockEntityDescriptor>(db =>
  30. {
  31. var (coll, c) = db.QueryEntities<CustomBlock.DataStruct>(ApiExclusiveGroups.customBlockGroup);
  32. var egids = new EGID[c];
  33. for (int i = 0; i < c; i++)
  34. egids[i] = new EGID(coll[i].ID, ApiExclusiveGroups.customBlockGroup);
  35. return egids;
  36. }));
  37. }
  38. public EntitiesDB entitiesDB { get; set; }
  39. public void Dispose()
  40. {
  41. }
  42. public void RegisterBlock(ushort id, string name)
  43. {
  44. Factory.BuildEntity<CustomBlockEntityDescriptor>(id, ApiExclusiveGroups.customBlockGroup)
  45. .Init(new CustomBlock.DataStruct {Name = new ECSString(name), ID = id});
  46. }
  47. public string Name { get; } = "GamecraftModdingAPICustomBlockEngine";
  48. public bool isRemovable { get; } = false;
  49. public IEntityFactory Factory { get; set; }
  50. }
  51. }