Skip to content

Commit f56ac5e

Browse files
committed
ref: kdoc
1 parent 93c942a commit f56ac5e

File tree

2 files changed

+130
-21
lines changed

2 files changed

+130
-21
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,28 @@ class RotationSettings(
99
c: Configurable,
1010
vis: () -> Boolean = { true },
1111
) : IRotationConfig {
12+
/**
13+
* The rotation mode
14+
*/
1215
override var rotationMode by c.setting(
1316
"Mode",
1417
RotationMode.SYNC,
1518
"SILENT - server-side rotation, SYNC - server-side rotation; client-side movement, LOCK - Lock camera",
1619
vis
1720
)
1821

22+
/**
23+
* How many ticks to keep the rotation before resetting
24+
*/
1925
override val keepTicks by c.setting("Keep Rotation", 3, 0..10, 1, "Ticks to keep rotation", " ticks", vis)
26+
27+
/**
28+
* How many ticks to wait before resetting the rotation
29+
*/
2030
override val resetTicks by c.setting("Reset Rotation", 3, 1..10, 1, "Ticks before rotation is reset", " ticks", vis)
2131

2232
/**
23-
* If true, rotation will be instant without any transition. If false, rotation will transition over time.
33+
* Whether the rotation is instant
2434
*/
2535
var instant by c.setting("Instant Rotation", true, "Instantly rotate", vis)
2636

@@ -51,8 +61,8 @@ class RotationSettings(
5161
) { vis() && !instant }
5262

5363
/**
54-
* We always have to pass turn speed to the interpolator, because player's yaw could be out of -180..180 range and
55-
* Thus we cant simply assign new angles to the player's rotation without getting flagged by Grim's AimModulo360 check
64+
* We must always provide turn speed to the interpolator because the player's yaw might exceed the -180 to 180 range.
65+
* Therefore, we cannot simply assign new angles to the player's rotation without getting flagged by Grim's AimModulo360 check.
5666
*/
5767
override val turnSpeed get() = if (instant) 180.0 else abs(mean + spread * nextRandom())
5868

@@ -64,4 +74,4 @@ class RotationSettings(
6474

6575
return sqrt(-2.0 * ln(u1)) * cos(2.0 * PI * u2)
6676
}
67-
}
77+
}

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

Lines changed: 116 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,78 @@ import net.minecraft.entity.LivingEntity
1313
import net.minecraft.entity.mob.MobEntity
1414
import net.minecraft.entity.passive.PassiveEntity
1515

16+
/**
17+
* Abstract class representing a targeting mechanism for entities in the game.
18+
*
19+
* This class provides the configuration and validation for targeting different types of entities
20+
* based on player settings and entity characteristics. It allows for specifying which types of entities
21+
* are targetable, the range of targeting, and various other conditions for targeting.
22+
*
23+
* @property owner The [Configurable] instance used to get and set configuration options for targeting.
24+
* @property predicate The predicate used to determine whether the targeting settings are visible and active.
25+
* @property defaultRange The default range within which entities can be targeted.
26+
* @property maxRange The maximum range within which entities can be targeted.
27+
*/
1628
abstract class Targeting(
17-
c: Configurable,
18-
vis: () -> Boolean = { true },
29+
owner: Configurable,
30+
predicate: () -> Boolean = { true },
1931
defaultRange: Double,
2032
maxRange: Double
2133
) : TargetingConfig {
22-
override val targetingRange by c.setting("Targeting Range", defaultRange, 1.0..maxRange, 0.05) { vis() }
2334

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 }
35+
/**
36+
* The range within which entities can be targeted. This value is configurable and constrained
37+
* between 1.0 and [maxRange].
38+
*/
39+
override val targetingRange by owner.setting("Targeting Range", defaultRange, 1.0..maxRange, 0.05) { predicate() }
40+
41+
/**
42+
* Whether players are included in the targeting scope.
43+
*/
44+
override val players by owner.setting("Players", true) { predicate() }
45+
46+
/**
47+
* Whether mobs are included in the targeting scope.
48+
*/
49+
private val mobs by owner.setting("Mobs", true) { predicate() }
50+
51+
/**
52+
* Whether hostile mobs are included in the targeting scope
53+
*/
54+
private val hostilesSetting by owner.setting("Hostiles", true) { predicate() && mobs }
55+
56+
/**
57+
* Whether passive animals are included in the targeting scope
58+
*/
59+
private val animalsSetting by owner.setting("Animals", true) { predicate() && mobs }
60+
61+
/**
62+
* Indicates whether hostile entities are included in the targeting scope.
63+
*/
2864
override val hostiles get() = mobs && hostilesSetting
65+
66+
/**
67+
* Indicates whether passive animals are included in the targeting scope.
68+
*/
2969
override val animals get() = mobs && animalsSetting
3070

