Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 19 additions & 41 deletions src/main/kotlin/com/lambda/command/commands/TransferCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import com.lambda.interaction.material.StackSelection.Companion.selectStack
import com.lambda.interaction.material.container.ContainerManager
import com.lambda.interaction.material.container.ContainerManager.findContainersWithMaterial
import com.lambda.interaction.material.container.ContainerManager.findContainersWithSpace
import com.lambda.interaction.material.transfer.TransferResult
import com.lambda.task.RootTask.run
import com.lambda.threading.runSafe
import com.lambda.task.RootTask
import com.lambda.task.Task
import com.lambda.threading.runSafeAutomated
import com.lambda.util.Communication.info
import com.lambda.util.extension.CommandBuilder

Expand All @@ -43,7 +43,7 @@ object TransferCommand : LambdaCommand(
usage = "transfer <move | cancel | undo> <item> <amount> <to>",
description = "Transfer items from anywhere to anywhere",
) {
private var lastContainerTransfer: TransferResult.ContainerTransfer? = null
private var lastContainerTransfer: Task<*>? = null

override fun CommandBuilder.create() {
required(itemStack("stack", registry)) { stack ->
Expand All @@ -54,12 +54,10 @@ object TransferCommand : LambdaCommand(
val selection = selectStack(count) {
isItem(stack(ctx).value().item)
}
with(AutomationConfig.Companion.DEFAULT) {
runSafe {
selection.findContainersWithMaterial().forEachIndexed { i, container ->
builder.suggest("\"${i + 1}. ${container.name}\"", container.description(selection))
}
}
AutomationConfig.Companion.DEFAULT.runSafeAutomated {
selection.findContainersWithMaterial().forEachIndexed { i, container ->
builder.suggest("\"${i + 1}. ${container.name}\"", container.description(selection))
}
}
builder.buildFuture()
}
Expand All @@ -68,11 +66,9 @@ object TransferCommand : LambdaCommand(
val selection = selectStack(amount(ctx).value()) {
isItem(stack(ctx).value().item)
}
with(AutomationConfig.Companion.DEFAULT) {
runSafe {
findContainersWithSpace(selection).forEachIndexed { i, container ->
builder.suggest("\"${i + 1}. ${container.name}\"", container.description(selection))
}
AutomationConfig.Companion.DEFAULT.runSafeAutomated {
selection.findContainersWithSpace().forEachIndexed { i, container ->
builder.suggest("\"${i + 1}. ${container.name}\"", container.description(selection))
}
}
builder.buildFuture()
Expand All @@ -81,35 +77,17 @@ object TransferCommand : LambdaCommand(
val selection = selectStack(amount().value()) {
isItem(stack().value().item)
}
val fromContainer = ContainerManager.containers().find {
it.name == from().value().split(".").last().trim()
} ?: return@executeWithResult failure("From container not found")
AutomationConfig.Companion.DEFAULT.runSafeAutomated {
val fromContainer = ContainerManager.containers().find {
it.name == from().value().split(".").last().trim()
} ?: return@executeWithResult failure("From container not found")

val toContainer = ContainerManager.containers().find {
it.name == to().value().split(".").last().trim()
} ?: return@executeWithResult failure("To container not found")
val toContainer = ContainerManager.containers().find {
it.name == to().value().split(".").last().trim()
} ?: return@executeWithResult failure("To container not found")

with(AutomationConfig.Companion.DEFAULT) {
when (val transaction = fromContainer.transfer(selection, toContainer)) {
is TransferResult.ContainerTransfer -> {
info("${transaction.name} started.")
lastContainerTransfer = transaction
transaction.finally {
info("${transaction.name} completed.")
}.run()
return@executeWithResult success()
}

is TransferResult.MissingItems -> {
return@executeWithResult failure("Missing items: ${transaction.missing}")
}

is TransferResult.NoSpace -> {
return@executeWithResult failure("No space in ${toContainer.name}")
}
}
fromContainer.transferByTask(selection, toContainer).execute(RootTask)
}

return@executeWithResult success()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/lambda/config/groups/BuildConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ interface BuildConfig : ISettingGroup {
val actionTimeout: Int
val maxBuildDependencies: Int

val entityReach: Double
val blockReach: Double
val entityReach: Double
val scanReach: Double

val checkSideVisibility: Boolean
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/lambda/config/groups/BuildSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class BuildSettings(
override val actionTimeout by c.setting("Action Timeout", 10, 1..30, 1, "Timeout for block breaks in ticks", unit = " ticks").group(baseGroup, Group.General).index()
override val maxBuildDependencies by c.setting("Max Sim Dependencies", 3, 0..10, 1, "Maximum dependency build results").group(baseGroup, Group.General).index()

override var entityReach by c.setting("Attack Reach", 3.0, 1.0..7.0, 0.01, "Maximum entity interaction distance").group(baseGroup, Group.Reach).index()
override var blockReach by c.setting("Interact Reach", 4.5, 1.0..7.0, 0.01, "Maximum block interaction distance").group(baseGroup, Group.Reach).index()
override var entityReach by c.setting("Attack Reach", 3.0, 1.0..7.0, 0.01, "Maximum entity interaction distance").group(baseGroup, Group.Reach).index()
override val scanReach: Double get() = max(entityReach, blockReach)

override val checkSideVisibility by c.setting("Visibility Check", true, "Whether to check if an AABB side is visible").group(baseGroup, Group.Scan).index()
Expand Down
9 changes: 4 additions & 5 deletions src/main/kotlin/com/lambda/config/groups/InventorySettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ class InventorySettings(
override val providerPriority by c.setting("Provider Priority", InventoryConfig.Priority.WithMinItems, "What container to prefer when retrieving the item from").group(baseGroup, Group.Container).index()
override val storePriority by c.setting("Store Priority", InventoryConfig.Priority.WithMinItems, "What container to prefer when storing the item to").group(baseGroup, Group.Container).index()

override val immediateAccessOnly by c.setting("Immediate Access Only", false, "Only allow access to inventories that can be accessed immediately").group(baseGroup, Group.Access).index()
override val accessShulkerBoxes by c.setting("Access Shulker Boxes", true, "Allow access to the player's shulker boxes") { !immediateAccessOnly }.group(baseGroup, Group.Access).index()
override val accessEnderChest by c.setting("Access Ender Chest", false, "Allow access to the player's ender chest") { !immediateAccessOnly }.group(baseGroup, Group.Access).index()
override val accessChests by c.setting("Access Chests", false, "Allow access to the player's normal chests") { !immediateAccessOnly }.group(baseGroup, Group.Access).index()
override val accessStashes by c.setting("Access Stashes", false, "Allow access to the player's stashes") { !immediateAccessOnly }.group(baseGroup, Group.Access).index()
override val accessShulkerBoxes by c.setting("Access Shulker Boxes", false, "Allow access to the player's shulker boxes").group(baseGroup, Group.Access).index()
override val accessChests by c.setting("Access Chests", false, "Allow access to the player's normal chests").group(baseGroup, Group.Access).index()
override val accessEnderChest by c.setting("Access Ender Chest", false, "Allow access to the player's ender chest").group(baseGroup, Group.Access).index()
override val accessStashes by c.setting("Access Stashes", false, "Allow access to the player's stashes").group(baseGroup, Group.Access).index()
}
8 changes: 5 additions & 3 deletions src/main/kotlin/com/lambda/interaction/BaritoneManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import baritone.api.BaritoneAPI
import baritone.api.IBaritone
import baritone.api.Settings
import baritone.api.pathing.goals.Goal
import com.lambda.config.AutomationConfig
import com.lambda.config.Configurable
import com.lambda.config.configurations.LambdaConfig
import com.lambda.config.groups.RotationSettings
import com.lambda.context.Automated
import com.lambda.config.AutomationConfig
import com.lambda.util.BlockUtils.blockPos
import com.lambda.util.NamedEnum
import net.fabricmc.loader.api.FabricLoader
Expand Down Expand Up @@ -352,8 +352,10 @@ object BaritoneManager : Configurable(LambdaConfig), Automated by AutomationConf
* Whether Baritone is active (pathing, calculating goal, etc.)
*/
val isActive: Boolean
get() = isBaritoneLoaded && (primary?.customGoalProcess?.isActive == true || primary?.pathingBehavior?.isPathing == true || primary?.pathingControlManager?.mostRecentInControl()
?.orElse(null)?.isActive == true)
get() = isBaritoneLoaded &&
(primary?.customGoalProcess?.isActive == true ||
primary?.pathingBehavior?.isPathing == true ||
primary?.pathingControlManager?.mostRecentInControl()?.orElse(null)?.isActive == true)

/**
* Sets the current Baritone goal and starts pathing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,9 @@ class BreakSim private constructor(simInfo: SimInfo)
}

val hotbarCandidates = stackSelection
.findContainersWithMaterial(silentSwapSelection)
.map { it.matchingStacks(stackSelection) }
.flatten()
if (hotbarCandidates.isEmpty()) {
.findContainersWithMaterial(silentSwapSelection)
.flatMap { it.matchingStacks(stackSelection) }
if (hotbarCandidates.isEmpty()) {
result(GenericResult.WrongItemSelection(pos, stackSelection, player.mainHandStack))
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import com.lambda.util.item.ItemUtils.blockItem
import com.lambda.util.math.MathUtils.floorToInt
import com.lambda.util.math.minus
import com.lambda.util.player.MovementUtils.sneaking
import com.lambda.util.player.SlotUtils.hotbarStacks
import com.lambda.util.player.copyPlayer
import com.lambda.util.world.raycast.RayCastUtils.blockResult
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -223,8 +224,9 @@ class InteractSim private constructor(simInfo: InteractSimInfo)
result(GenericResult.WrongItemSelection(pos, stackSelection, player.mainHandStack))
return null
}
val hotbarStacks = player.hotbarStacks
return stackSelection.filterStacks(container.stacks).run {
firstOrNull { it.inventoryIndex == player.inventory.selectedSlot }
firstOrNull { hotbarStacks.indexOf(it) == player.inventory.selectedSlot }
?: firstOrNull()
}
}
Expand Down Expand Up @@ -271,7 +273,7 @@ class InteractSim private constructor(simInfo: InteractSimInfo)
}

private suspend fun AutomatedSafeContext.testPlaceState(context: ItemPlacementContext): BlockState? {
val resultState = context.stack.blockItem.getPlacementState(context)
val resultState = (context.stack.blockItem ?: return null).getPlacementState(context)
?: run {
handleEntityBlockage(context)
return null
Expand All @@ -285,7 +287,7 @@ class InteractSim private constructor(simInfo: InteractSimInfo)

private suspend fun AutomatedSafeContext.handleEntityBlockage(context: ItemPlacementContext): List<Entity> {
val pos = context.blockPos
val theoreticalState = context.stack.blockItem.block.getPlacementState(context)
val theoreticalState = (context.stack.blockItem ?: return emptyList()).block.getPlacementState(context)
?: return emptyList()

val collisionShape = theoreticalState.getCollisionShape(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@

package com.lambda.interaction.construction.simulation.result

import com.lambda.context.Automated
import com.lambda.context.SafeContext
import com.lambda.context.AutomatedSafeContext
import com.lambda.task.Task

/**
* Represents a [BuildResult] with a resolvable [Task]
*/
interface Resolvable {
context(automated: Automated, safeContext: SafeContext)
fun resolve(): Task<*>?
context(task: Task<*>, _: AutomatedSafeContext)
fun resolve()
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ package com.lambda.interaction.construction.simulation.result.results

import baritone.api.pathing.goals.GoalBlock
import baritone.api.pathing.goals.GoalInverted
import com.lambda.context.Automated
import com.lambda.context.SafeContext
import com.lambda.graphics.renderer.esp.DirectionMask.mask
import com.lambda.graphics.esp.ShapeScope
import com.lambda.context.AutomatedSafeContext
import com.lambda.graphics.mc.TransientRegionESP
import com.lambda.graphics.renderer.esp.DirectionMask.mask
import com.lambda.interaction.construction.simulation.context.BreakContext
import com.lambda.interaction.construction.simulation.result.BuildResult
import com.lambda.interaction.construction.simulation.result.ComparableResult
Expand All @@ -34,8 +32,9 @@ import com.lambda.interaction.construction.simulation.result.Navigable
import com.lambda.interaction.construction.simulation.result.Rank
import com.lambda.interaction.construction.simulation.result.Resolvable
import com.lambda.interaction.material.StackSelection.Companion.selectStack
import com.lambda.interaction.material.container.ContainerManager.transfer
import com.lambda.interaction.material.container.containers.MainHandContainer
import com.lambda.interaction.material.container.ContainerManager.transferByTask
import com.lambda.interaction.material.container.containers.HotbarContainer
import com.lambda.task.Task
import net.minecraft.block.BlockState
import net.minecraft.item.Item
import net.minecraft.util.math.BlockPos
Expand Down Expand Up @@ -98,11 +97,12 @@ sealed class BreakResult : BuildResult() {
) : Resolvable, BreakResult() {
override val rank = Rank.BreakItemCantMine

context(automated: Automated, safeContext: SafeContext)
override fun resolve() =
context(task: Task<*>, _: AutomatedSafeContext)
override fun resolve() {
selectStack {
isItem(badItem).not()
}.transfer(MainHandContainer)
}.transferByTask(HotbarContainer)?.execute(task)
}

override fun compareResult(other: ComparableResult<Rank>) =
when (other) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
package com.lambda.interaction.construction.simulation.result.results

import baritone.api.pathing.goals.GoalNear
import com.lambda.context.Automated
import com.lambda.context.SafeContext
import com.lambda.graphics.esp.ShapeScope
import com.lambda.context.AutomatedSafeContext
import com.lambda.graphics.mc.TransientRegionESP
import com.lambda.interaction.construction.simulation.result.BuildResult
import com.lambda.interaction.construction.simulation.result.ComparableResult
Expand All @@ -29,8 +27,9 @@ import com.lambda.interaction.construction.simulation.result.Navigable
import com.lambda.interaction.construction.simulation.result.Rank
import com.lambda.interaction.construction.simulation.result.Resolvable
import com.lambda.interaction.material.StackSelection
import com.lambda.interaction.material.container.ContainerManager.transfer
import com.lambda.interaction.material.container.containers.MainHandContainer
import com.lambda.interaction.material.container.ContainerManager.transferByTask
import com.lambda.interaction.material.container.containers.HotbarContainer
import com.lambda.task.Task
import net.minecraft.client.data.TextureMap.side
import net.minecraft.item.ItemStack
import net.minecraft.util.math.BlockPos
Expand Down Expand Up @@ -98,8 +97,10 @@ sealed class GenericResult : BuildResult() {
override val rank = Rank.WrongItem
private val color = Color(3, 252, 169, 25)

context(automated: Automated, safeContext: SafeContext)
override fun resolve() = neededSelection.transfer(MainHandContainer)
context(task: Task<*>, _: AutomatedSafeContext)
override fun resolve() {
neededSelection.transferByTask(HotbarContainer)?.execute(task)
}

override fun render(esp: TransientRegionESP) {
esp.shapes(pos.x.toDouble(), pos.y.toDouble(), pos.z.toDouble()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import net.minecraft.state.property.Property
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Direction

sealed class TargetState() : StateMatcher {
sealed class TargetState : StateMatcher {
data object Empty : TargetState() {
override fun toString() = "Empty"

Expand Down Expand Up @@ -87,7 +87,7 @@ sealed class TargetState() : StateMatcher {
override fun getStack(pos: BlockPos) =
with(automatedSafeContext) {
findDisposable()?.stacks?.firstOrNull {
it.item.block in inventoryConfig.disposables && it.item.block !in replace
it.item in inventoryConfig.disposables && it.item.block !in replace
} ?: ItemStack(Items.NETHERRACK)
}

Expand All @@ -114,7 +114,7 @@ sealed class TargetState() : StateMatcher {
override fun getStack(pos: BlockPos) =
with(automatedSafeContext) {
findDisposable()?.stacks?.firstOrNull {
it.item.block in inventoryConfig.disposables
it.item in inventoryConfig.disposables
} ?: ItemStack(Items.NETHERRACK)
}

Expand Down Expand Up @@ -165,8 +165,7 @@ sealed class TargetState() : StateMatcher {
}

data class Stack(val itemStack: ItemStack) : TargetState() {
private val startStack: ItemStack = itemStack.copy()
override fun toString() = "Stack of ${startStack.item.name.string.capitalize()}"
override fun toString() = "Stack of ${itemStack.item.name.string.capitalize()}"

private val block = itemStack.item.block

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ object InteractManager : Manager<InteractRequest>(
) {
ActionResult.PASS
} else {
val item = itemStack.blockItem
val item = itemStack.blockItem ?: return ActionResult.FAIL
place(interactContext, request, hand, hitResult, item, ItemPlacementContext(context))
}
}
Expand Down
Loading