diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 51d02b6de2..09cff9285a 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -523,17 +523,20 @@ class Level implements ChunkManager, Metadatable{ * @param int $extraData * @param int $entityTypeId * @param bool $isBabyMob - * @param bool $disableRelativeVolume If true, all players receiving this sound-event will hear the sound at full volume regardless of distance */ - public function broadcastLevelSoundEvent(Vector3 $pos, int $soundId, int $extraData = -1, int $entityTypeId = -1, bool $isBabyMob = false, bool $disableRelativeVolume = false){ - $pk = new LevelSoundEventPacket(); - $pk->sound = $soundId; - $pk->extraData = $extraData; - $pk->entityType = AddEntityPacket::LEGACY_ID_MAP_BC[$entityTypeId] ?? ":"; - $pk->isBabyMob = $isBabyMob; - $pk->disableRelativeVolume = $disableRelativeVolume; - $pk->position = $pos->asVector3(); - $this->broadcastPacketToViewers($pos, $pk); + public function broadcastLevelSoundEvent(?Vector3 $pos, int $soundId, int $extraData = -1, int $entityTypeId = -1, bool $isBabyMob = false){ + $pk = LevelSoundEventPacket::create( + $soundId, + $extraData, + $pos, + AddEntityPacket::LEGACY_ID_MAP_BC[$entityTypeId] ?? ":", + $isBabyMob + ); + if($pos !== null){ + $this->broadcastPacketToViewers($pos, $pk); + }else{ + $this->broadcastGlobalPacket($pk); + } } public function getAutoSave() : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/LevelSoundEventPacket.php b/src/pocketmine/network/mcpe/protocol/LevelSoundEventPacket.php index 63350029ae..61a0293c91 100644 --- a/src/pocketmine/network/mcpe/protocol/LevelSoundEventPacket.php +++ b/src/pocketmine/network/mcpe/protocol/LevelSoundEventPacket.php @@ -285,6 +285,17 @@ class LevelSoundEventPacket extends DataPacket implements ClientboundPacket, Ser public const SOUND_CANT_BREED = 254; public const SOUND_UNDEFINED = 255; + public static function create(int $sound, int $extraData, ?Vector3 $pos, string $entityType = ":", bool $isBabyMob = false) : self{ + $result = new self; + $result->sound = $sound; + $result->extraData = $extraData; + $result->position = $pos; + $result->disableRelativeVolume = $pos === null; + $result->entityType = $entityType; + $result->isBabyMob = $isBabyMob; + return $result; + } + /** @var int */ public $sound; /** @var Vector3 */