Skip to content

Commit 3cd6ebd

Browse files
committed
ref: friends targeting
1 parent 04ae067 commit 3cd6ebd

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

common/src/main/kotlin/com/lambda/config/groups/Targeting.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ package com.lambda.config.groups
1919

2020
import com.lambda.config.Configurable
2121
import com.lambda.context.SafeContext
22+
import com.lambda.friend.FriendManager.isFriend
2223
import com.lambda.interaction.rotation.Rotation.Companion.dist
2324
import com.lambda.interaction.rotation.Rotation.Companion.rotation
2425
import com.lambda.interaction.rotation.Rotation.Companion.rotationTo
2526
import com.lambda.threading.runSafe
2627
import com.lambda.util.math.VecUtils.distSq
27-
import com.lambda.util.world.entitySearch
28+
import com.lambda.util.world.fastEntitySearch
2829
import net.minecraft.client.network.ClientPlayerEntity
2930
import net.minecraft.entity.LivingEntity
3031
import net.minecraft.entity.decoration.ArmorStandEntity
3132
import net.minecraft.entity.mob.MobEntity
3233
import 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)

common/src/main/kotlin/com/lambda/config/groups/TargetingConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface TargetingConfig {
2121
val targetingRange: Double
2222

2323
val players: Boolean
24+
val friends: Boolean
2425
val hostiles: Boolean
2526
val animals: Boolean
2627

common/src/main/kotlin/com/lambda/module/modules/combat/KillAura.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ object KillAura : Module(
130130
}
131131

132132
listener<TickEvent.Pre> {
133-
target = targeting.getTarget()
133+
target = targeting.target()
134134
if (!timerSync) attackTicks++
135135

136136
target?.let { entity ->

0 commit comments

Comments
 (0)