Skip to content

Commit a1076f4

Browse files
committed
cleanup automation configs by moving all overrides to use the dsl. This gets rid of the accidental full setting group overrides, but now newly linked configs will override the now supposed to be hard set settings...
1 parent 88d74be commit a1076f4

File tree

11 files changed

+122
-173
lines changed

11 files changed

+122
-173
lines changed

src/main/kotlin/com/lambda/config/AutomationConfig.kt

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,15 @@ open class AutomationConfig(
6262
val hiddenSettings = mutableSetOf<AbstractSetting<*>>()
6363

6464
companion object {
65-
context(module: Module)
66-
fun MutableAutomationConfig.setDefaultAutomationConfig(
67-
name: String = module.name,
65+
fun Module.automationConfig(
66+
name: String = this.name,
6867
edits: (AutomationConfig.() -> Unit)? = null
69-
) {
70-
defaultAutomationConfig = AutomationConfig("Default $name Automation Config").apply { edits?.invoke(this) }
71-
}
68+
) = AutomationConfig("$name Automation Config").apply { edits?.invoke(this) }
7269

73-
fun MutableAutomationConfig.setDefaultAutomationConfig(
70+
fun automationConfig(
7471
name: String,
7572
edits: (AutomationConfig.() -> Unit)? = null
76-
) {
77-
defaultAutomationConfig = AutomationConfig("Default $name Automation Config").apply { edits?.invoke(this) }
78-
}
73+
) = AutomationConfig("$name Automation Config").apply { edits?.invoke(this) }
7974

8075
object DEFAULT : AutomationConfig("Default") {
8176
val renders by setting("Render", false).group(Group.Render)

src/main/kotlin/com/lambda/config/UserAutomationConfig.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,24 @@
1818
package com.lambda.config
1919

2020
import com.lambda.config.configurations.UserAutomationConfigs
21+
import com.lambda.module.Module
2122
import com.lambda.module.ModuleRegistry.moduleNameMap
2223

2324
class UserAutomationConfig(override val name: String) : AutomationConfig(name, UserAutomationConfigs) {
2425
val linkedModules = setting<String>("Linked Modules", moduleNameMap.filter { it.value.defaultAutomationConfig != Companion.DEFAULT }.keys, emptySet())
25-
.onSelect { module -> moduleNameMap[module]?.automationConfig = this@UserAutomationConfig }
26-
.onDeselect { module ->
27-
moduleNameMap[module]?.let { module ->
26+
.onSelect { name ->
27+
moduleNameMap[name]?.let {
28+
it.removeLink()
29+
it.automationConfig = this@UserAutomationConfig
30+
}
31+
}
32+
.onDeselect { name ->
33+
moduleNameMap[name]?.let { module ->
2834
module.automationConfig = module.defaultAutomationConfig
2935
}
3036
}
37+
38+
private fun Module.removeLink() {
39+
(automationConfig as UserAutomationConfig).linkedModules.value -= name
40+
}
3141
}

src/main/kotlin/com/lambda/module/Module.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ abstract class Module(
121121
defaultKeybind: Bind = Bind.EMPTY,
122122
autoDisable: Boolean = false
123123
) : Nameable, Muteable, Configurable(ModuleConfigs), MutableAutomationConfig {
124-
final override var defaultAutomationConfig: AutomationConfig = AutomationConfig.Companion.DEFAULT
124+
override var defaultAutomationConfig: AutomationConfig = AutomationConfig.Companion.DEFAULT
125125
set(value) {
126126
field = value
127127
automationConfig = value

src/main/kotlin/com/lambda/module/modules/movement/BetterFirework.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package com.lambda.module.modules.movement
1919

20-
import com.lambda.config.AutomationConfig.Companion.setDefaultAutomationConfig
20+
import com.lambda.config.AutomationConfig.Companion.automationConfig
2121
import com.lambda.config.applyEdits
2222
import com.lambda.config.settings.complex.Bind
2323
import com.lambda.context.SafeContext
@@ -57,6 +57,14 @@ object BetterFirework : Module(
5757
private var clientSwing by setting("Swing", true, "Swing hand client side")
5858
private var invUse by setting("Inventory", true, "Use fireworks from inventory") { activateButton.key != KeyCode.Unbound.code }
5959

60+
override var defaultAutomationConfig = automationConfig {
61+
applyEdits {
62+
hideAllGroupsExcept(hotbarConfig, inventoryConfig)
63+
hotbarConfig::tickStageMask.edit { defaultValue(mutableSetOf(TickEvent.Pre)) }
64+
inventoryConfig::tickStageMask.edit { defaultValue(mutableSetOf(TickEvent.Pre)) }
65+
}
66+
}
67+
6068
private var takeoffState = TakeoffState.None
6169

6270
val ClientPlayerEntity.canTakeoff: Boolean
@@ -66,14 +74,6 @@ object BetterFirework : Module(
6674
get() = !abilities.flying && !isClimbing && !isGliding && !isTouchingWater && !isOnGround && !hasVehicle() && !hasStatusEffect(StatusEffects.LEVITATION)
6775

6876
init {
69-
setDefaultAutomationConfig {
70-
applyEdits {
71-
hideAllGroupsExcept(hotbarConfig, inventoryConfig)
72-
hotbarConfig::tickStageMask.edit { defaultValue(mutableSetOf(TickEvent.Pre)) }
73-
inventoryConfig::tickStageMask.edit { defaultValue(mutableSetOf(TickEvent.Pre)) }
74-
}
75-
}
76-
7777
listen<TickEvent.Pre> {
7878
when (takeoffState) {
7979
TakeoffState.None -> {}

src/main/kotlin/com/lambda/module/modules/player/AutoEat.kt

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717

1818
package com.lambda.module.modules.player
1919

20-
import com.lambda.config.AutomationConfig.Companion.setDefaultAutomationConfig
20+
import com.lambda.config.AutomationConfig.Companion.automationConfig
2121
import com.lambda.config.applyEdits
2222
import com.lambda.config.groups.EatConfig.Companion.reasonEating
23-
import com.lambda.config.groups.EatSettings
24-
import com.lambda.config.groups.InventorySettings
2523
import com.lambda.event.events.TickEvent
2624
import com.lambda.event.listener.SafeListener.Companion.listen
2725
import com.lambda.module.Module
@@ -30,37 +28,21 @@ import com.lambda.task.RootTask.run
3028
import com.lambda.task.tasks.EatTask
3129
import com.lambda.task.tasks.EatTask.Companion.eat
3230
import com.lambda.threading.runSafeAutomated
33-
import com.lambda.util.NamedEnum
3431

3532
object AutoEat : Module(
3633
name = "AutoEat",
3734
description = "Eats food when you are hungry",
3835
tag = ModuleTag.PLAYER,
3936
) {
40-
private enum class Group(override val displayName: String) : NamedEnum {
41-
Eating("Eating"),
42-
Inventory("Inventory")
43-
}
37+
override var defaultAutomationConfig = automationConfig {
38+
applyEdits {
39+
hideAllGroupsExcept(eatConfig)
40+
}
41+
}
4442

45-
override val eatConfig = EatSettings(this, Group.Eating)
46-
override val inventoryConfig = InventorySettings(this, Group.Inventory)
4743
private var eatTask: EatTask? = null
4844

4945
init {
50-
setDefaultAutomationConfig {
51-
applyEdits {
52-
hideGroups(
53-
buildConfig,
54-
breakConfig,
55-
placeConfig,
56-
interactConfig,
57-
rotationConfig,
58-
inventoryConfig,
59-
hotbarConfig,
60-
)
61-
}
62-
}
63-
6446
listen<TickEvent.Pre> {
6547
val reason = runSafeAutomated { reasonEating() }
6648
if (eatTask != null || !reason.shouldEat()) return@listen

src/main/kotlin/com/lambda/module/modules/player/FastBreak.kt

Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,16 @@
1717

1818
package com.lambda.module.modules.player
1919

20-
import com.lambda.config.AutomationConfig.Companion.setDefaultAutomationConfig
20+
import com.lambda.config.AutomationConfig.Companion.automationConfig
2121
import com.lambda.config.applyEdits
22-
import com.lambda.config.groups.BuildConfig
2322
import com.lambda.event.events.PlayerEvent
2423
import com.lambda.event.events.TickEvent
2524
import com.lambda.event.listener.SafeListener.Companion.listen
2625
import com.lambda.interaction.construction.context.BuildContext
2726
import com.lambda.interaction.construction.result.results.BreakResult
2827
import com.lambda.interaction.construction.simulation.BuildSimulator.simulate
2928
import com.lambda.interaction.construction.verify.TargetState
30-
import com.lambda.interaction.request.breaking.BreakConfig
3129
import com.lambda.interaction.request.breaking.BreakRequest.Companion.breakRequest
32-
import com.lambda.interaction.request.hotbar.HotbarConfig
3330
import com.lambda.module.Module
3431
import com.lambda.module.tag.ModuleTag
3532
import com.lambda.threading.runSafeAutomated
@@ -40,55 +37,43 @@ object FastBreak : Module(
4037
description = "Break blocks faster.",
4138
tag = ModuleTag.PLAYER,
4239
) {
43-
private val pendingInteractions = ConcurrentLinkedQueue<BuildContext>()
44-
45-
override val buildConfig = object : BuildConfig by super.buildConfig {
46-
override val pathing = false
47-
override val stayInRange = false
48-
override val interactionsPerTick = 1
49-
override val useDefaultReach = false
50-
override val interactReach = Double.MAX_VALUE
51-
override val checkSideVisibility = false
52-
override val strictRayCast = false
40+
override var defaultAutomationConfig = automationConfig {
41+
applyEdits {
42+
hideAllGroupsExcept(breakConfig, rotationConfig, hotbarConfig)
43+
buildConfig.apply {
44+
editTyped(
45+
::pathing,
46+
::stayInRange,
47+
::useDefaultReach,
48+
::checkSideVisibility,
49+
::strictRayCast
50+
) { defaultValue(false) }
51+
::interactionsPerTick.edit { defaultValue(1) }
52+
::interactReach.edit { defaultValue(Double.MAX_VALUE) }
53+
}
54+
breakConfig.apply {
55+
editTyped(
56+
::avoidLiquids,
57+
::avoidSupporting,
58+
::efficientOnly,
59+
::suitableToolsOnly
60+
) { defaultValue(false) }
61+
editTyped(
62+
::rotateForBreak,
63+
::doubleBreak
64+
) { defaultValue(false); hide() }
65+
::breaksPerTick.edit { defaultValue(1); hide() }
66+
::tickStageMask.edit { defaultValue(mutableSetOf(TickEvent.Input.Post)); hide() }
67+
::maxPendingBreaks.edit { defaultValue(Int.MAX_VALUE); hide() }
68+
hide(::sorter, ::unsafeCancels)
69+
}
70+
hotbarConfig::tickStageMask.edit { defaultValue(mutableSetOf(TickEvent.Input.Post)); hide() }
71+
}
5372
}
5473

55-
override val breakConfig = object : BreakConfig by super.breakConfig {
56-
override val rotateForBreak = false
57-
override val doubleBreak = false
58-
override val breaksPerTick = 1
59-
override val tickStageMask = setOf(TickEvent.Input.Post)
60-
override val maxPendingBreaks = Int.MAX_VALUE
61-
}
62-
63-
override val hotbarConfig = object : HotbarConfig by super.hotbarConfig {
64-
override val tickStageMask = setOf(TickEvent.Input.Post)
65-
}
74+
private val pendingInteractions = ConcurrentLinkedQueue<BuildContext>()
6675

6776
init {
68-
setDefaultAutomationConfig {
69-
applyEdits {
70-
breakConfig.apply {
71-
editTyped(
72-
::avoidLiquids,
73-
::avoidSupporting,
74-
::efficientOnly,
75-
::suitableToolsOnly
76-
) { defaultValue(false) }
77-
hide(
78-
::rotateForBreak,
79-
::doubleBreak,
80-
::breaksPerTick,
81-
::sorter,
82-
::unsafeCancels,
83-
::tickStageMask,
84-
::maxPendingBreaks
85-
)
86-
}
87-
hide(hotbarConfig::tickStageMask)
88-
hideAllGroupsExcept(breakConfig, rotationConfig, hotbarConfig)
89-
}
90-
}
91-
9277
listen<PlayerEvent.Attack.Block> { it.cancel() }
9378
listen<PlayerEvent.Breaking.Update> { event ->
9479
event.cancel()

src/main/kotlin/com/lambda/module/modules/player/HighwayTools.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package com.lambda.module.modules.player
1919

20-
import com.lambda.config.AutomationConfig.Companion.setDefaultAutomationConfig
20+
import com.lambda.config.AutomationConfig.Companion.automationConfig
2121
import com.lambda.config.applyEdits
2222
import com.lambda.interaction.BaritoneManager
2323
import com.lambda.interaction.construction.blueprint.Blueprint.Companion.emptyStructure
@@ -65,6 +65,12 @@ object HighwayTools : Module(
6565
private val distance by setting("Distance", -1, -1..1000000, 1, "Distance to build the highway/tunnel (negative for infinite)")
6666
private val sliceSize by setting("Slice Size", 3, 1..5, 1, "Number of slices to build at once")
6767

68+
override var defaultAutomationConfig = automationConfig {
69+
applyEdits {
70+
hideGroup(interactConfig)
71+
}
72+
}
73+
6874
private var octant = EightWayDirection.NORTH
6975
private var distanceMoved = 0
7076
private var startPos = BlockPos.ORIGIN
@@ -89,11 +95,6 @@ object HighwayTools : Module(
8995
}
9096

9197
init {
92-
setDefaultAutomationConfig {
93-
applyEdits {
94-
hideGroup(interactConfig)
95-
}
96-
}
9798
onEnable {
9899
octant = player.octant
99100
startPos = player.blockPos

src/main/kotlin/com/lambda/module/modules/player/Nuker.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package com.lambda.module.modules.player
1919

20-
import com.lambda.config.AutomationConfig.Companion.setDefaultAutomationConfig
20+
import com.lambda.config.AutomationConfig.Companion.automationConfig
2121
import com.lambda.config.applyEdits
2222
import com.lambda.interaction.BaritoneManager
2323
import com.lambda.interaction.construction.blueprint.TickingBlueprint.Companion.tickingBlueprint
@@ -44,14 +44,15 @@ object Nuker : Module(
4444
private val fillFloor by setting("Fill Floor", false)
4545
private val baritoneSelection by setting("Baritone Selection", false, "Restricts nuker to your baritone selection")
4646

47+
override var defaultAutomationConfig = automationConfig {
48+
applyEdits {
49+
hideGroup(interactConfig)
50+
}
51+
}
52+
4753
private var task: Task<*>? = null
4854

4955
init {
50-
setDefaultAutomationConfig {
51-
applyEdits {
52-
hideGroup(interactConfig)
53-
}
54-
}
5556
onEnable {
5657
task = tickingBlueprint {
5758
if (onGround && !player.isOnGround) return@tickingBlueprint emptyMap()

src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package com.lambda.module.modules.player
1919

20-
import com.lambda.config.AutomationConfig.Companion.setDefaultAutomationConfig
20+
import com.lambda.config.AutomationConfig.Companion.automationConfig
2121
import com.lambda.config.applyEdits
2222
import com.lambda.context.SafeContext
2323
import com.lambda.event.events.PlayerEvent
@@ -72,6 +72,24 @@ object PacketMine : Module(
7272
private val startColor by setting("Start Color", Color(255, 255, 0, 60), "The color of the start (closest to breaking) of the queue") { renderQueue && dynamicColor }.group(Group.Renders)
7373
private val endColor by setting("End Color", Color(255, 0, 0, 60), "The color of the end (farthest from breaking) of the queue") { renderQueue && dynamicColor }.group(Group.Renders)
7474

75+
override var defaultAutomationConfig = automationConfig {
76+
applyEdits {
77+
breakConfig.apply {
78+
editTyped(
79+
::avoidLiquids,
80+
::avoidSupporting,
81+
::efficientOnly,
82+
::suitableToolsOnly
83+
) { defaultValue(false) }
84+
::swing.edit { defaultValue(BreakConfig.SwingMode.Start) }
85+
}
86+
hotbarConfig.apply {
87+
::keepTicks.edit { defaultValue(0) }
88+
}
89+
hideGroups(buildConfig, placeConfig, interactConfig, inventoryConfig, eatConfig)
90+
}
91+
}
92+
7593
private val pendingInteractions = ConcurrentLinkedQueue<BuildContext>()
7694

7795
private var breaks = 0
@@ -97,24 +115,6 @@ object PacketMine : Module(
97115
private var attackedThisTick = false
98116

99117
init {
100-
setDefaultAutomationConfig {
101-
applyEdits {
102-
breakConfig.apply {
103-
editTyped(
104-
::avoidLiquids,
105-
::avoidSupporting,
106-
::efficientOnly,
107-
::suitableToolsOnly
108-
) { defaultValue(false) }
109-
::swing.edit { defaultValue(BreakConfig.SwingMode.Start) }
110-
}
111-
hotbarConfig.apply {
112-
::keepTicks.edit { defaultValue(0) }
113-
}
114-
hideGroups(buildConfig, placeConfig, interactConfig, inventoryConfig, eatConfig)
115-
}
116-
}
117-
118118
listen<TickEvent.Post> {
119119
attackedThisTick = false
120120
}

0 commit comments

Comments
 (0)