PocketMine-MP 5.17.1 git-df4ada81e5d74a14046f27cf44a37dcee69d657e
MapInfoRequestPacket.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
20use function count;
21
23 public const NETWORK_ID = ProtocolInfo::MAP_INFO_REQUEST_PACKET;
24
25 public int $mapId;
27 public array $clientPixels = [];
28
33 public static function create(int $mapId, array $clientPixels) : self{
34 $result = new self;
35 $result->mapId = $mapId;
36 $result->clientPixels = $clientPixels;
37 return $result;
38 }
39
40 protected function decodePayload(PacketSerializer $in) : void{
41 $this->mapId = $in->getActorUniqueId();
42
43 $this->clientPixels = [];
44 $count = $in->getLInt();
45 if($count > MapImage::MAX_HEIGHT * MapImage::MAX_WIDTH){
46 throw new PacketDecodeException("Too many pixels");
47 }
48 for($i = 0; $i < $count; $i++){
49 $this->clientPixels[] = MapInfoRequestPacketClientPixel::read($in);
50 }
51 }
52
53 protected function encodePayload(PacketSerializer $out) : void{
54 $out->putActorUniqueId($this->mapId);
55
56 $out->putLInt(count($this->clientPixels));
57 foreach($this->clientPixels as $pixel){
58 $pixel->write($out);
59 }
60 }
61
62 public function handle(PacketHandlerInterface $handler) : bool{
63 return $handler->handleMapInfoRequest($this);
64 }
65}
static create(int $mapId, array $clientPixels)