mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-19 12:15:32 +00:00
Use Chunk::getSubChunkChecked() in places where we know that an invalid coordinate cannot be requested
This commit is contained in:
parent
b270029161
commit
01001dca74
@ -43,7 +43,7 @@ final class ChunkSerializer{
|
||||
*/
|
||||
public static function getSubChunkCount(Chunk $chunk) : int{
|
||||
for($count = $chunk->getSubChunks()->count(); $count > 0; --$count){
|
||||
if($chunk->getSubChunk($count - 1)->isEmptyFast()){
|
||||
if($chunk->getSubChunkChecked($count - 1)->isEmptyFast()){
|
||||
continue;
|
||||
}
|
||||
return $count;
|
||||
@ -56,7 +56,7 @@ final class ChunkSerializer{
|
||||
$stream = new PacketSerializer();
|
||||
$subChunkCount = self::getSubChunkCount($chunk);
|
||||
for($y = 0; $y < $subChunkCount; ++$y){
|
||||
$layers = $chunk->getSubChunk($y)->getBlockLayers();
|
||||
$layers = $chunk->getSubChunkChecked($y)->getBlockLayers();
|
||||
$stream->putByte(8); //version
|
||||
|
||||
$stream->putByte(count($layers));
|
||||
|
@ -166,7 +166,7 @@ class Chunk{
|
||||
*/
|
||||
public function getHighestBlockAt(int $x, int $z) : int{
|
||||
for($y = $this->subChunks->count() - 1; $y >= 0; --$y){
|
||||
$height = $this->getSubChunk($y)->getHighestBlockAt($x, $z) | ($y << 4);
|
||||
$height = $this->getSubChunkChecked($y)->getHighestBlockAt($x, $z) | ($y << 4);
|
||||
if($height !== -1){
|
||||
return $height;
|
||||
}
|
||||
@ -204,7 +204,7 @@ class Chunk{
|
||||
public function recalculateHeightMap(\SplFixedArray $directSkyLightBlockers) : void{
|
||||
$maxSubChunkY = $this->subChunks->count() - 1;
|
||||
for(; $maxSubChunkY >= 0; $maxSubChunkY--){
|
||||
if(!$this->getSubChunk($maxSubChunkY)->isEmptyFast()){
|
||||
if(!$this->getSubChunkChecked($maxSubChunkY)->isEmptyFast()){
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -217,7 +217,7 @@ class Chunk{
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
$y = null;
|
||||
for($subChunkY = $maxSubChunkY; $subChunkY >= 0; $subChunkY--){
|
||||
$subHighestBlockY = $this->getSubChunk($subChunkY)->getHighestBlockAt($x, $z);
|
||||
$subHighestBlockY = $this->getSubChunkChecked($subChunkY)->getHighestBlockAt($x, $z);
|
||||
if($subHighestBlockY !== -1){
|
||||
$y = ($subChunkY * 16) + $subHighestBlockY;
|
||||
break;
|
||||
|
@ -27,7 +27,6 @@ use pocketmine\utils\Utils;
|
||||
use pocketmine\world\ChunkManager;
|
||||
use pocketmine\world\format\Chunk;
|
||||
use pocketmine\world\format\SubChunk;
|
||||
use function assert;
|
||||
|
||||
class SubChunkExplorer{
|
||||
/** @var ChunkManager */
|
||||
@ -78,9 +77,7 @@ class SubChunkExplorer{
|
||||
return SubChunkExplorerStatus::INVALID;
|
||||
}
|
||||
|
||||
$newSubChunk = $this->currentChunk->getSubChunk($y >> 4);
|
||||
assert($newSubChunk instanceof SubChunk, "chunk inside valid bounds should always be a SubChunk instance");
|
||||
$this->currentSubChunk = $newSubChunk;
|
||||
$this->currentSubChunk = $this->currentChunk->getSubChunkChecked($y >> 4);
|
||||
if($this->onSubChunkChangeFunc !== null){
|
||||
($this->onSubChunkChangeFunc)();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user