1+ package com.lambda.config.groups
2+
3+ import com.lambda.config.Configurable
4+ import com.lambda.context.SafeContext
5+ import com.lambda.interaction.rotation.Rotation.Companion.dist
6+ import com.lambda.interaction.rotation.Rotation.Companion.rotation
7+ import com.lambda.interaction.rotation.Rotation.Companion.rotationTo
8+ import com.lambda.threading.runSafe
9+ import com.lambda.util.math.VecUtils.distSq
10+ import com.lambda.util.world.WorldUtils.getFastEntities
11+ import net.minecraft.client.network.ClientPlayerEntity
12+ import net.minecraft.entity.LivingEntity
13+ import net.minecraft.entity.mob.MobEntity
14+ import net.minecraft.entity.passive.PassiveEntity
15+
16+ abstract class Targeting (
17+ c : Configurable ,
18+ vis : () -> Boolean = { true },
19+ defaultRange : Double ,
20+ maxRange : Double
21+ ) : TargetingConfig {
22+ override val targetingRange by c.setting(" Targeting Range" , defaultRange, 1.0 .. maxRange, 0.05 ) { vis() }
23+
24+ override val players by c.setting(" Players" , true ) { vis() }
25+ private val mobs by c.setting(" Mobs" , true ) { vis() }
26+ private val hostilesSetting by c.setting(" Hostiles" , true ) { vis() && mobs }
27+ private val animalsSetting by c.setting(" Animals" , true ) { vis() && mobs }
28+ override val hostiles get() = mobs && hostilesSetting
29+ override val animals get() = mobs && animalsSetting
30+
31+ override val invisible by c.setting(" Invisible" , true ) { vis() }
32+ override val dead by c.setting(" Dead" , false ) { vis() }
33+
34+ fun getEntities (): List <LivingEntity > =
35+ mutableListOf<LivingEntity >().apply {
36+ runSafe {
37+ getFastEntities(
38+ player.pos, targetingRange, this @apply,
39+ predicate = { entity -> validate(player, entity) }
40+ )
41+ }
42+ }
43+
44+ open fun validate (player : ClientPlayerEntity , entity : LivingEntity ) = when {
45+ ! players && entity.isPlayer -> false
46+ ! animals && entity is PassiveEntity -> false
47+ ! hostiles && entity is MobEntity -> false
48+
49+ ! invisible && entity.isInvisibleTo(player) -> false
50+ ! dead && entity.isDead -> false
51+
52+ else -> true
53+ }
54+
55+ class Combat (
56+ c : Configurable ,
57+ vis : () -> Boolean = { true },
58+ ) : Targeting(c, vis, 5.0 , 16.0 ) {
59+ val fov by c.setting(" FOV Limit" , 180 , 5 .. 180 , 1 ) { vis() }
60+ val priority by c.setting(" Priority" , Priority .DISTANCE ) { vis() }
61+
62+ override fun validate (player : ClientPlayerEntity , entity : LivingEntity ): Boolean {
63+ if (fov < 180 && player.rotation dist player.eyePos.rotationTo(entity.pos) > fov) return false
64+ return super .validate(player, entity)
65+ }
66+
67+ fun getTarget (): LivingEntity ? = runSafe {
68+ var best: LivingEntity ? = null
69+ var bestFactor = Double .MAX_VALUE
70+
71+ val comparator = { entity: LivingEntity , _: Int ->
72+ val factor = priority.factor(this , entity)
73+ if (factor < bestFactor) {
74+ best = entity
75+ bestFactor = factor
76+ }
77+ }
78+
79+ val predicate = { entity: LivingEntity ->
80+ validate(player, entity)
81+ }
82+
83+ getFastEntities<LivingEntity >(player.pos, targetingRange, null , comparator, predicate)
84+
85+ return @runSafe best
86+ }
87+ }
88+
89+ class ESP (
90+ c : Configurable ,
91+ vis : () -> Boolean = { true },
92+ ) : Targeting(c, vis, 128.0 , 1024.0 )
93+
94+ @Suppress(" Unused" )
95+ enum class Priority (val factor : SafeContext .(LivingEntity ) -> Double ) {
96+ DISTANCE ({ player.pos distSq it.pos }),
97+ HEALTH ({ it.health.toDouble() }),
98+ FOV ({ player.rotation dist player.eyePos.rotationTo(it.pos) })
99+ }
100+ }
0 commit comments