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.

MovementEngine.cs 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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(EGID blockID, float3 vector)
  30. {
  31. ref PositionEntityStruct posStruct = ref this.entitiesDB.QueryEntity<PositionEntityStruct>(blockID);
  32. ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntity<GridRotationStruct>(blockID);
  33. ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntity<LocalTransformEntityStruct>(blockID);
  34. ref UECSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntity<UECSPhysicsEntityStruct>(blockID);
  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).isProcessed = false;
  47. return posStruct.position;
  48. }
  49. public float3 GetPosition(EGID blockID)
  50. {
  51. ref PositionEntityStruct posStruct = ref this.entitiesDB.QueryEntity<PositionEntityStruct>(blockID);
  52. return posStruct.position;
  53. }
  54. }
  55. }