Skip to content

Commit c14bd87

Browse files
committed
Refactor inventory and build configurations
Standardize access to `disposables` and `ignoredBlocks` under specific config groups for modularity. Improved task handling by adding a new debug setting and validating rotation states in build tasks. Removed redundant logging and adjusted conditional checks for cleaner code execution.
1 parent ecd23e4 commit c14bd87

File tree

12 files changed

+29
-28
lines changed

12 files changed

+29
-28
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,22 @@
1717

1818
package com.lambda.config.groups
1919

20+
import net.minecraft.block.Block
21+
2022
interface BuildConfig {
2123
// General
2224
val pathing: Boolean
2325
val stayInRange: Boolean
2426
val collectDrops: Boolean
25-
val forceSilkTouch: Boolean
2627

2728
// Breaking
2829
val rotateForBreak: Boolean
2930
val breakConfirmation: Boolean
3031
val maxPendingBreaks: Int
3132
val breaksPerTick: Int
3233
val breakWeakBlocks: Boolean
34+
val forceSilkTouch: Boolean
35+
val ignoredBlocks: Set<Block>
3336

3437
// Placing
3538
val rotateForPlace: Boolean

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
package com.lambda.config.groups
1919

2020
import com.lambda.config.Configurable
21+
import com.lambda.module.modules.client.TaskFlowModule.setting
22+
import com.lambda.util.BlockUtils.allSigns
2123

2224
class BuildSettings(
2325
c: Configurable,
@@ -41,6 +43,7 @@ class BuildSettings(
4143
override val breaksPerTick by c.setting("Instant Breaks Per Tick", 5, 1..30, 1, "Maximum instant block breaks per tick") { vis() && page == Page.BREAK }
4244
override val breakWeakBlocks by c.setting("Break Weak Blocks", false, "Break blocks that dont have structural integrity (e.g: grass)") { vis() && page == Page.BREAK }
4345
override val forceSilkTouch by c.setting("Force Silk Touch", false, "Force silk touch when breaking blocks") { vis() && page == Page.BREAK }
46+
override val ignoredBlocks by setting("Ignored Blocks", allSigns, "Blocks that wont be broken") { vis() && page == Page.BREAK }
4447

4548
// Placing
4649
override val rotateForPlace by c.setting("Rotate For Place", true, "Rotate towards block while placing") { vis() && page == Page.PLACE }

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ package com.lambda.config.groups
1919

2020
import com.lambda.interaction.material.container.MaterialContainer
2121
import com.lambda.interaction.material.StackSelection
22+
import net.minecraft.block.Block
2223

2324
interface InventoryConfig {
25+
val disposables: Set<Block>
26+
2427
val actionTimout: Int
2528
val swapWithDisposables: Boolean
2629

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

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

2020
import com.lambda.config.Configurable
21+
import com.lambda.util.item.ItemUtils
2122

2223
class InventorySettings(
2324
c: Configurable,
2425
vis: () -> Boolean = { true },
2526
) : InventoryConfig {
26-
override val actionTimout by c.setting("Action Timeout", 10, 0..100, 1, "How long to wait for after each inventory action", " ticks")
27+
override val disposables by c.setting("Disposables", ItemUtils.defaultDisposables, "Items that will be ignored when checking for a free slot", vis)
28+
override val actionTimout by c.setting("Action Timeout", 10, 0..100, 1, "How long to wait for after each inventory action", " ticks", vis)
2729
override val swapWithDisposables by c.setting("Swap With Disposables", true, "Swap items with disposable ones", vis)
28-
2930
override val providerPriority by c.setting("Provider Priority", InventoryConfig.Priority.WITH_MIN_ITEMS, "What container to prefer when retrieving the item from", vis)
3031
override val storePriority by c.setting("Store Priority", InventoryConfig.Priority.WITH_MIN_ITEMS, "What container to prefer when storing the item to", vis)
3132
}

common/src/main/kotlin/com/lambda/interaction/construction/simulation/BuildSimulator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ object BuildSimulator {
9797
}
9898

9999
/* block should be ignored */
100-
if (state.block in TaskFlowModule.ignoredBlocks && target.type == TargetState.Type.AIR) {
100+
if (state.block in TaskFlowModule.build.ignoredBlocks && target.type == TargetState.Type.AIR) {
101101
return BuildResult.Ignored(pos)
102102
}
103103

common/src/main/kotlin/com/lambda/interaction/construction/verify/TargetState.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ sealed class TargetState(val type: Type) : StateMatcher {
5555

5656
override fun getStack(world: ClientWorld, pos: BlockPos) =
5757
findDisposable()?.stacks?.firstOrNull {
58-
it.item.block in TaskFlowModule.disposables
58+
it.item.block in TaskFlowModule.inventory.disposables
5959
} ?: ItemStack(Items.NETHERRACK)
6060

6161
override fun isAir() = false
@@ -70,7 +70,7 @@ sealed class TargetState(val type: Type) : StateMatcher {
7070

7171
override fun getStack(world: ClientWorld, pos: BlockPos) =
7272
findDisposable()?.stacks?.firstOrNull {
73-
it.item.block in TaskFlowModule.disposables
73+
it.item.block in TaskFlowModule.inventory.disposables
7474
} ?: ItemStack(Items.NETHERRACK)
7575

7676
override fun isAir() = false
@@ -81,7 +81,7 @@ sealed class TargetState(val type: Type) : StateMatcher {
8181

8282
override fun matches(state: BlockState, pos: BlockPos, world: ClientWorld) =
8383
state.block == blockState.block && state.properties.all {
84-
it in TaskFlowModule.defaultIgnoreTags || state[it] == blockState[it]
84+
/*it in TaskFlowModule.defaultIgnoreTags ||*/ state[it] == blockState[it]
8585
}
8686
override fun getStack(world: ClientWorld, pos: BlockPos): ItemStack =
8787
blockState.block.getPickStack(world, pos, blockState)

common/src/main/kotlin/com/lambda/interaction/material/container/ContainerManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ object ContainerManager : Loadable {
133133
}?.first
134134

135135
fun findDisposable() = container().find { container ->
136-
TaskFlowModule.disposables.any { container.materialAvailable(it.item.select()) >= 0 }
136+
TaskFlowModule.inventory.disposables.any { container.materialAvailable(it.item.select()) >= 0 }
137137
}
138138

139139
class NoContainerFound(selection: StackSelection) : Exception("No container found matching $selection")

common/src/main/kotlin/com/lambda/interaction/material/transfer/InventoryTransaction.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package com.lambda.interaction.material.transfer
2020
import com.lambda.context.SafeContext
2121
import com.lambda.task.Task
2222
import com.lambda.threading.runSafe
23-
import com.lambda.util.Communication.info
2423

2524
abstract class InventoryTransaction : Task<InventoryChanges>() {
2625
private var changes: InventoryChanges? = null
@@ -33,7 +32,6 @@ abstract class InventoryTransaction : Task<InventoryChanges>() {
3332
runSafe {
3433
changes?.let {
3534
it.detectChanges()
36-
info("Changes: $it")
3735
success(it)
3836
}
3937
} ?: failure("Failed to finish transaction")

common/src/main/kotlin/com/lambda/module/modules/client/TaskFlowModule.kt

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.lambda.module.modules.client
1919

2020
import com.lambda.config.groups.BuildSettings
21+
import com.lambda.config.groups.BuildSettings.Page
2122
import com.lambda.config.groups.InteractionSettings
2223
import com.lambda.config.groups.InventorySettings
2324
import com.lambda.config.groups.RotationSettings
@@ -36,7 +37,7 @@ object TaskFlowModule : Module(
3637
defaultTags = setOf(ModuleTag.CLIENT, ModuleTag.AUTOMATION)
3738
) {
3839
enum class Page {
39-
BUILD, ROTATION, INTERACTION, INVENTORY
40+
BUILD, ROTATION, INTERACTION, INVENTORY, DEBUG
4041
}
4142

4243
private val page by setting("Page", Page.BUILD)
@@ -45,20 +46,7 @@ object TaskFlowModule : Module(
4546
val interact = InteractionSettings(this) { page == Page.INTERACTION }
4647
val inventory = InventorySettings(this) { page == Page.INVENTORY }
4748

48-
val disposables by setting("Disposables", ItemUtils.defaultDisposables)
49-
val ignoredBlocks by setting("Ignored Blocks", allSigns)
50-
val defaultIgnoreTags = setOf(
51-
Properties.DISTANCE_1_7,
52-
Properties.PERSISTENT,
53-
Properties.WATERLOGGED,
54-
Properties.STAIR_SHAPE,
55-
Properties.UP,
56-
Properties.DOWN,
57-
Properties.NORTH,
58-
Properties.EAST,
59-
Properties.SOUTH,
60-
Properties.WEST
61-
)
49+
val showAllEntries by setting("Show All Entries", false, "Show all entries in the task tree") { page == Page.DEBUG }
6250

6351
@Volatile
6452
var drawables = listOf<Drawable>()

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.lambda.event.EventFlow
2323
import com.lambda.event.Subscriber
2424
import com.lambda.event.events.TickEvent
2525
import com.lambda.event.listener.SafeListener.Companion.listen
26+
import com.lambda.module.modules.client.TaskFlowModule
2627
import com.lambda.threading.runSafe
2728
import com.lambda.util.Communication.logError
2829
import com.lambda.util.Nameable
@@ -323,9 +324,9 @@ abstract class Task<Result> : Nameable {
323324

324325
private fun StringBuilder.appendTaskTree(task: Task<*>, level: Int = 0) {
325326
appendLine("${" ".repeat(level * 4)}${task.name}" + if (task !is TaskFlow) " [${task.state.display}]" else "")
326-
// if (task.state == State.COMPLETED || task.state == State.CANCELLED) return
327+
if (!TaskFlowModule.showAllEntries && (task.state == State.COMPLETED || task.state == State.CANCELLED)) return
327328
task.subTasks.forEach {
328-
// if (task is TaskFlow && (it.state == State.COMPLETED || it.state == State.CANCELLED)) return@forEach
329+
if (!TaskFlowModule.showAllEntries && task is TaskFlow && (it.state == State.COMPLETED || it.state == State.CANCELLED)) return@forEach
329330
appendTaskTree(it, level + 1)
330331
}
331332
}

0 commit comments

Comments
 (0)