@@ -19,17 +19,19 @@ package com.lambda.config.groups
1919
2020import com.lambda.config.Configurable
2121import com.lambda.context.SafeContext
22+ import com.lambda.friend.FriendManager.isFriend
2223import com.lambda.interaction.rotation.Rotation.Companion.dist
2324import com.lambda.interaction.rotation.Rotation.Companion.rotation
2425import com.lambda.interaction.rotation.Rotation.Companion.rotationTo
2526import com.lambda.threading.runSafe
2627import com.lambda.util.math.VecUtils.distSq
27- import com.lambda.util.world.entitySearch
28+ import com.lambda.util.world.fastEntitySearch
2829import net.minecraft.client.network.ClientPlayerEntity
2930import net.minecraft.entity.LivingEntity
3031import net.minecraft.entity.decoration.ArmorStandEntity
3132import net.minecraft.entity.mob.MobEntity
3233import net.minecraft.entity.passive.PassiveEntity
34+ import net.minecraft.server.network.ServerPlayerEntity
3335
3436/* *
3537 * Abstract class representing a targeting mechanism for entities in the game.
@@ -61,6 +63,12 @@ abstract class Targeting(
6163 */
6264 override val players by owner.setting(" Players" , true ) { predicate() }
6365
66+ /* *
67+ * Whether friends are included in the targeting scope.
68+ * Requires [players] to be true.
69+ */
70+ override val friends by owner.setting(" Friends" , false ) { predicate() && players }
71+
6472 /* *
6573 * Whether mobs are included in the targeting scope.
6674 */
@@ -104,7 +112,7 @@ abstract class Targeting(
104112 * @return `true` if the entity is valid for targeting, `false` otherwise.
105113 */
106114 open fun validate (player : ClientPlayerEntity , entity : LivingEntity ) = when {
107- ! players && entity.isPlayer -> false
115+ ! players && ( entity is ServerPlayerEntity && entity.isFriend) -> false
108116 ! animals && entity is PassiveEntity -> false
109117 ! hostiles && entity is MobEntity -> false
110118 entity is ArmorStandEntity -> false
@@ -153,12 +161,12 @@ abstract class Targeting(
153161 *
154162 * @return The best [LivingEntity] target, or `null` if no valid target is found.
155163 */
156- fun getTarget (): LivingEntity ? = runSafe {
164+ fun target (): LivingEntity ? = runSafe {
157165 val predicate = { entity: LivingEntity ->
158166 validate(player, entity)
159167 }
160168
161- return @runSafe entitySearch <LivingEntity >(targetingRange) {
169+ return @runSafe fastEntitySearch <LivingEntity >(targetingRange) {
162170 predicate(it)
163171 }.minByOrNull {
164172 priority.factor(this , it)
0 commit comments