31-
override val invisible by c.setting("Invisible", true) { vis() }
32-
override val dead by c.setting("Dead", false) { vis() }
71+
/**
72+
* Whether invisible entities are included in the targeting scope.
73+
*/
74+
override val invisible by owner.setting("Invisible", true) { predicate() }
3375

76+
/**
77+
* Whether dead entities are included in the targeting scope.
78+
*/
79+
override val dead by owner.setting("Dead", false) { predicate() }
80+
81+
/**
82+
* Validates whether a given entity is targetable by the player based on current settings.
83+
*
84+
* @param player The [ClientPlayerEntity] performing the targeting.
85+
* @param entity The [LivingEntity] being evaluated.
86+
* @return `true` if the entity is valid for targeting, `false` otherwise.
87+
*/
3488
open fun validate(player: ClientPlayerEntity, entity: LivingEntity) = when {
3589
!players && entity.isPlayer -> false
3690
!animals && entity is PassiveEntity -> false
@@ -42,18 +96,44 @@ abstract class Targeting(
4296
else -> true
4397
}
4498

99+
/**
100+
* Subclass for targeting entities specifically for combat purposes.
101+
*
102+
* @property fov The field of view limit within which entities are considered for targeting. Configurable.
103+
* @property priority The priority used to determine which entity is targeted when multiple candidates are available.
104+
*/
45105
class Combat(
46-
c: Configurable,
47-
vis: () -> Boolean = { true },
48-
) : Targeting(c, vis, 5.0, 16.0) {
49-
val fov by c.setting("FOV Limit", 180, 5..180, 1) { vis() }
50-
val priority by c.setting("Priority", Priority.DISTANCE) { vis() }
106+
owner: Configurable,
107+
predicate: () -> Boolean = { true },
108+
) : Targeting(owner, predicate, 5.0, 16.0) {
109+
110+
/**
111+
* The field of view limit for targeting entities. Configurable between 5 and 180 degrees.
112+
*/
113+
val fov by owner.setting("FOV Limit", 180, 5..180, 1) { predicate() }
114+
115+
/**
116+
* The priority used to determine which entity is targeted. Configurable with default set to [Priority.DISTANCE].
117+
*/
118+
val priority by owner.setting("Priority", Priority.DISTANCE) { predicate() }
51119

120+
/**
121+
* Validates whether a given entity is targetable for combat based on the field of view limit and other settings.
122+
*
123+
* @param player The [ClientPlayerEntity] performing the targeting.
124+
* @param entity The [LivingEntity] being evaluated.
125+
* @return `true` if the entity is valid for targeting, `false` otherwise.
126+
*/
52127
override fun validate(player: ClientPlayerEntity, entity: LivingEntity): Boolean {
53128
if (fov < 180 && player.rotation dist player.eyePos.rotationTo(entity.pos) > fov) return false
54129
return super.validate(player, entity)
55130
}
56131

132+
/**
133+
* Gets the best target for combat based on the current settings and priority.
134+
*
135+
* @return The best [LivingEntity] target, or `null` if no valid target is found.
136+
*/
57137
fun getTarget(): LivingEntity? = runSafe {
58138
val predicate = { entity: LivingEntity ->
59139
validate(player, entity)
@@ -67,15 +147,34 @@ abstract class Targeting(
67147
}
68148
}
69149

150+
/**
151+
* Subclass for targeting entities for ESP (Extrasensory Perception) purposes.
152+
*/
70153
class ESP(
71-
c: Configurable,
72-
vis: () -> Boolean = { true },
73-
) : Targeting(c, vis, 128.0, 1024.0)
154+
owner: Configurable,
155+
predicate: () -> Boolean = { true },
156+
) : Targeting(owner, predicate, 128.0, 1024.0)
74157

158+
/**
159+
* Enum representing the different priority factors used for determining the best target.
160+
*
161+
* @property factor A lambda function that calculates the priority factor for a given [LivingEntity].
162+
*/
75163
@Suppress("Unused")
76164
enum class Priority(val factor: SafeContext.(LivingEntity) -> Double) {
165+
/**
166+
* Prioritizes entities based on their distance from the player.
167+
*/
77168
DISTANCE({ player.pos distSq it.pos }),
169+
170+
/**
171+
* Prioritizes entities based on their health.
172+
*/
78173
HEALTH({ it.health.toDouble() }),
174+
175+
/**
176+
* Prioritizes entities based on their angle relative to the player's field of view.
177+
*/
79178
FOV({ player.rotation dist player.eyePos.rotationTo(it.pos) })
80179
}
81180
}

0 commit comments

Comments
 (0)