PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
Loading...
Searching...
No Matches
NetworkChunkPublisherUpdatePacket.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::NETWORK_CHUNK_PUBLISHER_UPDATE_PACKET;
24
25 public BlockPosition $blockPosition;
26 public int $radius;
28 public array $savedChunks = [];
29
30 public const MAX_SAVED_CHUNKS = 9216;
31
36 public static function create(BlockPosition $blockPosition, int $radius, array $savedChunks) : self{
37 $result = new self;
38 $result->blockPosition = $blockPosition;
39 $result->radius = $radius;
40 $result->savedChunks = $savedChunks;
41 return $result;
42 }
43
44 protected function decodePayload(PacketSerializer $in) : void{
45 $this->blockPosition = $in->getSignedBlockPosition();
46 $this->radius = $in->getUnsignedVarInt();
47
48 $count = $in->getLInt();
49 if($count > self::MAX_SAVED_CHUNKS){
50 throw new PacketDecodeException("Expected at most " . self::MAX_SAVED_CHUNKS . " saved chunks, got " . $count);
51 }
52 for($i = 0, $this->savedChunks = []; $i < $count; $i++){
53 $this->savedChunks[] = ChunkPosition::read($in);
54 }
55 }
56
57 protected function encodePayload(PacketSerializer $out) : void{
58 $out->putSignedBlockPosition($this->blockPosition);
59 $out->putUnsignedVarInt($this->radius);
60
61 $out->putLInt(count($this->savedChunks));
62 foreach($this->savedChunks as $chunk){
63 $chunk->write($out);
64 }
65 }
66
67 public function handle(PacketHandlerInterface $handler) : bool{
68 return $handler->handleNetworkChunkPublisherUpdate($this);
69 }
70}
static create(BlockPosition $blockPosition, int $radius, array $savedChunks)