PocketMine-MP 5.43.2 git-a137a986d01d9af23452b2e741699a770c7ae112
Loading...
Searching...
No Matches
PlaySoundPacket.php
1<?php
2
3/*
4 * This file is part of BedrockProtocol.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6 *
7 * BedrockProtocol is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\LE;
22
24 public const NETWORK_ID = ProtocolInfo::PLAY_SOUND_PACKET;
25
26 public string $soundName;
27 public float $x;
28 public float $y;
29 public float $z;
30 public float $volume;
31 public float $pitch;
32 public ?int $serverSoundHandle = null;
33
37 public static function create(
38 string $soundName,
39 float $x,
40 float $y,
41 float $z,
42 float $volume,
43 float $pitch,
44 ?int $serverSoundHandle,
45 ) : self{
46 $result = new self;
47 $result->soundName = $soundName;
48 $result->x = $x;
49 $result->y = $y;
50 $result->z = $z;
51 $result->volume = $volume;
52 $result->pitch = $pitch;
53 $result->serverSoundHandle = $serverSoundHandle;
54 return $result;
55 }
56
57 protected function decodePayload(ByteBufferReader $in) : void{
58 $this->soundName = CommonTypes::getString($in);
59 $blockPosition = CommonTypes::getBlockPosition($in);
60 $this->x = $blockPosition->getX() / 8;
61 $this->y = $blockPosition->getY() / 8;
62 $this->z = $blockPosition->getZ() / 8;
63 $this->volume = LE::readFloat($in);
64 $this->pitch = LE::readFloat($in);
65 $this->serverSoundHandle = CommonTypes::readOptional($in, LE::readUnsignedLong(...));
66 }
67
68 protected function encodePayload(ByteBufferWriter $out) : void{
69 CommonTypes::putString($out, $this->soundName);
70 CommonTypes::putBlockPosition($out, new BlockPosition((int) ($this->x * 8), (int) ($this->y * 8), (int) ($this->z * 8)));
71 LE::writeFloat($out, $this->volume);
72 LE::writeFloat($out, $this->pitch);
73 CommonTypes::writeOptional($out, $this->serverSoundHandle, LE::writeUnsignedLong(...));
74 }
75
76 public function handle(PacketHandlerInterface $handler) : bool{
77 return $handler->handlePlaySound($this);
78 }
79}
static create(string $soundName, float $x, float $y, float $z, float $volume, float $pitch, ?int $serverSoundHandle,)