22 public function __construct(
24 private int $requestResult,
25 private string $terrainData,
31 public function getRequestResult() :
int{
return $this->requestResult; }
33 public function getTerrainData() :
string{
return $this->terrainData; }
37 public static function read(
PacketSerializer $in,
bool $cacheEnabled) :
self{
38 $offset = SubChunkPositionOffset::read($in);
40 $requestResult = $in->
getByte();
42 $data = !$cacheEnabled || $requestResult !== SubChunkRequestResult::SUCCESS_ALL_AIR ? $in->
getString() :
"";
44 $heightMapDataType = $in->
getByte();
45 $heightMapData = match ($heightMapDataType) {
46 SubChunkPacketHeightMapType::NO_DATA =>
null,
47 SubChunkPacketHeightMapType::DATA => SubChunkPacketHeightMapInfo::read($in),
48 SubChunkPacketHeightMapType::ALL_TOO_HIGH => SubChunkPacketHeightMapInfo::allTooHigh(),
49 SubChunkPacketHeightMapType::ALL_TOO_LOW => SubChunkPacketHeightMapInfo::allTooLow(),
62 $this->offset->write($out);
64 $out->putByte($this->requestResult);
66 if(!$cacheEnabled || $this->requestResult !== SubChunkRequestResult::SUCCESS_ALL_AIR){
67 $out->putString($this->terrainData);
70 if($this->heightMap ===
null){
71 $out->putByte(SubChunkPacketHeightMapType::NO_DATA);
72 }elseif($this->heightMap->isAllTooLow()){
73 $out->putByte(SubChunkPacketHeightMapType::ALL_TOO_LOW);
74 }elseif($this->heightMap->isAllTooHigh()){
75 $out->putByte(SubChunkPacketHeightMapType::ALL_TOO_HIGH);
77 $heightMapData = $this->heightMap;
78 $out->putByte(SubChunkPacketHeightMapType::DATA);
79 $heightMapData->write($out);