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.

66 lines
2.4KB

  1. using RobocraftX.Common;
  2. using RobocraftX.UECS;
  3. using Svelto.ECS;
  4. using Svelto.ECS.EntityStructs;
  5. using Unity.Transforms;
  6. using Unity.Mathematics;
  7. using GamecraftModdingAPI.Utility;
  8. using GamecraftModdingAPI.Engines;
  9. namespace GamecraftModdingAPI.Blocks
  10. {
  11. /// <summary>
  12. /// Engine which executes block movement actions
  13. /// </summary>
  14. public class MovementEngine : IApiEngine
  15. {
  16. public string Name { get; } = "GamecraftModdingAPIMovementGameEngine";
  17. public EntitiesDB entitiesDB { set; private get; }
  18. public bool isRemovable => false;
  19. public bool IsInGame = false;
  20. public void Dispose()
  21. {
  22. IsInGame = false;
  23. }
  24. public void Ready()
  25. {
  26. IsInGame = true;
  27. }
  28. // implementations for Movement static class
  29. public float3 MoveBlock(uint blockID, float3 vector)
  30. {
  31. ref PositionEntityStruct posStruct = ref this.entitiesDB.QueryEntity<PositionEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
  32. ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntity<GridRotationStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
  33. ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntity<LocalTransformEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
  34. ref UECSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntity<UECSPhysicsEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
  35. // main (persistent) position
  36. posStruct.position = vector;
  37. // placement grid position
  38. gridStruct.position = vector;
  39. // rendered position
  40. transStruct.position = vector;
  41. // collision position
  42. FullGameFields._physicsWorld.EntityManager.SetComponentData(phyStruct.uecsEntity, new Translation
  43. {
  44. Value = posStruct.position
  45. });
  46. entitiesDB.QueryEntity<GridConnectionsEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP).isProcessed = false;
  47. return posStruct.position;
  48. }
  49. public float3 GetPosition(uint blockID)
  50. {
  51. ref PositionEntityStruct posStruct = ref this.entitiesDB.QueryEntity<PositionEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
  52. return posStruct.position;
  53. }
  54. }
  55. }