targets = mc.theWorld.loadedEntityList
.stream()
.filter(entity -> entity instanceof EntityLivingBase)
.map(entity -> (EntityLivingBase) entity)
.filter(entity -> {
if (entity instanceof EntityPlayer && !player.getValue()) {
return false;
}
if (entity instanceof EntityAnimal && !animals.getValue()) {
return false;
}
if (entity instanceof EntityMob && !mobs.getValue()) {
return false;
}
if (entity.isInvisible() && !invisibles.getValue()) {
return false;
}
if (entity.deathTime != 0 || entity.isDead) {
return false;
}
if (mc.thePlayer.getDistanceToEntity(entity) > range.getValue().doubleValue()) {
return false;
}
return entity != mc.thePlayer;
})
.sorted(Comparator.comparingDouble(entity -> mc.thePlayer.getDistanceToEntity(entity)))
.collect(Collectors.toList());
target = targets.isEmpty() ? null : targets.get(0);