World: don't create an empty chunk just for accessing the highest block

this is pointless since the chunk will not be generated anyway, so it serves no end to create it.
This commit is contained in:
Dylan K. Taylor 2020-10-31 21:27:16 +00:00
parent f0d62cf4ce
commit de867f1b86

View File

@ -2032,10 +2032,13 @@ class World implements ChunkManager{
/**
* Gets the highest block Y value at a specific $x and $z
*
* @return int 0-255
* @return int 0-255, or -1 if the chunk is not generated
*/
public function getHighestBlockAt(int $x, int $z) : int{
return $this->getOrLoadChunk($x >> 4, $z >> 4, true)->getHighestBlockAt($x & 0x0f, $z & 0x0f);
if(($chunk = $this->getOrLoadChunk($x >> 4, $z >> 4, false)) !== null){
return $chunk->getHighestBlockAt($x & 0x0f, $z & 0x0f);
}
return -1; //TODO: this should probably throw an exception (terrain not generated yet)
}
/**