path = $path; $this->worldData = $this->loadLevelData(); } /** * @return WorldData * @throws CorruptedWorldException * @throws UnsupportedWorldFormatException */ abstract protected function loadLevelData() : WorldData; public function getPath() : string{ return $this->path; } /** * @return WorldData */ public function getWorldData() : WorldData{ return $this->worldData; } /** * @param int $chunkX * @param int $chunkZ * * @return Chunk|null * @throws CorruptedChunkException */ public function loadChunk(int $chunkX, int $chunkZ) : ?Chunk{ return $this->readChunk($chunkX, $chunkZ); } public function saveChunk(Chunk $chunk) : void{ if(!$chunk->isGenerated()){ throw new \InvalidStateException("Cannot save un-generated chunk"); } $this->writeChunk($chunk); } /** * @param int $chunkX * @param int $chunkZ * * @return Chunk|null * @throws CorruptedChunkException */ abstract protected function readChunk(int $chunkX, int $chunkZ) : ?Chunk; abstract protected function writeChunk(Chunk $chunk) : void; }