Removed EmptySubChunk and SubChunkInterface

This commit is contained in:
Dylan K. Taylor 2020-10-31 23:10:31 +00:00
parent 13d7b7ee1a
commit e09d78238f
4 changed files with 10 additions and 130 deletions

View File

@ -505,17 +505,6 @@ class Chunk{
$this->dirtyFlags = 0; $this->dirtyFlags = 0;
} }
/**
* Returns the subchunk at the specified subchunk Y coordinate, or an empty, unmodifiable stub if it does not exist or the coordinate is out of range.
*/
public function getSubChunk(int $y) : SubChunkInterface{
if($y < 0 or $y >= $this->subChunks->getSize()){
return EmptySubChunk::getInstance(); //TODO: drop this and throw an exception here
}
return $this->subChunks[$y];
}
public function getSubChunkChecked(int $y) : SubChunk{ public function getSubChunkChecked(int $y) : SubChunk{
if($y < 0 || $y >= $this->subChunks->getSize()){ if($y < 0 || $y >= $this->subChunks->getSize()){
throw new \InvalidArgumentException("Invalid subchunk Y coordinate $y"); throw new \InvalidArgumentException("Invalid subchunk Y coordinate $y");

View File

@ -1,65 +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\world\format;
class EmptySubChunk implements SubChunkInterface{
/** @var EmptySubChunk */
private static $instance;
public static function getInstance() : self{
if(self::$instance === null){
self::$instance = new self();
}
return self::$instance;
}
public function isEmptyAuthoritative() : bool{
return true;
}
public function isEmptyFast() : bool{
return true;
}
public function getFullBlock(int $x, int $y, int $z) : int{
return 0;
}
public function getBlockLayers() : array{
return [];
}
public function getHighestBlockAt(int $x, int $z) : int{
return -1;
}
public function getBlockLightArray() : LightArray{
return LightArray::fill(0);
}
public function getBlockSkyLightArray() : LightArray{
return LightArray::fill(15);
}
}

View File

@ -26,7 +26,7 @@ namespace pocketmine\world\format;
use function array_values; use function array_values;
use function count; use function count;
class SubChunk implements SubChunkInterface{ class SubChunk{
/** @var int */ /** @var int */
private $defaultBlock; private $defaultBlock;
/** @var PalettedBlockArray[] */ /** @var PalettedBlockArray[] */
@ -50,11 +50,20 @@ class SubChunk implements SubChunkInterface{
$this->blockLight = $blockLight ?? LightArray::fill(0); $this->blockLight = $blockLight ?? LightArray::fill(0);
} }
/**
* Returns whether this subchunk contains any non-air blocks.
* This function will do a slow check, usually by garbage collecting first.
* This is typically useful for disk saving.
*/
public function isEmptyAuthoritative() : bool{ public function isEmptyAuthoritative() : bool{
$this->collectGarbage(); $this->collectGarbage();
return $this->isEmptyFast(); return $this->isEmptyFast();
} }
/**
* Returns a non-authoritative bool to indicate whether the chunk contains any blocks.
* This may report non-empty erroneously if the chunk has been modified and not garbage-collected.
*/
public function isEmptyFast() : bool{ public function isEmptyFast() : bool{
return count($this->blockLayers) === 0; return count($this->blockLayers) === 0;
} }

View File

@ -1,53 +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\world\format;
interface SubChunkInterface{
/**
* Returns whether this subchunk contains any non-air blocks.
* This function will do a slow check, usually by garbage collecting first.
* This is typically useful for disk saving.
*/
public function isEmptyAuthoritative() : bool;
/**
* Returns a non-authoritative bool to indicate whether the chunk contains any blocks.
* This may report non-empty erroneously if the chunk has been modified and not garbage-collected.
*/
public function isEmptyFast() : bool;
public function getFullBlock(int $x, int $y, int $z) : int;
/**
* @return PalettedBlockArray[]
*/
public function getBlockLayers() : array;
public function getHighestBlockAt(int $x, int $z) : int;
public function getBlockSkyLightArray() : LightArray;
public function getBlockLightArray() : LightArray;
}