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:
Dylan K. Taylor 2018-05-09 17:11:37 +01:00
parent 2ff2a2de08
commit 5c66c615bf

View File

@ -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;