mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-10 05:34:54 +00:00
Living: fix possible crash in getTargetBlock()
ArrayOutOfBoundsException is not thrown by SPL anymore since the exception handler throwing it was removed by @shoghicp. Regardless, it seems cleaner to to check it properly.
This commit is contained in:
parent
2ff2a2de08
commit
5c66c615bf
@ -816,12 +816,9 @@ abstract class Living extends Entity implements Damageable{
|
|||||||
* @return Block|null
|
* @return Block|null
|
||||||
*/
|
*/
|
||||||
public function getTargetBlock(int $maxDistance, array $transparent = []){
|
public function getTargetBlock(int $maxDistance, array $transparent = []){
|
||||||
try{
|
$line = $this->getLineOfSight($maxDistance, 1, $transparent);
|
||||||
$block = $this->getLineOfSight($maxDistance, 1, $transparent)[0];
|
if(!empty($line)){
|
||||||
if($block instanceof Block){
|
return array_shift($line);
|
||||||
return $block;
|
|
||||||
}
|
|
||||||
}catch(\ArrayOutOfBoundsException $e){
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user