for (final T other : type == null ? (List<T>) entity.getWorld().getEntities() : entity.getWorld().getEntitiesByClass(type.getType())) {
if (other == null || other == entity || type != null && !type.isInstance(other))
continue;
if (target == null || targetDistanceSquared > other.getLocation().distanceSquared(entity.getLocation())) {
final Vector t = other.getLocation().add(0, 1, 0).toVector().subtract(l);
if (n.clone().crossProduct(t).lengthSquared() < radiusSquared && t.normalize().dot(n) >= cos45) {
target = other;
targetDistanceSquared = target.getLocation().distanceSquared(entity.getLocation());
}
}
}