Removed Anvil RegionLoader, made mcregion RegionLoader usable for anything

This commit is contained in:
Dylan K. Taylor 2016-12-22 18:25:18 +00:00
parent 29c27993ad
commit 8ee3723588
4 changed files with 16 additions and 64 deletions

View File

@ -28,6 +28,7 @@ use pocketmine\level\format\LevelProvider;
use pocketmine\level\format\generic\GenericChunk;
use pocketmine\level\format\generic\SubChunk;
use pocketmine\level\format\mcregion\McRegion;
use pocketmine\level\format\mcregion\RegionLoader;
use pocketmine\level\Level;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\{ByteArrayTag, ByteTag, CompoundTag, IntArrayTag, IntTag, ListTag, LongTag};
@ -39,6 +40,8 @@ use pocketmine\utils\MainLogger;
class Anvil extends McRegion{
const REGION_FILE_EXTENSION = "mca";
public function nbtSerialize(GenericChunk $chunk) : string{
$nbt = new CompoundTag("Level", []);
$nbt->xPos = new IntTag("xPos", $chunk->getX());
@ -155,12 +158,6 @@ class Anvil extends McRegion{
}
}
/** @var RegionLoader[] */
protected $regions = [];
/** @var Chunk[] */
protected $chunks = [];
public static function getProviderName() : string{
return "anvil";
}
@ -171,7 +168,7 @@ class Anvil extends McRegion{
if($isValid){
$files = glob($path . "/region/*.mc*");
foreach($files as $f){
if(strpos($f, ".mcr") !== false){ //McRegion
if(strpos($f, "." . McRegion::REGION_FILE_EXTENSION) !== false){
$isValid = false;
break;
}
@ -186,19 +183,4 @@ class Anvil extends McRegion{
return 256;
}
/**
* @param int $x
* @param int $z
*
* @return RegionLoader
*/
protected function getRegion(int $x, int $z){
return $this->regions[Level::chunkHash($x, $z)] ?? null;
}
protected function loadRegion(int $x, int $z){
if(!isset($this->regions[$index = Level::chunkHash($x, $z)])){
$this->regions[$index] = new RegionLoader($this, $x, $z);
}
}
}

View File

@ -1,33 +0,0 @@
<?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\level\format\anvil;
use pocketmine\level\format\LevelProvider;
class RegionLoader extends \pocketmine\level\format\mcregion\RegionLoader{
public function __construct(LevelProvider $level, int $regionX, int $regionZ){
parent::__construct($level, $regionX, $regionZ, "mca");
}
}

View File

@ -23,6 +23,7 @@ declare(strict_types = 1);
namespace pocketmine\level\format\mcregion;
use pocketmine\level\format\anvil\Anvil;
use pocketmine\level\format\Chunk;
use pocketmine\level\format\LevelProvider;
use pocketmine\level\format\generic\GenericChunk;
@ -38,6 +39,14 @@ use pocketmine\utils\MainLogger;
class McRegion extends BaseLevelProvider{
const REGION_FILE_EXTENSION = "mcr";
/** @var RegionLoader[] */
protected $regions = [];
/** @var GenericChunk[] */
protected $chunks = [];
/**
* @param GenericChunk $chunk
*
@ -188,12 +197,6 @@ class McRegion extends BaseLevelProvider{
}
}
/** @var RegionLoader[] */
protected $regions = [];
/** @var Chunk[] */
protected $chunks = [];
public static function getProviderName() : string{
return "mcregion";
}
@ -209,7 +212,7 @@ class McRegion extends BaseLevelProvider{
if($isValid){
$files = glob($path . "/region/*.mc*");
foreach($files as $f){
if(strpos($f, ".mca") !== false){ //Anvil
if(strpos($f, "." . Anvil::REGION_FILE_EXTENSION) !== false){
$isValid = false;
break;
}
@ -420,7 +423,7 @@ class McRegion extends BaseLevelProvider{
*/
protected function loadRegion(int $x, int $z){
if(!isset($this->regions[$index = Level::chunkHash($x, $z)])){
$this->regions[$index] = new RegionLoader($this, $x, $z);
$this->regions[$index] = new RegionLoader($this, $x, $z, static::REGION_FILE_EXTENSION);
}
}

View File

@ -47,7 +47,7 @@ class RegionLoader{
public $lastUsed;
public function __construct(LevelProvider $level, int $regionX, int $regionZ, string $fileExtension = "mcr"){
public function __construct(LevelProvider $level, int $regionX, int $regionZ, string $fileExtension = McRegion::REGION_FILE_EXTENSION){
$this->x = $regionX;
$this->z = $regionZ;
$this->levelProvider = $level;