13declare(strict_types=1);
15namespace pocketmine\network\mcpe\protocol;
25 public const NETWORK_ID = ProtocolInfo::LEVEL_CHUNK_PACKET;
30 private const CLIENT_REQUEST_FULL_COLUMN_FAKE_COUNT = Limits::UINT32_MAX;
35 private const CLIENT_REQUEST_TRUNCATED_COLUMN_FAKE_COUNT = Limits::UINT32_MAX - 1;
38 private const MAX_BLOB_HASHES = 64;
42 private int $dimensionId;
43 private int $subChunkCount;
44 private bool $clientSubChunkRequestsEnabled;
46 private ?array $usedBlobHashes =
null;
47 private string $extraPayload;
54 public static function create(
ChunkPosition $chunkPosition,
int $dimensionId,
int $subChunkCount,
bool $clientSubChunkRequestsEnabled, ?array $usedBlobHashes,
string $extraPayload) : self{
56 $result->chunkPosition = $chunkPosition;
57 $result->dimensionId = $dimensionId;
58 $result->subChunkCount = $subChunkCount;
59 $result->clientSubChunkRequestsEnabled = $clientSubChunkRequestsEnabled;
60 $result->usedBlobHashes = $usedBlobHashes;
61 $result->extraPayload = $extraPayload;
65 public function getChunkPosition() :
ChunkPosition{ return $this->chunkPosition; }
67 public function getDimensionId() : int{ return $this->dimensionId; }
69 public function getSubChunkCount() : int{
70 return $this->subChunkCount;
73 public function isClientSubChunkRequestEnabled() : bool{
74 return $this->clientSubChunkRequestsEnabled;
77 public function isCacheEnabled() : bool{
78 return $this->usedBlobHashes !== null;
85 return $this->usedBlobHashes;
88 public function getExtraPayload() : string{
89 return $this->extraPayload;
97 if($subChunkCountButNotReally === self::CLIENT_REQUEST_FULL_COLUMN_FAKE_COUNT){
98 $this->clientSubChunkRequestsEnabled =
true;
99 $this->subChunkCount = PHP_INT_MAX;
100 }elseif($subChunkCountButNotReally === self::CLIENT_REQUEST_TRUNCATED_COLUMN_FAKE_COUNT){
101 $this->clientSubChunkRequestsEnabled =
true;
104 $this->clientSubChunkRequestsEnabled =
false;
105 $this->subChunkCount = $subChunkCountButNotReally;
108 $cacheEnabled = $in->
getBool();
110 $this->usedBlobHashes = [];
112 if($count > self::MAX_BLOB_HASHES){
113 throw new PacketDecodeException(
"Expected at most " . self::MAX_BLOB_HASHES .
" blob hashes, got " . $count);
115 for($i = 0; $i < $count; ++$i){
116 $this->usedBlobHashes[] = $in->
getLLong();
123 $this->chunkPosition->write($out);
126 if($this->clientSubChunkRequestsEnabled){
127 if($this->subChunkCount === PHP_INT_MAX){
131 $out->putLShort($this->subChunkCount);
137 $out->putBool($this->usedBlobHashes !==
null);
138 if($this->usedBlobHashes !==
null){
140 foreach($this->usedBlobHashes as $hash){
141 $out->putLLong($hash);
144 $out->putString($this->extraPayload);
148 return $handler->handleLevelChunk($this);
encodePayload(PacketSerializer $out)
static create(ChunkPosition $chunkPosition, int $dimensionId, int $subChunkCount, bool $clientSubChunkRequestsEnabled, ?array $usedBlobHashes, string $extraPayload)
handle(PacketHandlerInterface $handler)
decodePayload(PacketSerializer $in)
putUnsignedVarInt(int $v)