Skip to content

Commit 4c30aaa

Browse files
committed
swap instead of replace selected stack in kill aura
1 parent edb15e2 commit 4c30aaa

File tree

8 files changed

+43
-33
lines changed

8 files changed

+43
-33
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class InventorySettings(
4242
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()
4343

4444
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()
45-
override val accessShulkerBoxes by c.setting("Access Shulker Boxes", true, "Allow access to the player's shulker boxes").group(baseGroup, Group.Access).index()
46-
override val accessEnderChest by c.setting("Access Ender Chest", false, "Allow access to the player's ender chest").group(baseGroup, Group.Access).index()
47-
override val accessChests by c.setting("Access Chests", false, "Allow access to the player's normal chests").group(baseGroup, Group.Access).index()
48-
override val accessStashes by c.setting("Access Stashes", false, "Allow access to the player's stashes").group(baseGroup, Group.Access).index()
45+
override val accessShulkerBoxes by c.setting("Access Shulker Boxes", true, "Allow access to the player's shulker boxes") { !immediateAccessOnly }.group(baseGroup, Group.Access).index()
46+
override val accessEnderChest by c.setting("Access Ender Chest", false, "Allow access to the player's ender chest") { !immediateAccessOnly }.group(baseGroup, Group.Access).index()
47+
override val accessChests by c.setting("Access Chests", false, "Allow access to the player's normal chests") { !immediateAccessOnly }.group(baseGroup, Group.Access).index()
48+
override val accessStashes by c.setting("Access Stashes", false, "Allow access to the player's stashes") { !immediateAccessOnly }.group(baseGroup, Group.Access).index()
4949
}

