Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 4 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.internal.jvm.Jvm
import java.util.*

val modId: String by project
Expand Down Expand Up @@ -214,6 +212,10 @@ tasks {
}

kotlin {
compilerOptions {
freeCompilerArgs.add("-Xcontext-parameters")
}

jvmToolchain(21)
}

Expand Down
13 changes: 8 additions & 5 deletions src/main/kotlin/com/lambda/command/commands/BuildCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.lambda.brigadier.argument.value
import com.lambda.brigadier.executeWithResult
import com.lambda.brigadier.required
import com.lambda.command.LambdaCommand
import com.lambda.context.AutomationConfig
import com.lambda.interaction.construction.StructureRegistry
import com.lambda.interaction.construction.blueprint.Blueprint.Companion.toStructure
import com.lambda.interaction.construction.blueprint.StaticBlueprint.Companion.toBlueprint
Expand Down Expand Up @@ -61,11 +62,13 @@ object BuildCommand : LambdaCommand(
.loadStructureByRelativePath(Path.of(pathString))
.let { template ->
info("Building structure $pathString with dimensions ${template.size.toShortString()} created by ${template.author}")
lastBuildTask = template.toStructure()
.move(player.blockPos)
.toBlueprint()
.build()
.run()
lastBuildTask = with(AutomationConfig) {
template.toStructure()
.move(player.blockPos)
.toBlueprint()
.build()
.run()
}

return@executeWithResult success()
}
Expand Down
43 changes: 25 additions & 18 deletions src/main/kotlin/com/lambda/command/commands/TransferCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.lambda.brigadier.argument.value
import com.lambda.brigadier.executeWithResult
import com.lambda.brigadier.required
import com.lambda.command.LambdaCommand
import com.lambda.context.AutomationConfig
import com.lambda.interaction.material.StackSelection.Companion.selectStack
import com.lambda.interaction.material.container.ContainerManager
import com.lambda.interaction.material.container.ContainerManager.containerWithMaterial
Expand All @@ -52,8 +53,10 @@ object TransferCommand : LambdaCommand(
val selection = selectStack(count) {
isItem(stack(ctx).value().item)
}
selection.containerWithMaterial().forEachIndexed { i, container ->
builder.suggest("\"${i + 1}. ${container.name}\"", container.description(selection))
with(AutomationConfig) {
selection.containerWithMaterial().forEachIndexed { i, container ->
builder.suggest("\"${i + 1}. ${container.name}\"", container.description(selection))
}
}
builder.buildFuture()
}
Expand All @@ -62,8 +65,10 @@ object TransferCommand : LambdaCommand(
val selection = selectStack(amount(ctx).value()) {
isItem(stack(ctx).value().item)
}
containerWithSpace(selection).forEachIndexed { i, container ->
builder.suggest("\"${i + 1}. ${container.name}\"", container.description(selection))
with(AutomationConfig) {
containerWithSpace(selection).forEachIndexed { i, container ->
builder.suggest("\"${i + 1}. ${container.name}\"", container.description(selection))
}
}
builder.buildFuture()
}
Expand All @@ -79,22 +84,24 @@ object TransferCommand : LambdaCommand(
it.name == to().value().split(".").last().trim()
} ?: return@executeWithResult failure("To container not found")

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()
}
with(AutomationConfig) {
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.MissingItems -> {
return@executeWithResult failure("Missing items: ${transaction.missing}")
}

is TransferResult.NoSpace -> {
return@executeWithResult failure("No space in ${toContainer.name}")
is TransferResult.NoSpace -> {
return@executeWithResult failure("No space in ${toContainer.name}")
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/com/lambda/config/groups/BuildConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ interface BuildConfig {
val interactionTimeout: Int

// Breaking
val breaking: BreakSettings
val breakConfig: BreakSettings

// Placing
val placing: PlaceSettings
val placeConfig: PlaceSettings

// Interacting
val interacting: InteractSettings
val interactConfig: InteractSettings

enum class SwingType(
override val displayName: String,
Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/com/lambda/config/groups/BuildSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ class BuildSettings(
override val maxPendingInteractions by c.setting("Max Pending Interactions", 15, 1..30, 1, "The maximum count of pending interactions to allow before pausing future interactions", visibility = vis).group(*groupPath, Group.General)

// Breaking
override val breaking = BreakSettings(c, groupPath.toList() + Group.Break, vis)
override val breakConfig = BreakSettings(c, groupPath.toList() + Group.Break, vis)

// Placing
override val placing = PlaceSettings(c, groupPath.toList() + Group.Place, vis)
override val placeConfig = PlaceSettings(c, groupPath.toList() + Group.Place, vis)

//Interacting
override val interacting = InteractSettings(c, groupPath.toList() + Group.Interact, vis)
override val interactConfig = InteractSettings(c, groupPath.toList() + Group.Interact, vis)

override val interactionTimeout by c.setting("Interaction Timeout", 10, 1..30, 1, "Timeout for block breaks in ticks", unit = " ticks") {
vis() && (placing.placeConfirmationMode != PlaceConfig.PlaceConfirmationMode.None
|| breaking.breakConfirmation != BreakConfirmationMode.None
|| interacting.interactConfirmationMode != InteractionConfig.InteractConfirmationMode.None)
vis() && (placeConfig.placeConfirmationMode != PlaceConfig.PlaceConfirmationMode.None
|| breakConfig.breakConfirmation != BreakConfirmationMode.None
|| interactConfig.interactConfirmationMode != InteractionConfig.InteractConfirmationMode.None)
}.group(*groupPath, Group.Break, BreakSettings.Group.General).group(*groupPath, Group.Place).group(*groupPath, Group.Interact)
}
27 changes: 15 additions & 12 deletions src/main/kotlin/com/lambda/config/groups/EatConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

package com.lambda.config.groups

import com.lambda.context.SafeContext
import com.lambda.context.Automated
import com.lambda.context.AutomatedSafeContext
import com.lambda.interaction.material.StackSelection.Companion.selectStack
import com.lambda.threading.runSafe
import com.lambda.util.Describable
Expand Down Expand Up @@ -77,10 +78,11 @@ interface EatConfig {

fun shouldEat() = this != None

fun shouldKeepEating(config: EatConfig, stack: ItemStack?) = runSafe {
context(c: Automated)
fun shouldKeepEating(stack: ItemStack?) = runSafe {
if (stack == null || stack.isEmpty) return@runSafe false
when(this@Reason) {
Hunger -> when(config.saturated) {
Hunger -> when(c.eatConfig.saturated) {
Saturation.EatSmart -> stack.item.nutrition + player.hungerManager.foodLevel <= 20
Saturation.EatUntilFull -> player.hungerManager.isNotFull
}
Expand All @@ -90,21 +92,22 @@ interface EatConfig {
}
} ?: false

fun selector(config: EatConfig) = selectStack(sorter = config.selectionPriority.comparator) {
context(c: Automated)
fun selector() = selectStack(sorter = c.eatConfig.selectionPriority.comparator) {
when(this@Reason) {
None -> any()
Hunger -> isOneOfItems(config.nutritiousFood)
Damage -> isOneOfItems(config.regenerationFood)
Fire -> isOneOfItems(config.resistanceFood)
} and if (config.ignoreBadFood) isNoneOfItems(config.badFood) else any()
Hunger -> isOneOfItems(c.eatConfig.nutritiousFood)
Damage -> isOneOfItems(c.eatConfig.regenerationFood)
Fire -> isOneOfItems(c.eatConfig.resistanceFood)
} and if (c.eatConfig.ignoreBadFood) isNoneOfItems(c.eatConfig.badFood) else any()
}
}

companion object {
fun SafeContext.reasonEating(config: EatConfig) = when {
config.eatOnHunger && player.hungerManager.foodLevel <= config.minFoodLevel -> Reason.Hunger
config.eatOnDamage && player.health <= config.minDamage && !player.hasStatusEffect(StatusEffects.REGENERATION) -> Reason.Damage
config.eatOnFire && player.isOnFire && !player.hasStatusEffect(StatusEffects.FIRE_RESISTANCE) -> Reason.Fire
fun AutomatedSafeContext.reasonEating() = when {
eatConfig.eatOnHunger && player.hungerManager.foodLevel <= eatConfig.minFoodLevel -> Reason.Hunger
eatConfig.eatOnDamage && player.health <= eatConfig.minDamage && !player.hasStatusEffect(StatusEffects.REGENERATION) -> Reason.Damage
eatConfig.eatOnFire && player.isOnFire && !player.hasStatusEffect(StatusEffects.FIRE_RESISTANCE) -> Reason.Fire
else -> Reason.None
}
}
Expand Down
41 changes: 0 additions & 41 deletions src/main/kotlin/com/lambda/context/AbstractContext.kt

This file was deleted.

38 changes: 38 additions & 0 deletions src/main/kotlin/com/lambda/context/Automated.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2025 Lambda
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.lambda.context

import com.lambda.config.groups.BuildConfig
import com.lambda.config.groups.EatConfig
import com.lambda.config.groups.InteractionConfig
import com.lambda.interaction.request.hotbar.HotbarConfig
import com.lambda.interaction.request.inventory.InventoryConfig
import com.lambda.interaction.request.rotating.RotationConfig

interface Automated {
val buildConfig: BuildConfig
val rotationConfig: RotationConfig
val interactionConfig: InteractionConfig
val inventoryConfig: InventoryConfig
val hotbarConfig: HotbarConfig
val eatConfig: EatConfig
}

val Automated.breakConfig get() = buildConfig.breakConfig
val Automated.placeConfig get() = buildConfig.placeConfig
val Automated.interactConfig get() = buildConfig.interactConfig
23 changes: 23 additions & 0 deletions src/main/kotlin/com/lambda/context/AutomatedSafeContext.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2025 Lambda
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.lambda.context

class AutomatedSafeContext(
safeContext: SafeContext,
automated: Automated
) : SafeContext by safeContext, Automated by automated
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,43 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.lambda.module.modules.client
package com.lambda.context

import com.lambda.config.Configurable
import com.lambda.config.configurations.LambdaConfig
import com.lambda.config.groups.BuildSettings
import com.lambda.config.groups.EatSettings
import com.lambda.config.groups.HotbarSettings
import com.lambda.config.groups.InteractionSettings
import com.lambda.config.groups.InventorySettings
import com.lambda.config.groups.RotationSettings
import com.lambda.event.events.onStaticRender
import com.lambda.interaction.construction.result.BuildResult
import com.lambda.interaction.construction.result.Drawable
import com.lambda.module.Module
import com.lambda.module.tag.ModuleTag
import com.lambda.util.NamedEnum
import com.lambda.util.world.raycast.InteractionMask

object TaskFlowModule : Module(
name = "TaskFlow",
description = "Settings for task automation",
tag = ModuleTag.CLIENT,
) {
object AutomationConfig : Configurable(LambdaConfig), Automated {
override val name = "automation"

enum class Group(override val displayName: String) : NamedEnum {
Build("Build"),
Rotation("Rotation"),
Interaction("Interaction"),
Inventory("Inventory"),
Hotbar("Hotbar"),
Eat("Eat"),
Render("Render"),
Debug("Debug")
}

val build = BuildSettings(this, Group.Build)
val rotation = RotationSettings(this, Group.Rotation)
val interaction = InteractionSettings(this, Group.Interaction, InteractionMask.Both)
val inventory = InventorySettings(this, Group.Inventory)
val hotbar = HotbarSettings(this, Group.Hotbar)
val eat = EatSettings(this, Group.Eat)
val renders by setting("Render", false).group(Group.Render)

override val buildConfig = BuildSettings(this, Group.Build)
override val rotationConfig = RotationSettings(this, Group.Rotation)
override val interactionConfig = InteractionSettings(this, Group.Interaction, InteractionMask.Both)
override val inventoryConfig = InventorySettings(this, Group.Inventory)
override val hotbarConfig = HotbarSettings(this, Group.Hotbar)
override val eatConfig = EatSettings(this, Group.Eat)

val showAllEntries by setting("Show All Entries", false, "Show all entries in the task tree").group(Group.Debug)
val shrinkFactor by setting("Shrink Factor", 0.001, 0.0..1.0, 0.001).group(Group.Debug)
Expand All @@ -62,7 +62,8 @@ object TaskFlowModule : Module(

init {
onStaticRender {
with(it) { drawables.forEach { with(it) { buildRenderer() } } }
if (renders)
with(it) { drawables.forEach { with(it) { buildRenderer() } } }
}
}
}
}
Loading
Loading