Level: Added API method broadcastPacketToViewers()

This supersedes addChunkPacket() in most cases, and has a more clear name. It broadcasts the given packet to every player who has the target position within their chunk load radius.
This commit is contained in:
Dylan K. Taylor
2018-10-20 15:14:41 +01:00
parent 7c44eea625
commit d563b9e31b
6 changed files with 35 additions and 32 deletions

View File

@ -253,7 +253,7 @@ class Explosion{
$pk->position = $this->source->asVector3();
$pk->radius = $this->size;
$pk->records = $send;
$this->level->addChunkPacket($source->getFloorX() >> 4, $source->getFloorZ() >> 4, $pk);
$this->level->broadcastPacketToViewers($source, $pk);
$this->level->addParticle(new HugeExplodeSeedParticle($source));
$this->level->broadcastLevelSoundEvent($source, LevelSoundEventPacket::SOUND_EXPLODE);

View File

@ -452,7 +452,7 @@ class Level implements ChunkManager, Metadatable{
if($players === null){
foreach($pk as $e){
$this->addChunkPacket($sound->getFloorX() >> 4, $sound->getFloorZ() >> 4, $e);
$this->broadcastPacketToViewers($sound, $e);
}
}else{
$this->server->batchPackets($players, $pk, false);
@ -467,7 +467,7 @@ class Level implements ChunkManager, Metadatable{
if($players === null){
foreach($pk as $e){
$this->addChunkPacket($particle->getFloorX() >> 4, $particle->getFloorZ() >> 4, $e);
$this->broadcastPacketToViewers($particle, $e);
}
}else{
$this->server->batchPackets($players, $pk, false);
@ -487,7 +487,7 @@ class Level implements ChunkManager, Metadatable{
$pk->data = $data;
if($pos !== null){
$pk->position = $pos->asVector3();
$this->addChunkPacket($pos->getFloorX() >> 4, $pos->getFloorZ() >> 4, $pk);
$this->broadcastPacketToViewers($pos, $pk);
}else{
$pk->position = null;
$this->addGlobalPacket($pk);
@ -512,7 +512,7 @@ class Level implements ChunkManager, Metadatable{
$pk->isBabyMob = $isBabyMob;
$pk->disableRelativeVolume = $disableRelativeVolume;
$pk->position = $pos->asVector3();
$this->addChunkPacket($pos->getFloorX() >> 4, $pos->getFloorZ() >> 4, $pk);
$this->broadcastPacketToViewers($pos, $pk);
}
public function getAutoSave() : bool{
@ -611,6 +611,16 @@ class Level implements ChunkManager, Metadatable{
}
}
/**
* Broadcasts a packet to every player who has the target position within their view distance.
*
* @param Vector3 $pos
* @param DataPacket $packet
*/
public function broadcastPacketToViewers(Vector3 $pos, DataPacket $packet) : void{
$this->addChunkPacket($pos->getFloorX() >> 4, $pos->getFloorZ() >> 4, $packet);
}
/**
* Queues a DataPacket to be sent to everyone in the Level at the end of the current tick.
*