PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
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
40 public static function create(
41 int $sound,
42 Vector3 $position,
43 int $extraData,
44 string $entityType,
45 bool $isBabyMob,
46 bool $disableRelativeVolume,
47 int $actorUniqueId,
48 ) : self{
49 $result = new self;
50 $result->sound = $sound;
51 $result->position = $position;
52 $result->extraData = $extraData;
53 $result->entityType = $entityType;
54 $result->isBabyMob = $isBabyMob;
55 $result->disableRelativeVolume = $disableRelativeVolume;
56 $result->actorUniqueId = $actorUniqueId;
57 return $result;
58 }
59
60 public static function nonActorSound(int $sound, Vector3 $position, bool $disableRelativeVolume, int $extraData = -1) : self{
61 return self::create($sound, $position, $extraData, ":", false, $disableRelativeVolume, -1);
62 }
63
64 protected function decodePayload(ByteBufferReader $in) : void{
65 $this->sound = VarInt::readUnsignedInt($in);
66 $this->position = CommonTypes::getVector3($in);
67 $this->extraData = VarInt::readSignedInt($in);
68 $this->entityType = CommonTypes::getString($in);
69 $this->isBabyMob = CommonTypes::getBool($in);
70 $this->disableRelativeVolume = CommonTypes::getBool($in);
71 $this->actorUniqueId = LE::readSignedLong($in); //WHY IS THIS NON-STANDARD?
72 }
73
74 protected function encodePayload(ByteBufferWriter $out) : void{
75 VarInt::writeUnsignedInt($out, $this->sound);
76 CommonTypes::putVector3($out, $this->position);
77 VarInt::writeSignedInt($out, $this->extraData);
78 CommonTypes::putString($out, $this->entityType);
79 CommonTypes::putBool($out, $this->isBabyMob);
80 CommonTypes::putBool($out, $this->disableRelativeVolume);
81 LE::writeSignedLong($out, $this->actorUniqueId);
82 }
83
84 public function handle(PacketHandlerInterface $handler) : bool{
85 return $handler->handleLevelSoundEvent($this);
86 }
87}
static create(int $sound, Vector3 $position, int $extraData, string $entityType, bool $isBabyMob, bool $disableRelativeVolume, int $actorUniqueId,)