mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-11 05:55:33 +00:00
LevelSoundEventPacket: more helpers
This commit is contained in:
parent
10db57655e
commit
e1504c668e
@ -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{
|
||||
|
@ -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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user