Skip to content

Commit 7d4bacd

Browse files
committed
async mode in build task, enabled by default in Printer and Nuker. AutoPortal clears the current task when disabling, and a couple VisibilityChecker fixes
1 parent b069ac3 commit 7d4bacd

10 files changed

Lines changed: 250 additions & 98 deletions

File tree

src/main/kotlin/com/lambda/config/settings/complex/KeybindSetting.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ data class Bind(
215215
val modifiers: Int,
216216
val mouse: Int = -1,
217217
) {
218-
val truemods = buildList {
218+
val trueMods = buildList {
219219
if (modifiers and GLFW_MOD_SHIFT != 0) add(KeyCode.LeftShift)
220220
if (modifiers and GLFW_MOD_CONTROL != 0) add(KeyCode.LeftControl)
221221
if (modifiers and GLFW_MOD_ALT != 0) add(KeyCode.LeftAlt)
@@ -237,14 +237,14 @@ data class Bind(
237237
val list = mutableListOf<Any>()
238238

239239
if (mouse >= 0) list.add(Mouse.entries[mouse])
240-
if (modifiers > 0) list.add(truemods.joinToString(separator = "+") { it.name })
240+
if (modifiers > 0) list.add(trueMods.joinToString(separator = "+") { it.name })
241241
if (key > 0) list.add(KeyCode.fromKeyCode(key))
242242

243243
return list.joinToString(separator = "+") { it.toString() }
244244
}
245245

246246
override fun toString() =
247-
"Key Code: $key, Modifiers: ${truemods.joinToString(separator = "+") { it.name }}, Mouse Button: ${Mouse.entries.getOrNull(mouse) ?: "None"}"
247+
"Key Code: $key, Modifiers: ${trueMods.joinToString(separator = "+") { it.name }}, Mouse Button: ${Mouse.entries.getOrNull(mouse) ?: "None"}"
248248

249249
companion object {
250250
val EMPTY = Bind(0, 0, -1)

src/main/kotlin/com/lambda/interaction/managers/rotating/visibilty/VisibilityChecker.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ object VisibilityChecker {
190190
val pos = when (side) {
191191
Direction.DOWN -> Vec3d(
192192
pov.x.coerceIn(minX, maxX),
193-
minY + Client.scanShrinkFactor,
193+
minY - Client.scanShrinkFactor,
194194
pov.z.coerceIn(minZ, maxZ)
195195
)
196196
Direction.UP -> Vec3d(
@@ -201,15 +201,15 @@ object VisibilityChecker {
201201
Direction.NORTH -> Vec3d(
202202
pov.x.coerceIn(minX, maxX),
203203
pov.y.coerceIn(minY, maxY),
204-
minZ + Client.scanShrinkFactor
204+
minZ - Client.scanShrinkFactor
205205
)
206206
Direction.SOUTH -> Vec3d(
207207
pov.x.coerceIn(minX, maxX),
208208
pov.y.coerceIn(minY, maxY),
209209
maxZ + Client.scanShrinkFactor
210210
)
211211
Direction.WEST -> Vec3d(
212-
minX + Client.scanShrinkFactor,
212+
minX - Client.scanShrinkFactor,
213213
pov.y.coerceIn(minY, maxY),
214214
pov.z.coerceIn(minZ, maxZ)
215215
)
@@ -243,7 +243,7 @@ object VisibilityChecker {
243243
with(contract(Client.scanShrinkFactor)) {
244244
if (preProcessing == null || preProcessing.info.surfaceScan.mode == ScanMode.Full) return Pair(this, emptySet())
245245

246-
val (newXBounds, shrunkXSide) = toScanRange(minX, maxX, preProcessing.pos.x, Direction.Axis.X, preProcessing.info.surfaceScan)
246+
val (newXBounds, shrunkXSide) = toScanRange(minX, maxX, preProcessing.pos.x, Direction.Axis.X, preProcessing.info.surfaceScan)
247247
val (newYBounds, shrunkYSide) = toScanRange(minY, maxY, preProcessing.pos.y, Direction.Axis.Y, preProcessing.info.surfaceScan)
248248
val (newZBounds, shrunkZSide) = toScanRange(minZ, maxZ, preProcessing.pos.z, Direction.Axis.Z, preProcessing.info.surfaceScan)
249249

@@ -271,8 +271,8 @@ object VisibilityChecker {
271271
): Pair<ClosedRange<Double>, Direction?> {
272272
val range = if (scan.axis == axis) {
273273
when (scan.mode) {
274-
ScanMode.GreaterBlockHalf -> max(origin + 0.501, min)..max
275-
else -> min..min(origin + 0.499, max)
274+
ScanMode.GreaterBlockHalf -> max(origin + 0.5 + Client.scanShrinkFactor, min)..max
275+
else -> min..min(origin + 0.5 - Client.scanShrinkFactor, max)
276276
}
277277
} else min..max
278278
return Pair(

src/main/kotlin/com/lambda/module/modules/client/Client.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import com.lambda.util.NamedEnum
2626
object Client : Module(
2727
name = "Client",
2828
description = "Global settings for Lambda",
29-
tag = ModuleTag.CLIENT
29+
tag = ModuleTag.CLIENT,
30+
enabledByDefault = true
3031
) {
3132
private enum class Group(override val displayName: String) : NamedEnum {
3233
General("General"),

src/main/kotlin/com/lambda/module/modules/render/ContainerPreview.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ object ContainerPreview : Module(
9090
var isRenderingSubTooltip: Boolean = false
9191
private set
9292

93-
// Cache for container contents summary // Cache size is limited to 200 entries
93+
// Cache for container contents summary
9494
val containerCache = object : LinkedHashMap<Int, ContainerPreviewInfo>(16, 0.75f, true) {
9595
override fun removeEldestEntry(eldest: MutableMap.MutableEntry<Int, ContainerPreviewInfo>): Boolean {
9696
return size > 200
@@ -111,7 +111,7 @@ object ContainerPreview : Module(
111111
private fun getTooltipHeight() = TITLE_HEIGHT + ROWS * SLOT_SIZE + PADDING
112112

113113
/**
114-
* Check if mouse is over the locked tooltip area (for click blocking)
114+
* Check if the mouse is over the locked tooltip area (for click blocking)
115115
*/
116116
@JvmStatic
117117
fun isMouseOverLockedTooltip(mouseX: Int, mouseY: Int): Boolean {
@@ -186,14 +186,13 @@ object ContainerPreview : Module(
186186
private fun renderTooltipForStack(context: DrawContext, textRenderer: TextRenderer, stack: ItemStack, x: Int, y: Int, allowHover: Boolean) {
187187
val contents = getContainerContents(stack)
188188
val width = getTooltipWidth()
189-
val height = getTooltipHeight()
190189

191190
val matrices = context.matrices
192191
matrices.pushMatrix()
193192

194193
val tintColor = getContainerTintColor(stack)
195194

196-
drawBackground(context, x, y, width, height, tintColor)
195+
drawBackground(context, x, y, width, tintColor)
197196
val name = stack.name
198197
val textColor = getTextColor(tintColor)
199198
context.drawText(textRenderer, name, x + PADDING, y + 4, textColor, false)
@@ -301,7 +300,7 @@ object ContainerPreview : Module(
301300
return y
302301
}
303302

304-
private fun drawBackground(context: DrawContext, x: Int, y: Int, width: Int, height: Int, tintColor: Int) {
303+
private fun drawBackground(context: DrawContext, x: Int, y: Int, width: Int, tintColor: Int) {
305304
// Draw the shulker box texture background with tint
306305
// The shulker_box.png texture is 176x166
307306
// Top part (title area): y=0 to y=17

src/main/kotlin/com/lambda/module/modules/world/AutoPortal.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ object AutoPortal : Module(
144144
PosHandler.tick()
145145
}
146146

147+
onDisable {
148+
buildTask?.cancel()
149+
buildTask = null
150+
}
151+
147152
immediateRenderer("AutoPortal Immediate Renderer", { depthTest }) { safeContext ->
148153
if (!renders || !preview) return@immediateRenderer
149154
with (safeContext) {

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

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ object Nuker : Module(
4949
private val baritoneSelection by setting("Baritone Selection", false, "Restricts nuker to your baritone selection")
5050
private val inverseSelection by setting("Inverse Selection", false, "Breaks blocks outside of the baritone selection and ignores blocks inside") { baritoneSelection }
5151
private val sneakLowersFlatten by setting("Sneak Lowers Flatten", false)
52+
private val async by setting("Async", true, "Allows the simulation the 50 milliseconds between ticks where nothing changes to avoid lag. This causes a 1 tick wait between starting the module, and it performing actions")
53+
.onValueChange { _, _ -> if (buildTask != null) startBuildTask() }
5254

53-
private var task: Task<*>? = null
55+
private var buildTask: Task<*>? = null
5456

5557
init {
5658
setDefaultAutomationConfig {
@@ -62,35 +64,41 @@ object Nuker : Module(
6264
}
6365

6466
onEnable {
65-
task = tickingBlueprint {
66-
if (onGround && !player.isOnGround) return@tickingBlueprint emptyMap()
67-
68-
val selection = BlockPos.iterateOutwards(player.blockPos, width, height, width)
69-
.map { it.blockPos }
70-
.asSequence()
71-
.filter { !world.isAir(it) }
72-
.filter { !baritoneSelection || isInBaritoneSelection(it) != inverseSelection }
73-
.filter { isInFlatten(it, flattenMode, sneakLowersFlatten, baritoneSelection, inverseSelection) }
74-
.filter { isWithinDigDirection(it) }
75-
.associateWith { if (breakConfig.fillFluids) TargetState.Air else TargetState.Empty }
76-
77-
if (fillFloor) {
78-
val floor = BlockPos.iterateOutwards(player.blockPos.down(), width, 0, width)
79-
.map { it.blockPos }
80-
.associateWith { TargetState.Solid(setOf(Blocks.MAGMA_BLOCK)) }
81-
return@tickingBlueprint selection + floor
82-
}
83-
84-
selection
85-
}.build(finishOnDone = false)
86-
.run()
67+
startBuildTask()
8768
}
8869

8970
onDisable {
90-
task?.cancel()
71+
buildTask?.cancel()
72+
buildTask = null
9173
}
9274
}
9375

76+
private fun startBuildTask() {
77+
buildTask?.cancel()
78+
buildTask = tickingBlueprint {
79+
if (onGround && !player.isOnGround) return@tickingBlueprint emptyMap()
80+
81+
val selection = BlockPos.iterateOutwards(player.blockPos, width, height, width)
82+
.map { it.blockPos }
83+
.asSequence()
84+
.filter { !world.isAir(it) }
85+
.filter { !baritoneSelection || isInBaritoneSelection(it) != inverseSelection }
86+
.filter { isInFlatten(it, flattenMode, sneakLowersFlatten, baritoneSelection, inverseSelection) }
87+
.filter { isWithinDigDirection(it) }
88+
.associateWith { if (breakConfig.fillFluids) TargetState.Air else TargetState.Empty }
89+
90+
if (fillFloor) {
91+
val floor = BlockPos.iterateOutwards(player.blockPos.down(), width, 0, width)
92+
.map { it.blockPos }
93+
.associateWith { TargetState.Solid(setOf(Blocks.MAGMA_BLOCK)) }
94+
return@tickingBlueprint selection + floor
95+
}
96+
97+
selection
98+
}.build(finishOnDone = false, async = async)
99+
.run()
100+
}
101+
94102
private fun SafeContext.isWithinDigDirection(pos: BlockPos): Boolean {
95103
val playerPos = player.blockPos
96104
return when (directionalDig) {

src/main/kotlin/com/lambda/module/modules/world/Printer.kt

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,31 +53,41 @@ object Printer : Module(
5353
private val baritoneSelection by setting("Baritone Selection", false, "Restricts block breaking and placing to your baritone selection")
5454
private val inverseSelection by setting("Inverse Selection", false, "Break and place blocks outside of the baritone selection and ignores blocks inside") { baritoneSelection }
5555
private val sneakLowersFlatten by setting("Sneak Lowers Flatten", false, "When enabled, sneaking will lower the flattening level by 1, allowing you to mine the block below you")
56+
private val async by setting("Async", true, "Allows the simulation the 50 milliseconds between ticks where nothing changes to avoid lag. This causes a 1 tick wait between starting the module, and it performing actions")
57+
.onValueChange { _, _ -> if (buildTask != null) startBuildTask() }
5658

5759
private var buildTask: Task<*>? = null
5860

5961
init {
6062
setDefaultAutomationConfig()
6163

6264
onEnable {
63-
if (!litematicaAvailable()) {
64-
logError("Litematica is not installed!")
65-
disable()
66-
return@onEnable
67-
}
68-
buildTask = tickingBlueprint {
69-
val schematicWorld = SchematicWorldHandler.getSchematicWorld() ?: return@tickingBlueprint emptyMap()
70-
BlockPos.iterateOutwards(player.blockPos, range, range, range)
71-
.map { it.blockPos }
72-
.asSequence()
73-
.filter { pos -> !baritoneSelection || isInBaritoneSelection(pos) != inverseSelection }
74-
.filter { DataManager.getRenderLayerRange().isPositionWithinRange(it) && inSchematic(it) }
75-
.associateWith { TargetState.State(schematicWorld.getBlockState(it)) }
76-
.filter { air || !it.value.blockState.isAir }
77-
}.build(finishOnDone = false, buildResultFilter = { filterBuildResults(it) }).run()
65+
startBuildTask()
7866
}
7967

80-
onDisable { buildTask?.cancel(); buildTask = null }
68+
onDisable {
69+
buildTask?.cancel()
70+
buildTask = null
71+
}
72+
}
73+
74+
private fun startBuildTask() {
75+
if (!litematicaAvailable()) {
76+
logError("Litematica is not installed!")
77+
disable()
78+
return
79+
}
80+
buildTask?.cancel()
81+
buildTask = tickingBlueprint {
82+
val schematicWorld = SchematicWorldHandler.getSchematicWorld() ?: return@tickingBlueprint emptyMap()
83+
BlockPos.iterateOutwards(player.blockPos, range, range, range)
84+
.map { it.blockPos }
85+
.asSequence()
86+
.filter { pos -> !baritoneSelection || isInBaritoneSelection(pos) != inverseSelection }
87+
.filter { DataManager.getRenderLayerRange().isPositionWithinRange(it) && inSchematic(it) }
88+
.associateWith { TargetState.State(schematicWorld.getBlockState(it)) }
89+
.filter { air || !it.value.blockState.isAir }
90+
}.build(finishOnDone = false, async = async) { filterBuildResults(it) }.run()
8191
}
8292

8393
/**

0 commit comments

Comments
 (0)