PocketMine-MP 5.43.2 git-c9e7b3ab9bd2149f206392522e8eb7e9d8d68cfa
Loading...
Searching...
No Matches
LevelSoundEventPacket.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;
20use pmmp\encoding\VarInt;
24
26 public const NETWORK_ID = ProtocolInfo::LEVEL_SOUND_EVENT_PACKET;
27
29 public int $sound;
30 public Vector3 $position;
31 public int $extraData = -1;
32 public string $entityType = ":"; //???
33 public bool $isBabyMob = false; //...
34 public bool $disableRelativeVolume = false;
35 public int $actorUniqueId = -1;
36 public ?Vector3 $firePosition = null;
37
41 public static function create(
42 int $sound,
43 Vector3 $position,
44 int $extraData,
45 string $entityType,
46 bool $isBabyMob,
47 bool $disableRelativeVolume,
48 int $actorUniqueId,
49 ?Vector3 $firePosition,
50 ) : self{
51 $result = new self;
52 $result->sound = $sound;
53 $result->position = $position;
54 $result->extraData = $extraData;
55 $result->entityType = $entityType;
56 $result->isBabyMob = $isBabyMob;
57 $result->disableRelativeVolume = $disableRelativeVolume;
58 $result->actorUniqueId = $actorUniqueId;
59 $result->firePosition = $firePosition;
60 return $result;
61 }
62
63 public static function nonActorSound(int $sound, Vector3 $position, bool $disableRelativeVolume, int $extraData = -1) : self{
64 return self::create($sound, $position, $extraData, ":", false, $disableRelativeVolume, -1, null);
65 }
66
67 protected function decodePayload(ByteBufferReader $in) : void{
68 $this->sound = VarInt::readUnsignedInt($in);
69 $this->position = CommonTypes::getVector3($in);
70 $this->extraData = VarInt::readSignedInt($in);
71 $this->entityType = CommonTypes::getString($in);
72 $this->isBabyMob = CommonTypes::getBool($in);
73 $this->disableRelativeVolume = CommonTypes::getBool($in);
74 $this->actorUniqueId = LE::readSignedLong($in); //WHY IS THIS NON-STANDARD?
75 $this->firePosition = CommonTypes::readOptional($in, CommonTypes::getVector3(...));
76 }
77
78 protected function encodePayload(ByteBufferWriter $out) : void{
79 VarInt::writeUnsignedInt($out, $this->sound);
80 CommonTypes::putVector3($out, $this->position);
81 VarInt::writeSignedInt($out, $this->extraData);
82 CommonTypes::putString($out, $this->entityType);
83 CommonTypes::putBool($out, $this->isBabyMob);
84 CommonTypes::putBool($out, $this->disableRelativeVolume);
85 LE::writeSignedLong($out, $this->actorUniqueId);
86 CommonTypes::writeOptional($out, $this->firePosition, CommonTypes::putVector3(...));
87 }
88
89 public function handle(PacketHandlerInterface $handler) : bool{
90 return $handler->handleLevelSoundEvent($this);
91 }
92}
static create(int $sound, Vector3 $position, int $extraData, string $entityType, bool $isBabyMob, bool $disableRelativeVolume, int $actorUniqueId, ?Vector3 $firePosition,)