PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
Loading...
Searching...
No Matches
SubChunkRequestPacket.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::SUB_CHUNK_REQUEST_PACKET;
24
25 private int $dimension;
26 private SubChunkPosition $basePosition;
31 private array $entries;
32
38 public static function create(int $dimension, SubChunkPosition $basePosition, array $entries) : self{
39 $result = new self;
40 $result->dimension = $dimension;
41 $result->basePosition = $basePosition;
42 $result->entries = $entries;
43 return $result;
44 }
45
46 public function getDimension() : int{ return $this->dimension; }
47
48 public function getBasePosition() : SubChunkPosition{ return $this->basePosition; }
49
54 public function getEntries() : array{ return $this->entries; }
55
56 protected function decodePayload(PacketSerializer $in) : void{
57 $this->dimension = $in->getVarInt();
58 $this->basePosition = SubChunkPosition::read($in);
59
60 $this->entries = [];
61 for($i = 0, $count = $in->getLInt(); $i < $count; $i++){
62 $this->entries[] = SubChunkPositionOffset::read($in);
63 }
64 }
65
66 protected function encodePayload(PacketSerializer $out) : void{
67 $out->putVarInt($this->dimension);
68 $this->basePosition->write($out);
69
70 $out->putLInt(count($this->entries));
71 foreach($this->entries as $entry){
72 $entry->write($out);
73 }
74 }
75
76 public function handle(PacketHandlerInterface $handler) : bool{
77 return $handler->handleSubChunkRequest($this);
78 }
79}
static create(int $dimension, SubChunkPosition $basePosition, array $entries)