mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +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
|
||||
*/
|
||||
public function getTargetBlock(int $maxDistance, array $transparent = []){
|
||||
try{
|
||||
$block = $this->getLineOfSight($maxDistance, 1, $transparent)[0];
|
||||
if($block instanceof Block){
|
||||
return $block;
|
||||
}
|
||||
}catch(\ArrayOutOfBoundsException $e){
|
||||
$line = $this->getLineOfSight($maxDistance, 1, $transparent);
|
||||
if(!empty($line)){
|
||||
return array_shift($line);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
Loading…
x
Reference in New Issue
Block a user