Use NetworkBroadcastUtils for broadcasting packets

this eradicates all but 4 usages of Server in Entity, which is extremely cool.
This commit is contained in:
Dylan K. Taylor 2023-03-15 22:28:51 +00:00
parent a31e3331fd
commit 337a254768
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
4 changed files with 10 additions and 8 deletions

View File

@ -1351,6 +1351,7 @@ class Server{
/** /**
* @param Player[] $players * @param Player[] $players
* @param ClientboundPacket[] $packets * @param ClientboundPacket[] $packets
* @deprecated
*/ */
public function broadcastPackets(array $players, array $packets) : bool{ public function broadcastPackets(array $players, array $packets) : bool{
return NetworkBroadcastUtils::broadcastPackets($players, $packets); return NetworkBroadcastUtils::broadcastPackets($players, $packets);

View File

@ -787,7 +787,7 @@ abstract class Entity{
$this->spawnTo($player); $this->spawnTo($player);
} }
}else{ }else{
$this->server->broadcastPackets($this->hasSpawned, [MoveActorAbsolutePacket::create( NetworkBroadcastUtils::broadcastPackets($this->hasSpawned, [MoveActorAbsolutePacket::create(
$this->id, $this->id,
$this->getOffsetPosition($this->location), $this->getOffsetPosition($this->location),
$this->location->pitch, $this->location->pitch,
@ -802,7 +802,7 @@ abstract class Entity{
} }
protected function broadcastMotion() : void{ 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{ public function getGravity() : float{
@ -1682,7 +1682,7 @@ abstract class Entity{
* @param Player[]|null $targets * @param Player[]|null $targets
*/ */
public function broadcastAnimation(Animation $animation, ?array $targets = null) : void{ 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{ public function broadcastSound(Sound $sound, ?array $targets = null) : void{
if(!$this->silent){ if(!$this->silent){
$this->server->broadcastPackets($targets ?? $this->getViewers(), $sound->encode($this->location)); NetworkBroadcastUtils::broadcastPackets($targets ?? $this->getViewers(), $sound->encode($this->location));
} }
} }

View File

@ -176,7 +176,7 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
* @param Player[]|null $targets * @param Player[]|null $targets
*/ */
public function sendSkin(?array $targets = null) : void{ 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)) PlayerSkinPacket::create($this->getUniqueId(), "", "", SkinAdapterSingleton::get()->toSkinData($this->skin))
]); ]);
} }

View File

@ -65,6 +65,7 @@ use pocketmine\math\Vector3;
use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\StringTag; use pocketmine\nbt\tag\StringTag;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping; use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\NetworkBroadcastUtils;
use pocketmine\network\mcpe\protocol\BlockActorDataPacket; use pocketmine\network\mcpe\protocol\BlockActorDataPacket;
use pocketmine\network\mcpe\protocol\ClientboundPacket; use pocketmine\network\mcpe\protocol\ClientboundPacket;
use pocketmine\network\mcpe\protocol\types\BlockPosition; use pocketmine\network\mcpe\protocol\types\BlockPosition;
@ -685,7 +686,7 @@ class World implements ChunkManager{
$this->broadcastPacketToViewers($pos, $e); $this->broadcastPacketToViewers($pos, $e);
} }
}else{ }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); $this->broadcastPacketToViewers($pos, $e);
} }
}else{ }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); World::getXZ($index, $chunkX, $chunkZ);
$chunkPlayers = $this->getChunkPlayers($chunkX, $chunkZ); $chunkPlayers = $this->getChunkPlayers($chunkX, $chunkZ);
if(count($chunkPlayers) > 0){ if(count($chunkPlayers) > 0){
$this->server->broadcastPackets($chunkPlayers, $entries); NetworkBroadcastUtils::broadcastPackets($chunkPlayers, $entries);
} }
} }