Level: Allow broadcastLevelEvent() to accept a null position to broadcast to everyone in the Level

This commit is contained in:
Dylan K. Taylor 2018-01-17 17:52:01 +00:00
parent f0696f77ef
commit ecb3f9aeac

View File

@ -503,16 +503,21 @@ class Level implements ChunkManager, Metadatable{
/** /**
* Broadcasts a LevelEvent to players in the area. This could be sound, particles, weather changes, etc. * Broadcasts a LevelEvent to players in the area. This could be sound, particles, weather changes, etc.
* *
* @param Vector3 $pos * @param Vector3|null $pos If null, broadcasts to every player in the Level
* @param int $evid * @param int $evid
* @param int $data * @param int $data
*/ */
public function broadcastLevelEvent(Vector3 $pos, int $evid, int $data = 0){ public function broadcastLevelEvent(?Vector3 $pos, int $evid, int $data = 0){
$pk = new LevelEventPacket(); $pk = new LevelEventPacket();
$pk->evid = $evid; $pk->evid = $evid;
$pk->data = $data; $pk->data = $data;
$pk->position = $pos->asVector3(); if($pos !== null){
$this->addChunkPacket($pos->x >> 4, $pos->z >> 4, $pk); $pk->position = $pos->asVector3();
$this->addChunkPacket($pos->x >> 4, $pos->z >> 4, $pk);
}else{
$pk->position = null;
$this->addGlobalPacket($pk);
}
} }
/** /**