PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
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
17use pmmp\encoding\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\VarInt;
23
25 public const NETWORK_ID = ProtocolInfo::POSITION_TRACKING_D_B_SERVER_BROADCAST_PACKET;
26
27 public const ACTION_UPDATE = 0;
28 public const ACTION_DESTROY = 1;
29 public const ACTION_NOT_FOUND = 2;
30
31 private int $action;
32 private int $trackingId;
34 private CacheableNbt $nbt;
35
40 public static function create(int $action, int $trackingId, CacheableNbt $nbt) : self{
41 $result = new self;
42 $result->action = $action;
43 $result->trackingId = $trackingId;
44 $result->nbt = $nbt;
45 return $result;
46 }
47
48 public function getAction() : int{ return $this->action; }
49
50 public function getTrackingId() : int{ return $this->trackingId; }
51
53 public function getNbt() : CacheableNbt{ return $this->nbt; }
54
55 protected function decodePayload(ByteBufferReader $in) : void{
56 $this->action = Byte::readUnsigned($in);
57 $this->trackingId = VarInt::readSignedInt($in);
58 $this->nbt = new CacheableNbt(CommonTypes::getNbtCompoundRoot($in));
59 }
60
61 protected function encodePayload(ByteBufferWriter $out) : void{
62 Byte::writeUnsigned($out, $this->action);
63 VarInt::writeSignedInt($out, $this->trackingId);
64 $out->writeByteArray($this->nbt->getEncodedNbt());
65 }
66
67 public function handle(PacketHandlerInterface $handler) : bool{
68 return $handler->handlePositionTrackingDBServerBroadcast($this);
69 }
70}