0
0
mirror of https://github.com/pmmp/BedrockProtocol.git synced 2025-02-23 12:46:15 +00:00
BedrockProtocol/src/MapInfoRequestPacket.php
2022-08-09 18:57:29 +01:00

61 lines
1.7 KiB
PHP

<?php
/*
* This file is part of BedrockProtocol.
* Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
*
* BedrockProtocol is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol;
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\types\MapInfoRequestPacketClientPixel;
use function count;
class MapInfoRequestPacket extends DataPacket implements ServerboundPacket{
public const NETWORK_ID = ProtocolInfo::MAP_INFO_REQUEST_PACKET;
public int $mapId;
/** @var MapInfoRequestPacketClientPixel[] */
public array $clientPixels = [];
/**
* @generate-create-func
* @param MapInfoRequestPacketClientPixel[] $clientPixels
*/
public static function create(int $mapId, array $clientPixels) : self{
$result = new self;
$result->mapId = $mapId;
$result->clientPixels = $clientPixels;
return $result;
}
protected function decodePayload(PacketSerializer $in) : void{
$this->mapId = $in->getActorUniqueId();
$this->clientPixels = [];
for($i = 0, $count = $in->getLInt(); $i < $count; $i++){
$this->clientPixels[] = MapInfoRequestPacketClientPixel::read($in);
}
}
protected function encodePayload(PacketSerializer $out) : void{
$out->putActorUniqueId($this->mapId);
$out->putLInt(count($this->clientPixels));
foreach($this->clientPixels as $pixel){
$pixel->write($out);
}
}
public function handle(PacketHandlerInterface $handler) : bool{
return $handler->handleMapInfoRequest($this);
}
}