LevelSoundEventPacket: more helpers

This commit is contained in:
Dylan K. Taylor 2019-03-26 18:14:33 +00:00
parent 10db57655e
commit e1504c668e
2 changed files with 24 additions and 10 deletions

View File

@ -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{

View File

@ -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 */