public static @Nullable <T extends Entity> T closest(Entity targetEntity, List<T> entities) { return CollectionUtil.min( entities, entity -> entity.isDead || entity == targetEntity ? Double.MAX_VALUE : targetEntity.getDistanceSqToEntity(entity)) .orElse(null); }