World: prevent getHighestAdjacentBlockLight() and getHighestAdjacentBlockSkyLight() trying to exceed world bounds

this creates a problem for sky light above y=256, but this problem exists in lots of other places already anyway.
This commit is contained in:
Dylan K. Taylor 2019-10-22 20:54:54 +01:00
parent 9d3637c999
commit b8c857df64

View File

@ -1354,14 +1354,21 @@ class World implements ChunkManager{
* @return int * @return int
*/ */
public function getHighestAdjacentBlockSkyLight(int $x, int $y, int $z) : int{ public function getHighestAdjacentBlockSkyLight(int $x, int $y, int $z) : int{
return max([ $max = 0;
$this->getBlockSkyLightAt($x + 1, $y, $z), foreach([
$this->getBlockSkyLightAt($x - 1, $y, $z), [$x + 1, $y, $z],
$this->getBlockSkyLightAt($x, $y + 1, $z), [$x - 1, $y, $z],
$this->getBlockSkyLightAt($x, $y - 1, $z), [$x, $y + 1, $z],
$this->getBlockSkyLightAt($x, $y, $z + 1), [$x, $y - 1, $z],
$this->getBlockSkyLightAt($x, $y, $z - 1) [$x, $y, $z + 1],
]); [$x, $y, $z - 1]
] as [$x1, $y1, $z1]){
if(!$this->isInWorld($x1, $y1, $z1)){
continue;
}
$max = max($max, $this->getBlockSkyLightAt($x1, $y1, $z1));
}
return $max;
} }
public function updateBlockSkyLight(int $x, int $y, int $z){ public function updateBlockSkyLight(int $x, int $y, int $z){
@ -1385,14 +1392,21 @@ class World implements ChunkManager{
* @return int * @return int
*/ */
public function getHighestAdjacentBlockLight(int $x, int $y, int $z) : int{ public function getHighestAdjacentBlockLight(int $x, int $y, int $z) : int{
return max([ $max = 0;
$this->getBlockLightAt($x + 1, $y, $z), foreach([
$this->getBlockLightAt($x - 1, $y, $z), [$x + 1, $y, $z],
$this->getBlockLightAt($x, $y + 1, $z), [$x - 1, $y, $z],
$this->getBlockLightAt($x, $y - 1, $z), [$x, $y + 1, $z],
$this->getBlockLightAt($x, $y, $z + 1), [$x, $y - 1, $z],
$this->getBlockLightAt($x, $y, $z - 1) [$x, $y, $z + 1],
]); [$x, $y, $z - 1]
] as [$x1, $y1, $z1]){
if(!$this->isInWorld($x1, $y1, $z1)){
continue;
}
$max = max($max, $this->getBlockLightAt($x1, $y1, $z1));
}
return $max;
} }
public function updateBlockLight(int $x, int $y, int $z){ public function updateBlockLight(int $x, int $y, int $z){