58 public static function create(
ChunkPosition $chunkPosition,
int $dimensionId,
int $subChunkCount,
bool $clientSubChunkRequestsEnabled, ?array $usedBlobHashes,
string $extraPayload) : self{
60 $result->chunkPosition = $chunkPosition;
61 $result->dimensionId = $dimensionId;
62 $result->subChunkCount = $subChunkCount;
63 $result->clientSubChunkRequestsEnabled = $clientSubChunkRequestsEnabled;
64 $result->usedBlobHashes = $usedBlobHashes;
65 $result->extraPayload = $extraPayload;
103 $this->dimensionId = VarInt::readSignedInt($in);
105 $subChunkCountButNotReally = VarInt::readUnsignedInt($in);
106 if($subChunkCountButNotReally === self::CLIENT_REQUEST_FULL_COLUMN_FAKE_COUNT){
107 $this->clientSubChunkRequestsEnabled =
true;
108 $this->subChunkCount = PHP_INT_MAX;
109 }elseif($subChunkCountButNotReally === self::CLIENT_REQUEST_TRUNCATED_COLUMN_FAKE_COUNT){
110 $this->clientSubChunkRequestsEnabled =
true;
111 $this->subChunkCount = LE::readUnsignedShort($in);
113 $this->clientSubChunkRequestsEnabled =
false;
114 $this->subChunkCount = $subChunkCountButNotReally;
117 $cacheEnabled = CommonTypes::getBool($in);
119 $this->usedBlobHashes = [];
120 $count = VarInt::readUnsignedInt($in);
121 if($count > self::MAX_BLOB_HASHES){
122 throw new PacketDecodeException(
"Expected at most " . self::MAX_BLOB_HASHES .
" blob hashes, got " . $count);
124 for($i = 0; $i < $count; ++$i){
125 $this->usedBlobHashes[] = LE::readUnsignedLong($in);
128 $this->extraPayload = CommonTypes::getString($in);
132 $this->chunkPosition->write($out);
133 VarInt::writeSignedInt($out, $this->dimensionId);
135 if($this->clientSubChunkRequestsEnabled){
136 if($this->subChunkCount === PHP_INT_MAX){
137 VarInt::writeUnsignedInt($out, self::CLIENT_REQUEST_FULL_COLUMN_FAKE_COUNT);
139 VarInt::writeUnsignedInt($out, self::CLIENT_REQUEST_TRUNCATED_COLUMN_FAKE_COUNT);
140 LE::writeUnsignedShort($out, $this->subChunkCount);
143 VarInt::writeUnsignedInt($out, $this->subChunkCount);
146 CommonTypes::putBool($out, $this->usedBlobHashes !==
null);
147 if($this->usedBlobHashes !==
null){
148 VarInt::writeUnsignedInt($out, count($this->usedBlobHashes));
149 foreach($this->usedBlobHashes as $hash){
150 LE::writeUnsignedLong($out, $hash);
153 CommonTypes::putString($out, $this->extraPayload);