PocketMine-MP 5.42.1 git-443151900a14fe9dc682cbf786fa441be1294fab
Loading...
Searching...
No Matches
LocatorBarPacket.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\VarInt;
21use function count;
22
24 public const NETWORK_ID = ProtocolInfo::LOCATOR_BAR_PACKET;
25
30 private array $waypoints;
31
37 public static function create(array $waypoints) : self{
38 $result = new self;
39 $result->waypoints = $waypoints;
40 return $result;
41 }
42
43 protected function decodePayload(ByteBufferReader $in) : void{
44 $this->waypoints = [];
45 for($i = 0, $len = VarInt::readUnsignedInt($in); $i < $len; ++$i){
46 $this->waypoints[] = LocatorBarWaypointPayload::read($in);
47 }
48 }
49
50 protected function encodePayload(ByteBufferWriter $out) : void{
51 VarInt::writeUnsignedInt($out, count($this->waypoints));
52 foreach($this->waypoints as $waypoint){
53 $waypoint->write($out);
54 }
55 }
56
57 public function handle(PacketHandlerInterface $handler) : bool{
58 return $handler->handleLocatorBar($this);
59 }
60}