|
- using RobocraftX.Blocks.Ghost;
- using RobocraftX.Character.Camera;
- using RobocraftX.Character.Factories;
- using Svelto.ECS;
-
- namespace GamecraftModdingAPI.Blocks
- {
- public class BlockUtility
- {
- /// <summary>
- /// Returns the block the player is currently looking at.
- /// </summary>
- /// <param name="playerId">The player's ID</param>
- /// <param name="entitiesDB">The entities DB</param>
- /// <param name="maxDistance">The maximum distance from the player (default is the player's building reach)</param>
- /// <returns>The block's EGID or null if not found</returns>
- public static EGID? GetBlockLookedAt(uint playerId, EntitiesDB entitiesDB, float maxDistance = -1f)
- {
- if (!entitiesDB.TryQueryMappedEntities<CharacterCameraRayCastEntityStruct>(
- CameraExclusiveGroups.CameraGroup, out var mapper))
- return null;
- mapper.TryGetEntity(playerId, out CharacterCameraRayCastEntityStruct rayCast);
- float distance = maxDistance < 0
- ? GhostBlockUtils.GetBuildInteractionDistance(entitiesDB, rayCast)
- : maxDistance;
- if (rayCast.hit && rayCast.distance <= distance)
- return rayCast.hitEgid;
- return null;
- }
- }
- }
|