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{
70 $palette = $blockArray->getPalette();
73 $blockDecodeErrors = [];
74 foreach($palette as $k => $legacyIdMeta){
76 $id = $legacyIdMeta >> 4;
77 $meta = $legacyIdMeta & 0xf;
79 $newStateData = $this->blockDataUpgrader->upgradeIntIdMeta($id, $meta);
81 $blockDecodeErrors[] =
"Palette offset $k / Failed to upgrade legacy ID/meta $id:$meta: " . $e->getMessage();
82 $newStateData = GlobalBlockStateHandlers::getUnknownBlockStateData();
86 $newPalette[$k] = $this->blockStateDeserializer->deserialize($newStateData);
89 $blockDecodeErrors[] =
"Palette offset $k / Failed to deserialize upgraded state $id:$meta: " . $e->getMessage();
90 $newPalette[$k] = $this->blockStateDeserializer->deserialize(GlobalBlockStateHandlers::getUnknownBlockStateData());
94 if(count($blockDecodeErrors) > 0){
95 $logger->
error(
"Errors decoding/upgrading blocks:\n - " . implode(
"\n - ", $blockDecodeErrors));
99 return PalettedBlockArray::fromData(
100 $blockArray->getBitsPerBlock(),
101 $blockArray->getWordArray(),
106 protected function palettizeLegacySubChunkXZY(
string $idArray,
string $metaArray, \
Logger $logger) : PalettedBlockArray{
107 return $this->translatePalette(SubChunkConverter::convertSubChunkXZY($idArray, $metaArray), $logger);
110 protected function palettizeLegacySubChunkYZX(
string $idArray,
string $metaArray, \
Logger $logger) : PalettedBlockArray{
111 return $this->translatePalette(SubChunkConverter::convertSubChunkYZX($idArray, $metaArray), $logger);
114 protected function palettizeLegacySubChunkFromColumn(
string $idArray,
string $metaArray,
int $yOffset, \
Logger $logger) : PalettedBlockArray{
115 return $this->translatePalette(SubChunkConverter::convertSubChunkFromLegacyColumn($idArray, $metaArray, $yOffset), $logger);
118 public function getPath() : string{
123 return $this->worldData;