Skip to content

Commit ae2c06f

Browse files
committed
Improved rotation settings. No range but Gaussian distribution
1 parent ebb61f8 commit ae2c06f

File tree

6 files changed

+36
-26
lines changed

6 files changed

+36
-26
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ interface IRotationConfig {
2626
*/
2727
val resetTicks: Int
2828

29+
/**
30+
* If true, rotation will be instant without any transition. If false, rotation will transition over time.
31+
*/
32+
val instant: Boolean
33+
34+
/**
35+
* The mean (average) value for the Gaussian distribution used to calculate rotation speed.
36+
* This value represents the center of the distribution.
37+
*/
2938
val mean: Double
39+
40+
/**
41+
* The standard deviation for the Gaussian distribution used to calculate rotation speed.
42+
* This value represents the spread or dispersion of the distribution.
43+
*/
3044
val derivation: Double
3145
}

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ package com.lambda.config.groups
22

33
import com.lambda.config.Configurable
44
import com.lambda.interaction.rotation.RotationMode
5-
import kotlin.math.PI
6-
import kotlin.math.cos
7-
import kotlin.math.ln
8-
import kotlin.math.sqrt
5+
import kotlin.math.*
96
import kotlin.random.Random
107

118
class RotationSettings(
@@ -15,18 +12,22 @@ class RotationSettings(
1512
override var rotationMode by c.setting("Mode", RotationMode.SYNC, "SILENT - server-side rotation, SYNC - server-side rotation; client-side movement, LOCK - Lock camera", vis)
1613
override val keepTicks by c.setting("Keep Rotation", 3, 1..10, 1, "Ticks to keep rotation", " ticks", vis)
1714
override val resetTicks by c.setting("Reset Rotation", 3, 1..10, 1, "Ticks before rotation is reset", " ticks", vis)
18-
override var mean by c.setting("Mean", 90.0, 1.0..180.0, 0.1, "Average rotation speed", "", vis)
19-
override var derivation by c.setting("Standard Deviation", 10.0, 0.0..100.0, 0.1, "Spread of rotation speeds", "", vis)
15+
override var instant by c.setting("Instant Rotation", false, "Instantly rotate", vis)
16+
override var mean by c.setting("Mean", 20.0, 1.0..80.0, 0.1, "Average rotation speed") { vis() && !instant }
17+
override var derivation by c.setting("Standard Deviation", 5.0, 0.0..20.0, 0.1, "Spread of rotation speeds") { vis() && !instant }
2018

21-
override val turnSpeed get() = nextGaussian(mean, derivation)
19+
override val turnSpeed get() = abs(nextGaussian(mean, derivation))
2220

2321
var speedMultiplier = 1.0
2422

25-
private fun nextGaussian(mean: Double = 0.0, standardDeviation: Double = 1.0): Double {
23+
private fun nextGaussian(
24+
mean: Double = 0.0,
25+
deviation: Double = 1.0
26+
): Double {
2627
val u1 = Random.nextDouble()
2728
val u2 = Random.nextDouble()
2829

2930
val randStdNormal = sqrt(-2.0 * ln(u1)) * cos(2.0 * PI * u2)
30-
return mean + standardDeviation * randStdNormal
31+
return mean + deviation * randStdNormal
3132
}
3233
}

common/src/main/kotlin/com/lambda/interaction/RotationManager.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ object RotationManager : Loadable {
8080
currentRotation = currentContext?.let { context ->
8181
val rotationTo = if (keepTicks >= 0) context.rotation else player.rotation
8282

83+
if (context.config.instant) {
84+
return@let rotationTo
85+
}
86+
8387
var speedMultiplier = (context.config as? RotationSettings)?.speedMultiplier ?: 1.0
8488
if (keepTicks < 0) speedMultiplier = 1.0
8589

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
package com.lambda.module.modules.client
22

3-
import com.lambda.config.groups.IRotationConfig
4-
import com.lambda.interaction.rotation.RotationMode
3+
import com.lambda.config.groups.RotationSettings
54
import com.lambda.module.Module
65
import com.lambda.module.tag.ModuleTag
7-
import com.lambda.util.math.MathUtils.random
86

97
object Baritone : Module(
108
name = "Baritone",
119
description = "Baritone configuration",
1210
defaultTags = setOf(ModuleTag.CLIENT)
1311
) {
14-
private val r1 by setting("Turn Speed 1", 70.0, 1.0..180.0, 0.1)
15-
private val r2 by setting("Turn Speed 2", 110.0, 1.0..180.0, 0.1)
16-
17-
val rotation = object : IRotationConfig {
18-
override val rotationMode = RotationMode.SYNC
19-
override val turnSpeed get() = random(r1, r2)
20-
override val keepTicks = 3
21-
override val resetTicks = 3
22-
}
12+
val rotation = RotationSettings(this)
2313
}

common/src/main/kotlin/com/lambda/module/modules/player/Freecam.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ object Freecam : Module(
3232
) {
3333
private val speed by setting("Speed", 0.5f, 0.1f..1.0f, 0.1f)
3434
private val sprint by setting("Sprint Multiplier", 3.0f, 0.1f..10.0f, 0.1f, description = "Set below 1.0 to fly slower on sprint.")
35+
private val reach by setting("Reach", 5.0, 1.0..100.0, 1.0, "Freecam reach distance")
3536
private val rotateToTarget by setting("Rotate to target", true)
36-
private val reach by setting("Reach", 4.0, 1.0..100.0, 0.1)
3737

38-
private val rotationConfig = RotationSettings(this).apply {
38+
private val rotationConfig = RotationSettings(this) {
39+
rotateToTarget
40+
}.apply {
3941
rotationMode = RotationMode.LOCK
4042
}
4143

common/src/main/kotlin/com/lambda/module/modules/player/Replay.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,14 @@ object Replay : Module(
5656
private val cycle by setting("Cycle Play Mode", KeyCode.B, description = "REPLAY: Replay the recording once. CONTINUE: Replay the recording and continue recording. LOOP: Loop the recording.")
5757
private val check by setting("Set Checkpoint", KeyCode.V, description = "Create a checkpoint while recording.")
5858

59-
private val loops by setting("Loops", -1, -1..10, 1, description = "Number of times to loop the replay. -1 for infinite.", unit = "repeats")
59+
private val loops by setting("Loops", -1, -1..10, 1, description = "Number of times to loop the replay. -1 for infinite.", unit = " repeats")
6060
private val velocityCheck by setting("Velocity check", true, description = "Check if the player is moving before starting a recording.")
6161
private val cancelOnDeviation by setting("Cancel on deviation", true)
6262
private val deviationThreshold by setting("Deviation threshold", 0.1, 0.1..5.0, 0.1, description = "The threshold for the deviation to cancel the replay.") { cancelOnDeviation }
6363

6464
private val rotationConfig = RotationSettings(this).apply {
6565
rotationMode = RotationMode.LOCK
66-
r1 = 1000.0
67-
r2 = 1001.0
66+
instant = true
6867
}
6968

7069
enum class State {

0 commit comments

Comments
 (0)