Skip to content

Commit a871d9e

Browse files
committed
Code Quality
1 parent 566df15 commit a871d9e

File tree

12 files changed

+57
-67
lines changed

12 files changed

+57
-67
lines changed

common/src/main/kotlin/com/lambda/brigadier/argument/PrimitiveArguments.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import com.mojang.brigadier.arguments.*
3030

3131
/**
3232
* Reads the boolean value from the argument in
33-
* the receiver [ArgumentReader].
33+
* the receiver [DefaultArgumentReader].
3434
*
3535
* @see BoolArgumentType.getBool
3636
*/
@@ -42,7 +42,7 @@ fun DefaultArgumentReader<BoolArgumentType>.value(): Boolean {
4242

4343
/**
4444
* Reads the boolean value from the argument in
45-
* the receiver [ArgumentReader].
45+
* the receiver [DefaultArgumentReader].
4646
*
4747
* @see BoolArgumentType.getBool
4848
*/
@@ -54,7 +54,7 @@ fun DefaultArgumentReader<DoubleArgumentType>.value(): Double {
5454

5555
/**
5656
* Reads the float value from the argument in
57-
* the receiver [ArgumentReader].
57+
* the receiver [DefaultArgumentReader].
5858
*
5959
* @see FloatArgumentType.getFloat
6060
*/
@@ -66,7 +66,7 @@ fun DefaultArgumentReader<FloatArgumentType>.value(): Float {
6666

6767
/**
6868
* Reads the integer value from the argument in
69-
* the receiver [ArgumentReader].
69+
* the receiver [DefaultArgumentReader].
7070
*
7171
* @see IntegerArgumentType.getInteger
7272
*/
@@ -78,7 +78,7 @@ fun DefaultArgumentReader<IntegerArgumentType>.value(): Int {
7878

7979
/**
8080
* Reads the long value from the argument in
81-
* the receiver [ArgumentReader].
81+
* the receiver [DefaultArgumentReader].
8282
*
8383
* @see LongArgumentType.getLong
8484
*/

common/src/main/kotlin/com/lambda/event/listener/SafeListener.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ class SafeListener(
9797
* - [SafeContext.interaction]
9898
* - [SafeContext.connection]
9999
*
100-
* This listener is special for tasks, as its behavior is
101-
* to only listen while the [Task.onAction] function is active / while the task is running.
102-
*
103100
* Usage:
104101
* ```kotlin
105102
* myTask.listener<MyEvent> { event ->

common/src/main/kotlin/com/lambda/event/listener/UnsafeListener.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.lambda.event.listener
22

3+
import com.lambda.context.SafeContext
34
import com.lambda.event.Event
45
import com.lambda.event.EventFlow
56
import com.lambda.event.Muteable

common/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ data class BreakContext(
3030
ctx.world.isAir(result.blockPos.offset(it))
3131
}
3232

33-
override val expectedState = checkedState.fluidState.blockState
33+
override val expectedState: BlockState = checkedState.fluidState.blockState
3434

3535
override fun compareTo(other: ComparableContext): Int {
3636
return when (other) {

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.lambda.module
22

3+
import com.lambda.command.LambdaCommand
34
import com.lambda.config.AbstractSetting
45
import com.lambda.config.Configurable
56
import com.lambda.config.Configuration
@@ -14,8 +15,9 @@ import com.lambda.event.listener.SafeListener
1415
import com.lambda.event.listener.SafeListener.Companion.listener
1516
import com.lambda.event.listener.UnsafeListener
1617
import com.lambda.gui.impl.clickgui.LambdaClickGui
18+
import com.lambda.gui.impl.clickgui.buttons.ModuleButton
19+
import com.lambda.module.modules.client.ClickGui
1720
import com.lambda.module.tag.ModuleTag
18-
import com.lambda.task.Task
1921
import com.lambda.util.KeyCode
2022
import com.lambda.util.Nameable
2123

@@ -26,14 +28,14 @@ import com.lambda.util.Nameable
2628
*
2729
* Each [Module] has a [name], which is displayed in-game.
2830
* The [description] of the module is shown when hovering over
29-
* the [ModuleButton] in the GUI and in [Commands]s.
31+
* the [ModuleButton] in the GUI and in [LambdaCommand]s.
3032
* The [Module] can be associated with a [Set] of [ModuleTag]s to allow for
3133
* easier filtering and searching in the GUI.
3234
*
3335
* A [Module] can be activated by a [keybind], represented by a [KeyCode].
3436
* The default [keybind] is the key on which
3537
* the module will be activated by default.
36-
* If a module does not need to be activated by a key (like [ClickGUI]),
38+
* If a module does not need to be activated by a key (like [ClickGui]),
3739
* the default [keybind] should not be set (using [KeyCode.UNBOUND]).
3840
*
3941
* [Module]s are [Configurable]s with [settings] (see [AbstractSetting] for all setting types).
@@ -78,9 +80,8 @@ import com.lambda.util.Nameable
7880
* See [SafeListener] and [UnsafeListener] for more details.
7981
*
8082
* @property name The name of the module, displayed in-game.
81-
* @property description The description of the module,
82-
* shown on hover over the module button in the GUI and in commands.
83-
* @property tag The leading module tag associated with the module.
83+
* @property description The description of the module shown on hover over the module button in the GUI and in commands.
84+
* @property defaultTags The default [ModuleTag]s associated with the module.
8485
* @property alwaysListening If true, the module's listeners will be triggered even if the module is not enabled.
8586
* @property isEnabledSetting The setting that determines if the module is enabled.
8687
* @property keybindSetting The setting that determines the keybind for the module.
@@ -167,4 +168,4 @@ abstract class Module(
167168
if (from != to) block(to)
168169
}
169170
}
170-
}
171+
}

common/src/main/kotlin/com/lambda/task/Task.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ abstract class Task<Result> : Nameable {
5454
open var timeout: Int = Int.MAX_VALUE
5555
open var tries: Int = 0
5656
open var repeats: Int = 0
57-
open var cooldown: Int = TaskFlow.taskCooldown
58-
open var onStart: SafeContext.(Task<Result>) -> Unit = {}
59-
open var onSuccess: SafeContext.(Task<Result>, Result) -> Unit = { _, _ -> }
60-
open var onRetry: SafeContext.(Task<Result>) -> Unit = {}
61-
open var onTimeout: SafeContext.(Task<Result>) -> Unit = {}
62-
open var onRepeat: SafeContext.(Task<Result>, Result, Int) -> Unit = { _, _, _ -> }
63-
open var onException: SafeContext.(Task<Result>, Throwable) -> Unit = { _, _ -> }
57+
open val cooldown: Int = TaskFlow.taskCooldown
58+
open val onStart: SafeContext.(Task<Result>) -> Unit = {}
59+
open val onSuccess: SafeContext.(Task<Result>, Result) -> Unit = { _, _ -> }
60+
open val onRetry: SafeContext.(Task<Result>) -> Unit = {}
61+
open val onTimeout: SafeContext.(Task<Result>) -> Unit = {}
62+
open val onRepeat: SafeContext.(Task<Result>, Result, Int) -> Unit = { _, _, _ -> }
63+
open val onException: SafeContext.(Task<Result>, Throwable) -> Unit = { _, _ -> }
6464

6565
open var pausable = true
6666

@@ -437,7 +437,7 @@ abstract class Task<Result> : Nameable {
437437
this.onRepeat = action
438438
return this
439439
}
440-
440+
441441
@Ta5kBuilder
442442
inline fun <reified T : Event> withListener(
443443
crossinline action: SafeContext.(Task<Result>) -> Unit
@@ -467,7 +467,7 @@ abstract class Task<Result> : Nameable {
467467
init { this.name = name }
468468
override fun SafeContext.onStart() { success(Unit) }
469469
}
470-
470+
471471
@Ta5kBuilder
472472
fun failTask(
473473
message: String
@@ -546,4 +546,4 @@ abstract class Task<Result> : Nameable {
546546
}
547547

548548
}
549-
}
549+
}

common/src/main/kotlin/com/lambda/task/tasks/BreakBlock.kt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
package com.lambda.task.tasks
22

33
import baritone.api.pathing.goals.GoalBlock
4+
import com.lambda.config.groups.IRotationConfig
5+
import com.lambda.config.groups.InteractionConfig
46
import com.lambda.context.SafeContext
57
import com.lambda.event.events.RotationEvent
68
import com.lambda.event.events.TickEvent
79
import com.lambda.event.events.WorldEvent
810
import com.lambda.event.listener.SafeListener.Companion.listener
9-
import com.lambda.config.groups.InteractionConfig
1011
import com.lambda.interaction.construction.context.BreakContext
11-
import com.lambda.config.groups.IRotationConfig
1212
import com.lambda.interaction.visibilty.VisibilityChecker.lookAtBlock
1313
import com.lambda.module.modules.client.TaskFlow
1414
import com.lambda.task.Task
15-
import com.lambda.task.tasks.GoalTask.Companion.moveToBlock
16-
import com.lambda.task.tasks.GoalTask.Companion.moveToBlockUntil
17-
import com.lambda.task.tasks.GoalTask.Companion.moveToGoal
18-
import com.lambda.task.tasks.GoalTask.Companion.moveToGoalUntil
1915
import com.lambda.util.BaritoneUtils
2016
import com.lambda.util.BlockUtils.blockState
21-
import com.lambda.util.BlockUtils.item
2217
import com.lambda.util.item.ItemUtils.block
23-
import com.lambda.util.item.ItemUtils.defaultDisposables
2418
import com.lambda.util.player.SlotUtils.clickSlot
2519
import com.lambda.util.player.SlotUtils.hotbarAndStorage
2620
import com.lambda.util.primitives.extension.inventorySlots
@@ -43,7 +37,7 @@ class BreakBlock @Ta5kBuilder constructor(
4337
val blockPos: BlockPos get() = ctx.result.blockPos
4438
private var beginState: BlockState? = null
4539
val SafeContext.state: BlockState get() = blockPos.blockState(world)
46-
override var cooldown = Int.MAX_VALUE
40+
override val cooldown
4741
get() = maxOf(TaskFlow.build.breakCoolDown, TaskFlow.taskCooldown)
4842
private var drop: ItemEntity? = null
4943

@@ -145,4 +139,4 @@ class BreakBlock @Ta5kBuilder constructor(
145139
swingHand
146140
)
147141
}
148-
}
142+
}

common/src/main/kotlin/com/lambda/task/tasks/PlaceBlock.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class PlaceBlock @Ta5kBuilder constructor(
1919
private val waitForConfirmation: Boolean,
2020
) : Task<Unit>() {
2121
private var beginState: BlockState? = null
22-
override var cooldown = Int.MAX_VALUE
22+
override val cooldown
2323
get() = maxOf(TaskFlow.build.placeCooldown, TaskFlow.taskCooldown)
2424
override var timeout = 20
2525
private var placed = false
@@ -106,4 +106,4 @@ class PlaceBlock @Ta5kBuilder constructor(
106106
waitForConfirmation: Boolean = TaskFlow.build.placeConfirmation,
107107
) = PlaceBlock(ctx, swingHand, rotate, waitForConfirmation)
108108
}
109-
}
109+
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.lambda.util
22

3+
import java.io.InputStream
4+
35
class LambdaResource(val path: String) {
4-
val stream
5-
get() =
6-
javaClass.getResourceAsStream("/assets/lambda/$path")
7-
}
6+
val stream: InputStream?
7+
get() = javaClass.getResourceAsStream("/assets/lambda/$path")
8+
}

common/src/main/kotlin/com/lambda/util/math/Color.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ val Color.hsb
77
.map(Float::toDouble)
88
.toDoubleArray()
99

10-
fun DoubleArray.readHSB() =
11-
Color.getHSBColor(this[0].toFloat(), this[1].toFloat(), this[2].toFloat())
10+
fun DoubleArray.readHSB(): Color = Color.getHSBColor(this[0].toFloat(), this[1].toFloat(), this[2].toFloat())
1211

1312
val Color.hue get() = hsb[0]
1413
val Color.saturation get() = hsb[1]
@@ -17,4 +16,4 @@ val Color.brightness get() = hsb[2]
1716
val Color.r get() = red / 255f
1817
val Color.g get() = green / 255f
1918
val Color.b get() = blue / 255f
20-
val Color.a get() = alpha / 255f
19+
val Color.a get() = alpha / 255f

0 commit comments

Comments
 (0)