PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
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
36 public static function create(string $soundName, float $x, float $y, float $z, float $volume, float $pitch) : self{
37 $result = new self;
38 $result->soundName = $soundName;
39 $result->x = $x;
40 $result->y = $y;
41 $result->z = $z;
42 $result->volume = $volume;
43 $result->pitch = $pitch;
44 return $result;
45 }
46
47 protected function decodePayload(ByteBufferReader $in) : void{
48 $this->soundName = CommonTypes::getString($in);
49 $blockPosition = CommonTypes::getBlockPosition($in);
50 $this->x = $blockPosition->getX() / 8;
51 $this->y = $blockPosition->getY() / 8;
52 $this->z = $blockPosition->getZ() / 8;
53 $this->volume = LE::readFloat($in);
54 $this->pitch = LE::readFloat($in);
55 }
56
57 protected function encodePayload(ByteBufferWriter $out) : void{
58 CommonTypes::putString($out, $this->soundName);
59 CommonTypes::putBlockPosition($out, new BlockPosition((int) ($this->x * 8), (int) ($this->y * 8), (int) ($this->z * 8)));
60 LE::writeFloat($out, $this->volume);
61 LE::writeFloat($out, $this->pitch);
62 }
63
64 public function handle(PacketHandlerInterface $handler) : bool{
65 return $handler->handlePlaySound($this);
66 }
67}
static create(string $soundName, float $x, float $y, float $z, float $volume, float $pitch)