mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-23 03:16:35 +00:00
Separate writable parts of RegionWorldProvider into WritableRegionWorldProvider
This commit is contained in:
parent
e6fb6b1f27
commit
08f0c9a244
@ -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),
|
||||
|
@ -46,11 +46,6 @@ use function zlib_decode;
|
||||
* @internal
|
||||
*/
|
||||
trait LegacyAnvilChunkTrait{
|
||||
|
||||
protected function serializeChunk(Chunk $chunk) : string{
|
||||
throw new \RuntimeException("Unsupported");
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws CorruptedChunkException
|
||||
*/
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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(
|
||||
|
58
src/world/format/io/region/WritableRegionWorldProvider.php
Normal file
58
src/world/format/io/region/WritableRegionWorldProvider.php
Normal 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));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user