PocketMine-MP 5.21.2 git-b2aa6396c3cc2cafdd815eacc360e1ad89599899
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
19
21 public const NETWORK_ID = ProtocolInfo::PLAY_SOUND_PACKET;
22
23 public string $soundName;
24 public float $x;
25 public float $y;
26 public float $z;
27 public float $volume;
28 public float $pitch;
29
33 public static function create(string $soundName, float $x, float $y, float $z, float $volume, float $pitch) : self{
34 $result = new self;
35 $result->soundName = $soundName;
36 $result->x = $x;
37 $result->y = $y;
38 $result->z = $z;
39 $result->volume = $volume;
40 $result->pitch = $pitch;
41 return $result;
42 }
43
44 protected function decodePayload(PacketSerializer $in) : void{
45 $this->soundName = $in->getString();
46 $blockPosition = $in->getBlockPosition();
47 $this->x = $blockPosition->getX() / 8;
48 $this->y = $blockPosition->getY() / 8;
49 $this->z = $blockPosition->getZ() / 8;
50 $this->volume = $in->getLFloat();
51 $this->pitch = $in->getLFloat();
52 }
53
54 protected function encodePayload(PacketSerializer $out) : void{
55 $out->putString($this->soundName);
56 $out->putBlockPosition(new BlockPosition((int) ($this->x * 8), (int) ($this->y * 8), (int) ($this->z * 8)));
57 $out->putLFloat($this->volume);
58 $out->putLFloat($this->pitch);
59 }
60
61 public function handle(PacketHandlerInterface $handler) : bool{
62 return $handler->handlePlaySound($this);
63 }
64}
static create(string $soundName, float $x, float $y, float $z, float $volume, float $pitch)