Merge branch 'release/3.4'

This commit is contained in:
Dylan K. Taylor 2018-10-20 15:26:17 +01:00
commit 831a35ec69
6 changed files with 47 additions and 34 deletions

View File

@ -1966,9 +1966,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
public function handleLevelSoundEvent(LevelSoundEventPacket $packet) : bool{ public function handleLevelSoundEvent(LevelSoundEventPacket $packet) : bool{
//TODO: add events so plugins can change this //TODO: add events so plugins can change this
if($this->chunk !== null){ $this->getLevel()->broadcastPacketToViewers($this, $packet);
$this->getLevel()->addChunkPacket($this->chunk->getX(), $this->chunk->getZ(), $packet);
}
return true; return true;
} }

View File

@ -1134,34 +1134,30 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
} }
protected function broadcastMovement(bool $teleport = false) : void{ protected function broadcastMovement(bool $teleport = false) : void{
if($this->chunk !== null){ $pk = new MoveEntityAbsolutePacket();
$pk = new MoveEntityAbsolutePacket(); $pk->entityRuntimeId = $this->id;
$pk->entityRuntimeId = $this->id; $pk->position = $this->getOffsetPosition($this);
$pk->position = $this->getOffsetPosition($this);
//this looks very odd but is correct as of 1.5.0.7 //this looks very odd but is correct as of 1.5.0.7
//for arrows this is actually x/y/z rotation //for arrows this is actually x/y/z rotation
//for mobs x and z are used for pitch and yaw, and y is used for headyaw //for mobs x and z are used for pitch and yaw, and y is used for headyaw
$pk->xRot = $this->pitch; $pk->xRot = $this->pitch;
$pk->yRot = $this->yaw; //TODO: head yaw $pk->yRot = $this->yaw; //TODO: head yaw
$pk->zRot = $this->yaw; $pk->zRot = $this->yaw;
if($teleport){ if($teleport){
$pk->flags |= MoveEntityAbsolutePacket::FLAG_TELEPORT; $pk->flags |= MoveEntityAbsolutePacket::FLAG_TELEPORT;
}
$this->level->addChunkPacket($this->chunk->getX(), $this->chunk->getZ(), $pk);
} }
$this->level->broadcastPacketToViewers($this, $pk);
} }
protected function broadcastMotion() : void{ protected function broadcastMotion() : void{
if($this->chunk !== null){ $pk = new SetEntityMotionPacket();
$pk = new SetEntityMotionPacket(); $pk->entityRuntimeId = $this->id;
$pk->entityRuntimeId = $this->id; $pk->motion = $this->getMotion();
$pk->motion = $this->getMotion();
$this->level->addChunkPacket($this->chunk->getX(), $this->chunk->getZ(), $pk); $this->level->broadcastPacketToViewers($this, $pk);
}
} }
protected function applyDragBeforeGravity() : bool{ protected function applyDragBeforeGravity() : bool{

View File

@ -87,6 +87,6 @@ class ChestInventory extends ContainerInventory{
$pk->z = (int) $holder->z; $pk->z = (int) $holder->z;
$pk->eventType = 1; //it's always 1 for a chest $pk->eventType = 1; //it's always 1 for a chest
$pk->eventData = $isOpen ? 1 : 0; $pk->eventData = $isOpen ? 1 : 0;
$holder->getLevel()->addChunkPacket($holder->getFloorX() >> 4, $holder->getFloorZ() >> 4, $pk); $holder->getLevel()->broadcastPacketToViewers($holder, $pk);
} }
} }

View File

@ -254,7 +254,7 @@ class Explosion{
$pk->position = $this->source->asVector3(); $pk->position = $this->source->asVector3();
$pk->radius = $this->size; $pk->radius = $this->size;
$pk->records = $send; $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->addParticle(new HugeExplodeSeedParticle($source));
$this->level->broadcastLevelSoundEvent($source, LevelSoundEventPacket::SOUND_EXPLODE); $this->level->broadcastLevelSoundEvent($source, LevelSoundEventPacket::SOUND_EXPLODE);

View File

@ -455,7 +455,7 @@ class Level implements ChunkManager, Metadatable{
if($players === null){ if($players === null){
foreach($pk as $e){ foreach($pk as $e){
$this->addChunkPacket($sound->getFloorX() >> 4, $sound->getFloorZ() >> 4, $e); $this->broadcastPacketToViewers($sound, $e);
} }
}else{ }else{
$this->server->broadcastPackets($players, $pk); $this->server->broadcastPackets($players, $pk);
@ -470,7 +470,7 @@ class Level implements ChunkManager, Metadatable{
if($players === null){ if($players === null){
foreach($pk as $e){ foreach($pk as $e){
$this->addChunkPacket($particle->getFloorX() >> 4, $particle->getFloorZ() >> 4, $e); $this->broadcastPacketToViewers($particle, $e);
} }
}else{ }else{
$this->server->broadcastPackets($players, $pk); $this->server->broadcastPackets($players, $pk);
@ -490,10 +490,10 @@ class Level implements ChunkManager, Metadatable{
$pk->data = $data; $pk->data = $data;
if($pos !== null){ if($pos !== null){
$pk->position = $pos->asVector3(); $pk->position = $pos->asVector3();
$this->addChunkPacket($pos->getFloorX() >> 4, $pos->getFloorZ() >> 4, $pk); $this->broadcastPacketToViewers($pos, $pk);
}else{ }else{
$pk->position = null; $pk->position = null;
$this->addGlobalPacket($pk); $this->broadcastGlobalPacket($pk);
} }
} }
@ -515,7 +515,7 @@ class Level implements ChunkManager, Metadatable{
$pk->isBabyMob = $isBabyMob; $pk->isBabyMob = $isBabyMob;
$pk->disableRelativeVolume = $disableRelativeVolume; $pk->disableRelativeVolume = $disableRelativeVolume;
$pk->position = $pos->asVector3(); $pk->position = $pos->asVector3();
$this->addChunkPacket($pos->getFloorX() >> 4, $pos->getFloorZ() >> 4, $pk); $this->broadcastPacketToViewers($pos, $pk);
} }
public function getAutoSave() : bool{ public function getAutoSave() : bool{
@ -613,7 +613,27 @@ class Level implements ChunkManager, Metadatable{
} }
/** /**
* Queues a DataPacket to be sent to everyone in the Level at the end of the current tick. * 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);
}
/**
* Broadcasts a packet to every player in the level.
*
* @param DataPacket $packet
*/
public function broadcastGlobalPacket(DataPacket $packet) : void{
$this->globalPackets[] = $packet;
}
/**
* @deprecated
* @see Level::broadcastGlobalPacket()
* *
* @param DataPacket $packet * @param DataPacket $packet
*/ */

View File

@ -67,8 +67,7 @@ abstract class Spawnable extends Tile{
return; return;
} }
$pk = $this->createSpawnPacket(); $this->level->broadcastPacketToViewers($this, $this->createSpawnPacket());
$this->level->addChunkPacket($this->getFloorX() >> 4, $this->getFloorZ() >> 4, $pk);
} }
/** /**