22 public function __construct(
24 private int $requestResult,
25 private string $terrainData,
32 public function getRequestResult() :
int{
return $this->requestResult; }
34 public function getTerrainData() :
string{
return $this->terrainData; }
40 public static function read(
PacketSerializer $in,
bool $cacheEnabled) :
self{
41 $offset = SubChunkPositionOffset::read($in);
43 $requestResult = $in->
getByte();
45 $data = !$cacheEnabled || $requestResult !== SubChunkRequestResult::SUCCESS_ALL_AIR ? $in->
getString() :
"";
47 $heightMapDataType = $in->
getByte();
48 $heightMapData = match ($heightMapDataType) {
49 SubChunkPacketHeightMapType::NO_DATA =>
null,
50 SubChunkPacketHeightMapType::DATA => SubChunkPacketHeightMapInfo::read($in),
51 SubChunkPacketHeightMapType::ALL_TOO_HIGH => SubChunkPacketHeightMapInfo::allTooHigh(),
52 SubChunkPacketHeightMapType::ALL_TOO_LOW => SubChunkPacketHeightMapInfo::allTooLow(),
56 $renderHeightMapDataType = $in->
getByte();
57 $renderHeightMapData = match ($renderHeightMapDataType) {
58 SubChunkPacketHeightMapType::NO_DATA =>
null,
59 SubChunkPacketHeightMapType::DATA => SubChunkPacketHeightMapInfo::read($in),
60 SubChunkPacketHeightMapType::ALL_TOO_HIGH => SubChunkPacketHeightMapInfo::allTooHigh(),
61 SubChunkPacketHeightMapType::ALL_TOO_LOW => SubChunkPacketHeightMapInfo::allTooLow(),
62 SubChunkPacketHeightMapType::ALL_COPIED => $heightMapData,
63 default =>
throw new PacketDecodeException(
"Unknown render heightmap data type $renderHeightMapDataType")
76 $this->offset->write($out);
78 $out->putByte($this->requestResult);
80 if(!$cacheEnabled || $this->requestResult !== SubChunkRequestResult::SUCCESS_ALL_AIR){
81 $out->putString($this->terrainData);
84 if($this->heightMap ===
null){
85 $out->putByte(SubChunkPacketHeightMapType::NO_DATA);
86 }elseif($this->heightMap->isAllTooLow()){
87 $out->putByte(SubChunkPacketHeightMapType::ALL_TOO_LOW);
88 }elseif($this->heightMap->isAllTooHigh()){
89 $out->putByte(SubChunkPacketHeightMapType::ALL_TOO_HIGH);
91 $heightMapData = $this->heightMap;
92 $out->putByte(SubChunkPacketHeightMapType::DATA);
93 $heightMapData->write($out);
96 if($this->renderHeightMap ===
null){
97 $out->putByte(SubChunkPacketHeightMapType::ALL_COPIED);
98 }elseif($this->renderHeightMap->isAllTooLow()){
99 $out->putByte(SubChunkPacketHeightMapType::ALL_TOO_LOW);
100 }elseif($this->renderHeightMap->isAllTooHigh()){
101 $out->putByte(SubChunkPacketHeightMapType::ALL_TOO_HIGH);
103 $renderHeightMapData = $this->renderHeightMap;
104 $out->putByte(SubChunkPacketHeightMapType::DATA);
105 $renderHeightMapData->write($out);