PocketMine-MP 5.15.1 git-08c6e63aac45a450fe3b437616ee8aa2500e04e2
PositionTrackingDBServerBroadcastPacket.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::POSITION_TRACKING_D_B_SERVER_BROADCAST_PACKET;
22
23 public const ACTION_UPDATE = 0;
24 public const ACTION_DESTROY = 1;
25 public const ACTION_NOT_FOUND = 2;
26
27 private int $action;
28 private int $trackingId;
30 private CacheableNbt $nbt;
31
36 public static function create(int $action, int $trackingId, CacheableNbt $nbt) : self{
37 $result = new self;
38 $result->action = $action;
39 $result->trackingId = $trackingId;
40 $result->nbt = $nbt;
41 return $result;
42 }
43
44 public function getAction() : int{ return $this->action; }
45
46 public function getTrackingId() : int{ return $this->trackingId; }
47
49 public function getNbt() : CacheableNbt{ return $this->nbt; }
50
51 protected function decodePayload(PacketSerializer $in) : void{
52 $this->action = $in->getByte();
53 $this->trackingId = $in->getVarInt();
54 $this->nbt = new CacheableNbt($in->getNbtCompoundRoot());
55 }
56
57 protected function encodePayload(PacketSerializer $out) : void{
58 $out->putByte($this->action);
59 $out->putVarInt($this->trackingId);
60 $out->put($this->nbt->getEncodedNbt());
61 }
62
63 public function handle(PacketHandlerInterface $handler) : bool{
64 return $handler->handlePositionTrackingDBServerBroadcast($this);
65 }
66}