Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import baritone.api.BaritoneAPI
import baritone.api.IBaritone
import baritone.api.Settings
import baritone.api.pathing.goals.Goal
import baritone.api.process.IBaritoneProcess
import baritone.api.process.PathingCommand
import baritone.api.process.PathingCommandType
import com.lambda.config.Config
import com.lambda.config.ConfigBlock
import com.lambda.config.Group
Expand All @@ -30,6 +33,9 @@ import com.lambda.config.blocks.RotationSettings
import com.lambda.config.categories.LambdaCategory
import com.lambda.config.entries.onValueChange
import com.lambda.context.Automated
import com.lambda.core.Loadable
import com.lambda.event.events.TickEvent
import com.lambda.event.listener.SafeListener.Companion.listen
import com.lambda.util.BlockUtils.blockPos
import net.minecraft.util.BlockMirror
import net.minecraft.util.BlockRotation
Expand All @@ -38,7 +44,7 @@ import net.minecraft.util.BlockRotation
object BaritoneHandler : Config(
"baritone",
LambdaCategory
), Automated by AutomationConfig.DEFAULT {
), Loadable, Automated by AutomationConfig.DEFAULT {
val baritoneAvailable by lazy {
runCatching {
Class.forName("baritone.api.BaritoneAPI")
Expand Down Expand Up @@ -66,15 +72,44 @@ object BaritoneHandler : Config(
get() = baritoneAvailable && primary?.pathingBehavior?.isPathing == true

/**
* Whether Baritone is active (pathing, calculating goal, etc.)
* Whether Baritone is active (pathing, calculating goal, etc.) and not held still by [pause]
*/
@JvmStatic val isActive: Boolean
get() = baritoneAvailable &&
get() = baritoneAvailable && !isPaused &&
(primary?.customGoalProcess?.isActive == true ||
primary?.pathingBehavior?.isPathing == true ||
primary?.pathingControlManager?.mostRecentInControl()?.orElse(null)?.isActive == true ||
primary?.elytraProcess?.isActive == true)

private val isPaused: Boolean
get() = baritoneAvailable &&
primary?.pathingControlManager?.mostRecentInControl()?.orElse(null) === PauseProcess &&
primary.pathingBehavior?.isPathing != true

private var pauseRequested = false

/**
* Requests Baritone to pause, call it from [TickEvent.Pre] every tick you want it paused
*/
fun pause() {
pauseRequested = true
}

override fun load(): String {
if (baritoneAvailable) primary?.pathingControlManager?.registerProcess(PauseProcess)
listen<TickEvent.Post> { pauseRequested = false }
return "Loaded Baritone Handler"
}

private object PauseProcess : IBaritoneProcess {
override fun isActive() = pauseRequested
override fun onTick(calcFailed: Boolean, isSafeToCancel: Boolean) = PathingCommand(null, PathingCommandType.REQUEST_PAUSE)
override fun isTemporary() = true
override fun onLostControl() {}
override fun priority() = 5.1
override fun displayName0() = "Lambda pause"
}

/**
* Sets the current Baritone goal and starts pathing
*/
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/com/lambda/module/modules/combat/KillAura.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.lambda.event.listener.SafeListener.Companion.listen
import com.lambda.interaction.container.containers.HotbarContainer
import com.lambda.interaction.container.selection.select
import com.lambda.interaction.container.selection.stackSelection
import com.lambda.interaction.handler.handlers.BaritoneHandler
import com.lambda.interaction.handler.handlers.ContainerHandler.findSlot
import com.lambda.interaction.manager.managers.hotbar.hotbarRequest
import com.lambda.interaction.manager.managers.rotating.rotationRequest
Expand Down Expand Up @@ -58,6 +59,7 @@ object KillAura : Module(
private const val TARGETING_TAB = "Targeting"

@Tab(GENERAL_TAB) private val rotate by setting("Rotate", true)
@Tab(GENERAL_TAB) private val pauseBaritone by setting("Pause Baritone", true, "Pause Baritone to look at the target") { rotate }
@Tab(GENERAL_TAB) private val swap by setting("Swap", true, "Swap to the item with the highest damage")
@Tab(GENERAL_TAB) private val disableWhileGliding by setting("Disable While Gliding", false, "Disables when gliding with an elytra")
@Tab(GENERAL_TAB) private val damageMode by setting("Damage Mode", DamageMode.Dps)
Expand Down Expand Up @@ -113,6 +115,7 @@ object KillAura : Module(
var rotated = true
if (rotate) withSafeAutomated {
val rotationRequest = lookAtEntity(entity)?.rotation?.let { rotationRequest { rotation(it) } }?.submit() ?: return@listen
if (pauseBaritone) BaritoneHandler.pause()
rotated = rotationRequest.done && entity === prevEntity && validServerRot
prevEntity = entity
validServerRot = rotationRequest.done
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/com/lambda/module/modules/player/AutoEat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.lambda.config.hideAllExcept
import com.lambda.config.withEdits
import com.lambda.event.events.TickEvent
import com.lambda.event.listener.SafeListener.Companion.listen
import com.lambda.interaction.handler.handlers.BaritoneHandler
import com.lambda.module.Module
import com.lambda.module.ModuleTag
import com.lambda.task.Task
Expand All @@ -37,6 +38,8 @@ object AutoEat : Module(
description = "Eats food when you are hungry",
tag = ModuleTag.PLAYER,
) {
private val pauseBaritone by setting("Pause Baritone", true, "Pause Baritone while eating")

private var eatTask: Task<*>? = null

init {
Expand All @@ -46,6 +49,9 @@ object AutoEat : Module(
}

listen<TickEvent.Pre> {
val state = eatTask?.state
if (pauseBaritone && (state == Task.State.Running || state == Task.State.Paused)) BaritoneHandler.pause()

val reason = withSafeAutomated { reasonEating() }
if (eatTask != null || !reason.shouldEat()) return@listen

Expand Down