mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-06 11:57:10 +00:00
Use NetworkBroadcastUtils for broadcasting packets
this eradicates all but 4 usages of Server in Entity, which is extremely cool.
This commit is contained in:
parent
a31e3331fd
commit
337a254768
@ -1351,6 +1351,7 @@ class Server{
|
||||
/**
|
||||
* @param Player[] $players
|
||||
* @param ClientboundPacket[] $packets
|
||||
* @deprecated
|
||||
*/
|
||||
public function broadcastPackets(array $players, array $packets) : bool{
|
||||
return NetworkBroadcastUtils::broadcastPackets($players, $packets);
|
||||
|
@ -787,7 +787,7 @@ abstract class Entity{
|
||||
$this->spawnTo($player);
|
||||
}
|
||||
}else{
|
||||
$this->server->broadcastPackets($this->hasSpawned, [MoveActorAbsolutePacket::create(
|
||||
NetworkBroadcastUtils::broadcastPackets($this->hasSpawned, [MoveActorAbsolutePacket::create(
|
||||
$this->id,
|
||||
$this->getOffsetPosition($this->location),
|
||||
$this->location->pitch,
|
||||
@ -802,7 +802,7 @@ abstract class Entity{
|
||||
}
|
||||
|
||||
protected function broadcastMotion() : void{
|
||||
$this->server->broadcastPackets($this->hasSpawned, [SetActorMotionPacket::create($this->id, $this->getMotion())]);
|
||||
NetworkBroadcastUtils::broadcastPackets($this->hasSpawned, [SetActorMotionPacket::create($this->id, $this->getMotion())]);
|
||||
}
|
||||
|
||||
public function getGravity() : float{
|
||||
@ -1682,7 +1682,7 @@ abstract class Entity{
|
||||
* @param Player[]|null $targets
|
||||
*/
|
||||
public function broadcastAnimation(Animation $animation, ?array $targets = null) : void{
|
||||
$this->server->broadcastPackets($targets ?? $this->getViewers(), $animation->encode());
|
||||
NetworkBroadcastUtils::broadcastPackets($targets ?? $this->getViewers(), $animation->encode());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1691,7 +1691,7 @@ abstract class Entity{
|
||||
*/
|
||||
public function broadcastSound(Sound $sound, ?array $targets = null) : void{
|
||||
if(!$this->silent){
|
||||
$this->server->broadcastPackets($targets ?? $this->getViewers(), $sound->encode($this->location));
|
||||
NetworkBroadcastUtils::broadcastPackets($targets ?? $this->getViewers(), $sound->encode($this->location));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -176,7 +176,7 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
|
||||
* @param Player[]|null $targets
|
||||
*/
|
||||
public function sendSkin(?array $targets = null) : void{
|
||||
$this->server->broadcastPackets($targets ?? $this->hasSpawned, [
|
||||
NetworkBroadcastUtils::broadcastPackets($targets ?? $this->hasSpawned, [
|
||||
PlayerSkinPacket::create($this->getUniqueId(), "", "", SkinAdapterSingleton::get()->toSkinData($this->skin))
|
||||
]);
|
||||
}
|
||||
|
@ -65,6 +65,7 @@ use pocketmine\math\Vector3;
|
||||
use pocketmine\nbt\tag\IntTag;
|
||||
use pocketmine\nbt\tag\StringTag;
|
||||
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
|
||||
use pocketmine\network\mcpe\NetworkBroadcastUtils;
|
||||
use pocketmine\network\mcpe\protocol\BlockActorDataPacket;
|
||||
use pocketmine\network\mcpe\protocol\ClientboundPacket;
|
||||
use pocketmine\network\mcpe\protocol\types\BlockPosition;
|
||||
@ -685,7 +686,7 @@ class World implements ChunkManager{
|
||||
$this->broadcastPacketToViewers($pos, $e);
|
||||
}
|
||||
}else{
|
||||
$this->server->broadcastPackets($this->filterViewersForPosition($pos, $players), $pk);
|
||||
NetworkBroadcastUtils::broadcastPackets($this->filterViewersForPosition($pos, $players), $pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -711,7 +712,7 @@ class World implements ChunkManager{
|
||||
$this->broadcastPacketToViewers($pos, $e);
|
||||
}
|
||||
}else{
|
||||
$this->server->broadcastPackets($this->filterViewersForPosition($pos, $ev->getRecipients()), $pk);
|
||||
NetworkBroadcastUtils::broadcastPackets($this->filterViewersForPosition($pos, $ev->getRecipients()), $pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1021,7 +1022,7 @@ class World implements ChunkManager{
|
||||
World::getXZ($index, $chunkX, $chunkZ);
|
||||
$chunkPlayers = $this->getChunkPlayers($chunkX, $chunkZ);
|
||||
if(count($chunkPlayers) > 0){
|
||||
$this->server->broadcastPackets($chunkPlayers, $entries);
|
||||
NetworkBroadcastUtils::broadcastPackets($chunkPlayers, $entries);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user