PocketMine-MP 5.15.1 git-5ef247620a7c6301a849b54e5ef1009217729fc8
LevelEventPacket.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
20
22 public const NETWORK_ID = ProtocolInfo::LEVEL_EVENT_PACKET;
23
25 public int $eventId;
26 public int $eventData;
27 public ?Vector3 $position = null;
28
32 public static function create(int $eventId, int $eventData, ?Vector3 $position) : self{
33 $result = new self;
34 $result->eventId = $eventId;
35 $result->eventData = $eventData;
36 $result->position = $position;
37 return $result;
38 }
39
40 public static function standardParticle(int $particleId, int $data, Vector3 $position) : self{
41 return self::create(LevelEvent::ADD_PARTICLE_MASK | $particleId, $data, $position);
42 }
43
44 protected function decodePayload(PacketSerializer $in) : void{
45 $this->eventId = $in->getVarInt();
46 $this->position = $in->getVector3();
47 $this->eventData = $in->getVarInt();
48 }
49
50 protected function encodePayload(PacketSerializer $out) : void{
51 $out->putVarInt($this->eventId);
52 $out->putVector3Nullable($this->position);
53 $out->putVarInt($this->eventData);
54 }
55
56 public function handle(PacketHandlerInterface $handler) : bool{
57 return $handler->handleLevelEvent($this);
58 }
59}
static create(int $eventId, int $eventData, ?Vector3 $position)