Skip to content

Commit f1fb9b1

Browse files
committed
Refactor tool, inventory, and block usage logic.
Unify tool selection logic with new configuration options, improving flexibility for allowed tools and container access. Replace `wrong item` handling with a more robust `wrong item selection` mechanism, enhancing context-aware resolutions. Adjust block-breaking and material-handling processes for cleaner, modular, and efficient code.
1 parent 8993fd7 commit f1fb9b1

File tree

14 files changed

+180
-64
lines changed

14 files changed

+180
-64
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ interface BuildConfig {
3939
val breakConfirmation: BreakConfirmationMode
4040
val breaksPerTick: Int
4141
val forceSilkTouch: Boolean
42+
val forceFortunePickaxe: Boolean
43+
val minFortuneLevel: Int
4244
val ignoredBlocks: Set<Block>
4345

4446
val breakWeakBlocks: Boolean

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,20 @@ class BuildSettings(
3838

3939
// Breaking
4040
override val breakMode by c.setting("Break Mode", BuildConfig.BreakMode.Vanilla) { vis() && page == Page.Break }
41-
override val breakThreshold by c.setting("Break Threshold", 1.0f, 0.1f..1.0f, 0.1f, "The break amount at which the block is considered broken") { vis() && page == Page.Break }
41+
override val breakThreshold by c.setting("Break Threshold", 1.0f, 0.1f..1.0f, 0.02f, "The break amount at which the block is considered broken") { vis() && page == Page.Break }
4242
override val doubleBreak by c.setting("Double Break", false, "Allows breaking two blocks at once") { vis() && page == Page.Break }
4343
override val breakDelay by c.setting("Break Delay", 5, 0..5, 1, "The delay between breaking blocks", " ticks") { vis() && page == Page.Break }
4444
override val sounds by c.setting("Sounds", true, "Plays the breaking sounds") { vis() && page == Page.Break }
4545
override val particles by c.setting("Particles", true, "Renders the breaking particles") { vis() && page == Page.Break }
4646
override val breakingTexture by c.setting("Breaking Overlay", true, "Overlays the breaking texture at its different stages") { vis() && page == Page.Break }
4747
override val rotateForBreak by c.setting("Rotate For Break", true, "Rotate towards block while breaking") { vis() && page == Page.Break }
48+
override val ignoredBlocks by c.setting("Ignored Blocks", allSigns, "Blocks that wont be broken") { vis() && page == Page.Break }
4849
override val breakConfirmation by c.setting("Break Confirmation", BuildConfig.BreakConfirmationMode.BreakThenAwait, "The style of confirmation used when breaking") { vis() && page == Page.Break }
4950
override val breaksPerTick by c.setting("Instant Breaks Per Tick", 5, 1..30, 1, "Maximum instant block breaks per tick") { vis() && page == Page.Break }
5051
override val breakWeakBlocks by c.setting("Break Weak Blocks", false, "Break blocks that dont have structural integrity (e.g: grass)") { vis() && page == Page.Break }
5152
override val forceSilkTouch by c.setting("Force Silk Touch", false, "Force silk touch when breaking blocks") { vis() && page == Page.Break }
52-
override val ignoredBlocks by c.setting("Ignored Blocks", allSigns, "Blocks that wont be broken") { vis() && page == Page.Break }
53+
override val forceFortunePickaxe by c.setting("Force Fortune Pickaxe", false, "Force fortune pickaxe when breaking blocks") { vis() && page == Page.Break }
54+
override val minFortuneLevel by c.setting("Min Fortune Level", 1, 1..3, 1, "The minimum fortune level to use") { vis() && page == Page.Break && forceFortunePickaxe }
5355

5456
// Placing
5557
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: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,61 @@
1717

1818
package com.lambda.config.groups
1919

20+
import com.lambda.interaction.material.ContainerSelection
21+
import com.lambda.interaction.material.ContainerSelection.Companion.selectContainer
2022
import com.lambda.interaction.material.StackSelection
23+
import com.lambda.interaction.material.StackSelection.Companion.selectStack
2124
import com.lambda.interaction.material.container.MaterialContainer
25+
import com.lambda.util.item.ItemUtils
2226
import net.minecraft.block.Block
27+
import net.minecraft.item.Item
28+
import net.minecraft.item.Items
29+
import net.minecraft.item.ToolItem
30+
import net.minecraft.item.ToolMaterial
31+
import net.minecraft.item.ToolMaterials
2332

2433
interface InventoryConfig {
2534
val disposables: Set<Block>
26-
val accessEnderChest: Boolean
27-
2835
val swapWithDisposables: Boolean
29-
3036
val providerPriority: Priority
3137
val storePriority: Priority
3238

33-
val silentSwap: Boolean
39+
val accessShulkerBoxes: Boolean
40+
val accessEnderChest: Boolean
41+
val accessChests: Boolean
42+
val accessStashes: Boolean
43+
44+
val containerSelection: ContainerSelection get() = selectContainer {
45+
val allowedContainers = mutableSetOf<MaterialContainer.Rank>().apply {
46+
addAll(MaterialContainer.Rank.entries)
47+
if (!accessShulkerBoxes) remove(MaterialContainer.Rank.SHULKER_BOX)
48+
if (!accessEnderChest) remove(MaterialContainer.Rank.ENDER_CHEST)
49+
if (!accessChests) remove(MaterialContainer.Rank.CHEST)
50+
if (!accessStashes) remove(MaterialContainer.Rank.STASH)
51+
}
52+
ofAnyType(*allowedContainers.toTypedArray())
53+
}
54+
55+
val useWoodenTools: Boolean
56+
val useStoneTools: Boolean
57+
val useIronTools: Boolean
58+
val useDiamondTools: Boolean
59+
val useNetheriteTools: Boolean
60+
val useGoldTools: Boolean
61+
val useShears: Boolean
62+
val useFlintAndSteel: Boolean
63+
64+
val allowedTools get() = mutableSetOf<Item>().apply {
65+
addAll(ItemUtils.tools)
66+
if (!useWoodenTools) removeIf { it is ToolItem && it.material == ToolMaterials.WOOD }
67+
if (!useStoneTools) removeIf { it is ToolItem && it.material == ToolMaterials.STONE }
68+
if (!useIronTools) removeIf { it is ToolItem && it.material == ToolMaterials.IRON }
69+
if (!useDiamondTools) removeIf { it is ToolItem && it.material == ToolMaterials.DIAMOND }
70+
if (!useNetheriteTools) removeIf { it is ToolItem && it.material == ToolMaterials.NETHERITE }
71+
if (!useGoldTools) removeIf { it is ToolItem && it.material == ToolMaterials.GOLD }
72+
if (!useShears) removeIf { it == Items.SHEARS }
73+
if (!useFlintAndSteel) removeIf { it == Items.FLINT_AND_STEEL }
74+
}
3475

3576
enum class Priority {
3677
WithMinItems,

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,28 @@ class InventorySettings(
2424
c: Configurable,
2525
vis: () -> Boolean = { true },
2626
) : InventoryConfig {
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 accessEnderChest by c.setting("Access Ender Chest", false, "Allow access to the player's ender chest", vis)
29-
override val swapWithDisposables by c.setting("Swap With Disposables", true, "Swap items with disposable ones", vis)
30-
override val providerPriority by c.setting("Provider Priority", InventoryConfig.Priority.WithMinItems, "What container to prefer when retrieving the item from", vis)
31-
override val storePriority by c.setting("Store Priority", InventoryConfig.Priority.WithMinItems, "What container to prefer when storing the item to", vis)
32-
override val silentSwap by c.setting("Silent Swap", true, "", vis)
27+
val page by c.setting("Inventory Page", Page.Container, "The page to open when the module is enabled", vis)
28+
29+
override val disposables by c.setting("Disposables", ItemUtils.defaultDisposables, "Items that will be included when checking for a free slot / are allowed to be droped when inventory is full") { vis() && page == Page.Container}
30+
override val swapWithDisposables by c.setting("Swap With Disposables", true, "Swap items with disposable ones") { vis() && page == Page.Container}
31+
override val providerPriority by c.setting("Provider Priority", InventoryConfig.Priority.WithMinItems, "What container to prefer when retrieving the item from") { vis() && page == Page.Container}
32+
override val storePriority by c.setting("Store Priority", InventoryConfig.Priority.WithMinItems, "What container to prefer when storing the item to") { vis() && page == Page.Container}
33+
34+
override val accessShulkerBoxes by c.setting("Access Shulker Boxes", true, "Allow access to the player's shulker boxes") { vis() && page == Page.Access}
35+
override val accessEnderChest by c.setting("Access Ender Chest", false, "Allow access to the player's ender chest") { vis() && page == Page.Access}
36+
override val accessChests by c.setting("Access Chests", false, "Allow access to the player's normal chests") { vis() && page == Page.Access}
37+
override val accessStashes by c.setting("Access Stashes", false, "Allow access to the player's stashes") { vis() && page == Page.Access}
38+
39+
override val useWoodenTools by c.setting("Use Wooden Tools", false, "Use wooden tools to mine blocks") { vis() && page == Page.Tools}
40+
override val useStoneTools by c.setting("Use Stone Tools", false, "Use stone tools to mine blocks") { vis() && page == Page.Tools}
41+
override val useIronTools by c.setting("Use Iron Tools", false, "Use iron tools to mine blocks") { vis() && page == Page.Tools}
42+
override val useDiamondTools by c.setting("Use Diamond Tools", true, "Use diamond tools to mine blocks") { vis() && page == Page.Tools}
43+
override val useNetheriteTools by c.setting("Use Netherite Tools", true, "Use netherite tools to mine blocks") { vis() && page == Page.Tools}
44+
override val useGoldTools by c.setting("Use Gold Tools", false, "Use gold tools to mine blocks") { vis() && page == Page.Tools}
45+
override val useShears by c.setting("Use Shears", true, "Use shears to mine blocks") { vis() && page == Page.Tools}
46+
override val useFlintAndSteel by c.setting("Use Flint and Steel", true, "Use flint and steel to mine blocks?") { vis() && page == Page.Tools}
47+
48+
enum class Page {
49+
Container, Access, Tools
50+
}
3351
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.lambda.interaction.construction.context
1919

2020
import com.lambda.config.groups.BuildConfig
21+
import com.lambda.config.groups.InventoryConfig
2122
import com.lambda.context.SafeContext
2223
import com.lambda.graphics.renderer.esp.DirectionMask
2324
import com.lambda.graphics.renderer.esp.DirectionMask.exclude
@@ -44,9 +45,10 @@ data class BreakContext(
4445
override val rotation: RotationRequest,
4546
override val checkedState: BlockState,
4647
override val targetState: TargetState,
47-
override var slotIndex: Int?,
48+
override var hotbarIndex: Int,
4849
val instantBreak: Boolean,
4950
val buildConfig: BuildConfig,
51+
val inventoryConfig: InventoryConfig
5052
) : BuildContext {
5153
private val baseColor = Color(222, 0, 0, 25)
5254
private val sideColor = Color(222, 0, 0, 100)

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ package com.lambda.interaction.construction.context
2020
import com.lambda.config.groups.BuildConfig
2121
import com.lambda.interaction.construction.result.Drawable
2222
import com.lambda.interaction.construction.verify.TargetState
23+
import com.lambda.interaction.material.container.MaterialContainer
2324
import com.lambda.interaction.request.rotation.RotationRequest
2425
import net.minecraft.block.BlockState
26+
import net.minecraft.item.ItemStack
2527
import net.minecraft.util.hit.BlockHitResult
2628
import net.minecraft.util.math.BlockPos
2729
import net.minecraft.util.math.Vec3d
@@ -34,8 +36,10 @@ interface BuildContext : Comparable<BuildContext>, Drawable {
3436
val targetState: TargetState
3537
val expectedPos: BlockPos
3638
val checkedState: BlockState
37-
val slotIndex: Int?
39+
val hotbarIndex: Int
3840
val rotation: RotationRequest
3941

4042
fun shouldRotate(config: BuildConfig): Boolean
43+
44+
data class LocalizedStack(val container: MaterialContainer, val stack: ItemStack)
4145
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ data class PlaceContext(
3939
override val distance: Double,
4040
override val expectedState: BlockState,
4141
override val checkedState: BlockState,
42-
override val slotIndex: Int?,
42+
override val hotbarIndex: Int,
4343
override val expectedPos: BlockPos,
4444
override val targetState: TargetState,
4545
val sneak: Boolean,

common/src/main/kotlin/com/lambda/interaction/construction/result/BuildResult.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ import baritone.api.pathing.goals.GoalNear
2222
import com.lambda.config.groups.InventoryConfig
2323
import com.lambda.context.SafeContext
2424
import com.lambda.interaction.construction.context.BuildContext
25+
import com.lambda.interaction.material.StackSelection
2526
import com.lambda.interaction.material.StackSelection.Companion.select
2627
import com.lambda.interaction.material.container.ContainerManager.transfer
2728
import com.lambda.interaction.material.container.MaterialContainer
2829
import com.lambda.interaction.material.container.containers.MainHandContainer
2930
import com.lambda.util.BlockUtils.blockState
3031
import com.lambda.util.Nameable
3132
import net.minecraft.block.BlockState
32-
import net.minecraft.item.Item
3333
import net.minecraft.item.ItemStack
3434
import net.minecraft.util.math.BlockPos
3535
import net.minecraft.util.math.Box
@@ -190,24 +190,23 @@ abstract class BuildResult : ComparableResult<Rank>, Nameable {
190190

191191
/**
192192
* Player has an inefficient tool equipped.
193-
* @param neededItem The best tool for the block state.
193+
* @param neededSelection The best tool for the block state.
194194
*/
195-
data class WrongItem(
195+
data class WrongItemSelection(
196196
override val blockPos: BlockPos,
197197
val context: BuildContext,
198-
//TODO: probably need to make this a list of items
199-
val neededItem: Item,
198+
val neededSelection: StackSelection,
200199
val currentItem: ItemStack,
201200
val inventory: InventoryConfig
202201
) : Drawable, Resolvable, BuildResult() {
203-
override val name: String get() = "Wrong item ($currentItem) for ${blockPos.toShortString()} need ${neededItem.name.string}"
202+
override val name: String get() = "Wrong item ($currentItem) for ${blockPos.toShortString()} need $neededSelection"
204203
override val rank = Rank.WRONG_ITEM
205204
private val color = Color(3, 252, 169, 25)
206205

207206
override val pausesParent get() = true
208207

209-
override fun resolve() = neededItem.select()
210-
.transfer(MainHandContainer, inventory) ?: MaterialContainer.FailureTask("Couldn't find ${neededItem.name.string} anywhere.")
208+
override fun resolve() = neededSelection
209+
.transfer(MainHandContainer, inventory) ?: MaterialContainer.FailureTask("Couldn't find $neededSelection anywhere.")
211210

212211
override fun SafeContext.buildRenderer() {
213212
if (blockState(blockPos).isAir) {
@@ -219,7 +218,7 @@ abstract class BuildResult : ComparableResult<Rank>, Nameable {
219218

220219
override fun compareTo(other: ComparableResult<Rank>): Int {
221220
return when (other) {
222-
is WrongItem -> context.compareTo(other.context)
221+
is WrongItemSelection -> context.compareTo(other.context)
223222
else -> super.compareTo(other)
224223
}
225224
}
@@ -256,7 +255,7 @@ abstract class BuildResult : ComparableResult<Rank>, Nameable {
256255

257256
override fun compareTo(other: ComparableResult<Rank>): Int {
258257
return when (other) {
259-
is WrongItem -> context.compareTo(other.context)
258+
is WrongItemSelection -> context.compareTo(other.context)
260259
else -> super.compareTo(other)
261260
}
262261
}

0 commit comments

Comments
 (0)