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