public static function getCrosshairTarget(Entity $entity, $accuracy = 0.5, $max = PHP_INT_MAX)
{
$found = null;
$direction = $entity->getDirectionVector()->multiply($accuracy);
/** @var Vector3 $last */
for ($last = null, $pos = $entity->add($direction), $i = 1; $i * $accuracy <= $max; $last = $pos->floor(), $pos = $entity->add($direction->multiply(++$i))) {
if ($last instanceof Vector3) {
if ($last->x === $pos->getFloorX() and $last->y === $pos->getFloorY() and $last->z === $pos->getFloorZ()) {
continue;
}
if ($pos->y < 0) {
break;
}
$maxY = 127;
if (defined($path = "pemapmodder\\worldeditart\\MAX_WORLD_HEIGHT")) {
$maxY = constant($path);
}
if ($pos->y > $maxY + 1) {
break;
}
$block = $entity->getLevel()->getBlock($pos);
if (!$block instanceof Block) {
break;
}
if ($block instanceof Air) {
continue;
}
$found = $block;
break;
}
}
return $found;
}