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.

31 lines
1.3KB

  1. using RobocraftX.Blocks.Ghost;
  2. using RobocraftX.Character.Camera;
  3. using RobocraftX.Character.Factories;
  4. using Svelto.ECS;
  5. namespace GamecraftModdingAPI.Blocks
  6. {
  7. public class BlockUtility
  8. {
  9. /// <summary>
  10. /// Returns the block the player is currently looking at.
  11. /// </summary>
  12. /// <param name="playerId">The player's ID</param>
  13. /// <param name="entitiesDB">The entities DB</param>
  14. /// <param name="maxDistance">The maximum distance from the player (default is the player's building reach)</param>
  15. /// <returns>The block's EGID or null if not found</returns>
  16. public static EGID? GetBlockLookedAt(uint playerId, EntitiesDB entitiesDB, float maxDistance = -1f)
  17. {
  18. if (!entitiesDB.TryQueryMappedEntities<CharacterCameraRayCastEntityStruct>(
  19. CameraExclusiveGroups.CameraGroup, out var mapper))
  20. return null;
  21. mapper.TryGetEntity(playerId, out CharacterCameraRayCastEntityStruct rayCast);
  22. float distance = maxDistance < 0
  23. ? GhostBlockUtils.GetBuildInteractionDistance(entitiesDB, rayCast)
  24. : maxDistance;
  25. if (rayCast.hit && rayCast.distance <= distance)
  26. return rayCast.hitEgid;
  27. return null;
  28. }
  29. }
  30. }