45 public function __construct(
46 protected string $path,
49 if(!file_exists($path)){
54 $this->blockStateDeserializer = GlobalBlockStateHandlers::getDeserializer();
55 $this->blockDataUpgrader = GlobalBlockStateHandlers::getUpgrader();
56 $this->blockStateSerializer = GlobalBlockStateHandlers::getSerializer();
67 private function translatePalette(PalettedBlockArray $blockArray, \
Logger $logger) : PalettedBlockArray{
68 $palette = $blockArray->getPalette();
71 $blockDecodeErrors = [];
72 foreach($palette as $k => $legacyIdMeta){
74 $id = $legacyIdMeta >> 4;
75 $meta = $legacyIdMeta & 0xf;
77 $newStateData = $this->blockDataUpgrader->upgradeIntIdMeta($id, $meta);
79 $blockDecodeErrors[] =
"Palette offset $k / Failed to upgrade legacy ID/meta $id:$meta: " . $e->getMessage();
80 $newStateData = GlobalBlockStateHandlers::getUnknownBlockStateData();
84 $newPalette[$k] = $this->blockStateDeserializer->deserialize($newStateData);
87 $blockDecodeErrors[] =
"Palette offset $k / Failed to deserialize upgraded state $id:$meta: " . $e->getMessage();
88 $newPalette[$k] = $this->blockStateDeserializer->deserialize(GlobalBlockStateHandlers::getUnknownBlockStateData());
92 if(count($blockDecodeErrors) > 0){
93 $logger->
error(
"Errors decoding/upgrading blocks:\n - " . implode(
"\n - ", $blockDecodeErrors));
97 return PalettedBlockArray::fromData(
98 $blockArray->getBitsPerBlock(),
99 $blockArray->getWordArray(),
104 protected function palettizeLegacySubChunkXZY(
string $idArray,
string $metaArray, \
Logger $logger) : PalettedBlockArray{
105 return $this->translatePalette(SubChunkConverter::convertSubChunkXZY($idArray, $metaArray), $logger);
108 protected function palettizeLegacySubChunkYZX(
string $idArray,
string $metaArray, \
Logger $logger) : PalettedBlockArray{
109 return $this->translatePalette(SubChunkConverter::convertSubChunkYZX($idArray, $metaArray), $logger);
112 protected function palettizeLegacySubChunkFromColumn(
string $idArray,
string $metaArray,
int $yOffset, \
Logger $logger) : PalettedBlockArray{
113 return $this->translatePalette(SubChunkConverter::convertSubChunkFromLegacyColumn($idArray, $metaArray, $yOffset), $logger);
116 public function getPath() : string{
121 return $this->worldData;