Separate writable parts of RegionWorldProvider into WritableRegionWorldProvider

This commit is contained in:
Dylan K. Taylor 2021-04-15 15:20:57 +01:00
parent e6fb6b1f27
commit 08f0c9a244
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
5 changed files with 58 additions and 24 deletions

View File

@ -31,10 +31,6 @@ use pocketmine\world\format\SubChunk;
class Anvil extends RegionWorldProvider{
use LegacyAnvilChunkTrait;
protected function serializeSubChunk(SubChunk $subChunk) : CompoundTag{
throw new \RuntimeException("Unsupported");
}
protected function deserializeSubChunk(CompoundTag $subChunk) : SubChunk{
return new SubChunk(BlockLegacyIds::AIR << 4, [SubChunkConverter::convertSubChunkYZX(
self::readFixedSizeByteArray($subChunk, "Blocks", 4096),

View File

@ -46,11 +46,6 @@ use function zlib_decode;
* @internal
*/
trait LegacyAnvilChunkTrait{
protected function serializeChunk(Chunk $chunk) : string{
throw new \RuntimeException("Unsupported");
}
/**
* @throws CorruptedChunkException
*/

View File

@ -39,14 +39,6 @@ use pocketmine\world\format\SubChunk;
use function zlib_decode;
class McRegion extends RegionWorldProvider{
/**
* @throws \RuntimeException
*/
protected function serializeChunk(Chunk $chunk) : string{
throw new \RuntimeException("Unsupported");
}
/**
* @throws CorruptedChunkException
*/

View File

@ -163,8 +163,6 @@ abstract class RegionWorldProvider extends BaseWorldProvider{
}
}
abstract protected function serializeChunk(Chunk $chunk) : string;
/**
* @throws CorruptedChunkException
*/
@ -224,11 +222,6 @@ abstract class RegionWorldProvider extends BaseWorldProvider{
return null;
}
public function saveChunk(int $chunkX, int $chunkZ, Chunk $chunk) : void{
self::getRegionIndex($chunkX, $chunkZ, $regionX, $regionZ);
$this->loadRegion($regionX, $regionZ)->writeChunk($chunkX & 0x1f, $chunkZ & 0x1f, $this->serializeChunk($chunk));
}
private function createRegionIterator() : \RegexIterator{
return new \RegexIterator(
new \FilesystemIterator(

View File

@ -0,0 +1,58 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\world\format\io\region;
use pocketmine\world\format\Chunk;
use pocketmine\world\format\io\data\JavaWorldData;
use pocketmine\world\format\io\WritableWorldProvider;
use pocketmine\world\WorldCreationOptions;
use function file_exists;
use function mkdir;
/**
* This class implements the stuff needed for general region-based world providers to support saving.
* While this isn't used at the time of writing, it may come in useful if Java 1.13 Anvil support is ever implemented,
* or for a custom world format based on the region concept.
*/
abstract class WritableRegionWorldProvider extends RegionWorldProvider implements WritableWorldProvider{
public static function generate(string $path, string $name, WorldCreationOptions $options) : void{
if(!file_exists($path)){
mkdir($path, 0777, true);
}
if(!file_exists($path . "/region")){
mkdir($path . "/region", 0777);
}
JavaWorldData::generate($path, $name, $options, static::getPcWorldFormatVersion());
}
abstract protected function serializeChunk(Chunk $chunk) : string;
public function saveChunk(int $chunkX, int $chunkZ, Chunk $chunk) : void{
self::getRegionIndex($chunkX, $chunkZ, $regionX, $regionZ);
$this->loadRegion($regionX, $regionZ)->writeChunk($chunkX & 0x1f, $chunkZ & 0x1f, $this->serializeChunk($chunk));
}
}