Level: Add API method getViewersForPosition()

This returns all players who have the given position within their view radius.
This commit is contained in:
Dylan K. Taylor 2018-10-20 16:25:56 +01:00
parent 3028832cd3
commit 43426a4c5c

View File

@ -595,6 +595,16 @@ class Level implements ChunkManager, Metadatable{
return $this->chunkLoaders[Level::chunkHash($chunkX, $chunkZ)] ?? [];
}
/**
* Returns an array of players who have the target position within their view distance.
* @param Vector3 $pos
*
* @return Player[]
*/
public function getViewersForPosition(Vector3 $pos) : array{
return $this->getChunkPlayers($pos->getFloorX() >> 4, $pos->getFloorZ() >> 4);
}
/**
* Queues a DataPacket to be sent to all players using the chunk at the specified X/Z coordinates at the end of the
* current tick.