src/main/kotlin/com/lambda/interaction/managers/hotbar/HotbarRequest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class HotbarRequest(
2626
val slot: Int,
2727
automated: Automated,
2828
var keepTicks: Int = automated.hotbarConfig.keepTicks,
29-
var swapPause: Int = automated.hotbarConfig.swapPause,
29+
val swapPause: Int = automated.hotbarConfig.swapPause,
3030
override val nowOrNothing: Boolean = true
3131
) : Request(), LogContext, Automated by automated {
3232
override val requestId = ++requestCount

src/main/kotlin/com/lambda/interaction/managers/inventory/InventoryConfig.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ interface InventoryConfig : ISettingGroup {
4242

4343
val containerSelection: ContainerSelection
4444
get() = ContainerSelection.selectContainer {
45-
val allowedContainers = mutableSetOf<MaterialContainer.Rank>().apply {
45+
val allowedContainers = buildSet {
4646
addAll(MaterialContainer.Rank.entries)
47-
if (!accessShulkerBoxes) remove(MaterialContainer.Rank.ShulkerBox)
48-
if (!accessEnderChest) remove(MaterialContainer.Rank.EnderChest)
49-
if (!accessChests) remove(MaterialContainer.Rank.Chest)
50-
if (!accessStashes) remove(MaterialContainer.Rank.Stash)
47+
if (!accessShulkerBoxes || immediateAccessOnly) remove(MaterialContainer.Rank.ShulkerBox)
48+
if (!accessEnderChest || immediateAccessOnly) remove(MaterialContainer.Rank.EnderChest)
49+
if (!accessChests || immediateAccessOnly) remove(MaterialContainer.Rank.Chest)
50+
if (!accessStashes || immediateAccessOnly) remove(MaterialContainer.Rank.Stash)
5151
}
5252
ofAnyType(*allowedContainers.toTypedArray())
5353
}

src/main/kotlin/com/lambda/interaction/material/ContainerSelection.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.lambda.interaction.material
1919

20+
import com.lambda.context.SafeContext
2021
import com.lambda.interaction.material.container.MaterialContainer
2122

2223
/**
@@ -62,6 +63,11 @@ class ContainerSelection {
6263
fun noneOfType(vararg types: MaterialContainer.Rank): (MaterialContainer) -> Boolean =
6364
{ container -> !types.contains(container.rank) }
6465

66+
@ContainerSelectionDsl
67+
context(_: SafeContext)
68+
fun immediateOnly(): (MaterialContainer) -> Boolean =
69+
{ container -> !container.isImmediatelyAccessible() }
70+
6571
/**
6672
* Returns a function that combines two container predicates using logical AND.
6773
*/

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ object ContainerManager : Loadable {
9292
block: (MaterialContainer) -> Boolean,
9393
): MaterialContainer? = containers().find(block)
9494

95-
context(_: Automated, _: SafeContext)
96-
fun StackSelection.findContainerWithMaterial(): MaterialContainer? =
97-
findContainersWithMaterial().firstOrNull()
95+
context(automated: Automated, _: SafeContext)
96+
fun StackSelection.findContainerWithMaterial(
97+
containerSelection: ContainerSelection = automated.inventoryConfig.containerSelection
98+
): MaterialContainer? = findContainersWithMaterial(containerSelection).firstOrNull()
9899

99100
context(_: Automated, _: SafeContext)
100101
fun findContainerWithSpace(selection: StackSelection): MaterialContainer? =

src/main/kotlin/com/lambda/module/HudModule.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ abstract class HudModule(
2626
name: String,
2727
description: String = "",
2828
tag: ModuleTag,
29-
val customWindow: Boolean = false,
3029
alwaysListening: Boolean = false,
3130
enabledByDefault: Boolean = false,
3231
defaultKeybind: Bind = Bind.EMPTY,

src/main/kotlin/com/lambda/module/hud/ManagerDebugLoggers.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ import com.lambda.util.NamedEnum
2727
object ManagerDebugLoggers : HudModule(
2828
"ManagerDebugLoggers",
2929
"debug loggers for all action managers in lambda",
30-
ModuleTag.HUD,
31-
customWindow = true
30+
ModuleTag.HUD
3231
) {
3332
enum class Group(override val displayName: String) : NamedEnum {
3433
General("General"),

src/main/kotlin/com/lambda/module/modules/combat/KillAura.kt

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,19 @@ import com.lambda.context.SafeContext
2424
import com.lambda.event.events.PlayerPacketEvent
2525
import com.lambda.event.events.TickEvent
2626
import com.lambda.event.listener.SafeListener.Companion.listen
27+
import com.lambda.interaction.managers.Request.Companion.submit
28+
import com.lambda.interaction.managers.hotbar.HotbarRequest
2729
import com.lambda.interaction.managers.rotating.RotationRequest
2830
import com.lambda.interaction.managers.rotating.visibilty.lookAtEntity
2931
import com.lambda.interaction.material.StackSelection.Companion.selectStack
30-
import com.lambda.interaction.material.container.ContainerManager.transfer
31-
import com.lambda.interaction.material.container.containers.MainHandContainer
3232
import com.lambda.module.Module
3333
import com.lambda.module.tag.ModuleTag
34-
import com.lambda.task.RootTask.run
35-
import com.lambda.threading.runSafe
3634
import com.lambda.threading.runSafeAutomated
3735
import com.lambda.util.NamedEnum
3836
import com.lambda.util.item.ItemStackUtils.attackDamage
3937
import com.lambda.util.item.ItemStackUtils.attackSpeed
40-
import com.lambda.util.item.ItemStackUtils.equal
4138
import com.lambda.util.math.random
42-
import com.lambda.util.player.SlotUtils.hotbarAndStorage
39+
import com.lambda.util.player.SlotUtils.hotbar
4340
import net.minecraft.entity.LivingEntity
4441
import net.minecraft.item.ItemStack
4542
import net.minecraft.util.Hand
@@ -64,6 +61,9 @@ object KillAura : Module(
6461
val target: LivingEntity?
6562
get() = targeting.target()
6663

64+
private var prevEntity = target
65+
private var validServerRot = false
66+
6767
private var lastAttackTime = 0L
6868
private var hitDelay = 100.0
6969

@@ -90,7 +90,7 @@ object KillAura : Module(
9090
init {
9191
setDefaultAutomationConfig {
9292
applyEdits {
93-
hideAllGroupsExcept(buildConfig)
93+
hideAllGroupsExcept(buildConfig, hotbarConfig, rotationConfig)
9494
buildConfig.apply {
9595
hide(::pathing, ::stayInRange, ::collectDrops, ::spleefEntities, ::maxPendingActions, ::actionTimeout, ::maxBuildDependencies, ::blockReach)
9696
}
@@ -105,19 +105,24 @@ object KillAura : Module(
105105

106106
listen<TickEvent.Pre> {
107107
target?.let { entity ->
108-
if (swap) {
109-
val selection = selectStack().sortByDescending {
110-
damageMode.block(this, it)
111-
}
112-
113-
if (!selection.bestItemMatch(player.hotbarAndStorage).equal(player.mainHandStack))
114-
selection.transfer(MainHandContainer)?.run()
115-
}
116-
117108
// Wait until the rotation has a hit result on the entity
118109
if (rotate) runSafeAutomated {
119110
val rotationRequest = RotationRequest(lookAtEntity(entity)?.rotation ?: return@listen, this@KillAura).submit()
120-
if (!rotationRequest.done) return@listen
111+
val canContinue = !rotationRequest.done || entity !== prevEntity || !validServerRot
112+
prevEntity = entity
113+
validServerRot = rotationRequest.done
114+
if (canContinue) return@listen
115+
}
116+
117+
if (swap) {
118+
val selection = selectStack().sortByDescending {
119+
damageMode.block(this, it)
120+
}
121+
122+
selection.bestItemMatch(player.hotbar)?.let { bestStack ->
123+
val slotId = player.hotbar.indexOf(bestStack)
124+
if (!submit(HotbarRequest(slotId, this@KillAura, nowOrNothing = false)).done) return@listen
125+
}
121126
}
122127

123128
// Cooldown check

0 commit comments

Comments
 (0)