Skip to content

Commit 51db814

Browse files
committed
swapping logic again
1 parent 5792bcf commit 51db814

File tree

2 files changed

+38
-32
lines changed

2 files changed

+38
-32
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ object HotbarManager : Manager<HotbarRequest>(
9393
* @see setActiveSlot
9494
*/
9595
override fun AutomatedSafeContext.handleRequest(request: HotbarRequest) {
96-
96+
if (request.slot !in 0..8) return
9797
if (request.nowOrNothing && tickStage !in hotbarConfig.tickStageMask) return
9898

9999
activeRequest?.let { active ->

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

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,18 @@ object CrystalAura : Module(
141141
}
142142
}
143143

144-
init {
145-
setDefaultAutomationConfig {
146-
applyEdits {
147-
hideAllGroupsExcept(buildConfig, rotationConfig, hotbarConfig, inventoryConfig)
148-
buildConfig.apply {
149-
hide(::pathing, ::stayInRange, ::collectDrops, ::spleefEntities,
150-
::maxPendingActions, ::actionTimeout, ::maxBuildDependencies, ::breakBlocks, ::interactBlocks)
151-
}
152-
}
153-
}
144+
init {
145+
setDefaultAutomationConfig {
146+
applyEdits {
147+
hideAllGroupsExcept(buildConfig, rotationConfig, hotbarConfig, inventoryConfig)
148+
buildConfig.apply {
149+
hide(
150+
::pathing, ::stayInRange, ::collectDrops, ::spleefEntities,
151+
::maxPendingActions, ::actionTimeout, ::maxBuildDependencies, ::breakBlocks, ::interactBlocks
152+
)
153+
}
154+
}
155+
}
154156

155157
// Async ticking
156158
fixedRateTimer(
@@ -276,15 +278,16 @@ object CrystalAura : Module(
276278
blueprint[mutableBlockPos]
277279
}.filter { it.hasCrystal }.maxByOrNull { it.priority }?.explode()
278280

279-
best.place()
280-
}
281+
best.place()
282+
}
281283

282-
private fun SafeContext.placeInternal(opportunity: Opportunity, hand: Hand) {
283-
connection.sendPacket {
284-
PlayerInteractBlockC2SPacket(
285-
hand, BlockHitResult(opportunity.crystalPosition, opportunity.side, opportunity.blockPos, false), 0
286-
)
287-
}
284+
private fun SafeContext.placeInternal(opportunity: Opportunity, hand: Hand) {
285+
interaction.syncSelectedSlot()
286+
connection.sendPacket {
287+
PlayerInteractBlockC2SPacket(
288+
hand, BlockHitResult(opportunity.crystalPosition, opportunity.side, opportunity.blockPos, false), 0
289+
)
290+
}
288291

289292
player.swingHand(hand)
290293
}
@@ -476,19 +479,22 @@ object CrystalAura : Module(
476479
if (rotate && !rotationRequest { rotation(placeRotation) }.submit().done)
477480
return@runSafe
478481

479-
val selection = selectStack { isItem(Items.END_CRYSTAL) }
480-
if (swap &&
481-
(swapHand == Hand.MAIN_HAND && player.mainHandStack.item != selection.item) ||
482-
(swapHand == Hand.OFF_HAND && player.offHandStack.item != selection.item)
483-
) runSafeAutomated {
484-
val crystalSlot = player.hotbarStacks.indexOfFirst { selection.filterStack(it) }
485-
if (crystalSlot != -1) {
486-
if (!HotbarRequest(crystalSlot, this).submit().done) return@runSafe
487-
else return@runSafeAutomated
488-
}
489-
val swapTo = when (swapHand) { Hand.MAIN_HAND -> HotbarContainer; Hand.OFF_HAND -> OffHandContainer }
490-
if (!selection.transfer(swapTo)) return@runSafe
491-
}
482+
val selection = selectStack { isItem(Items.END_CRYSTAL) }
483+
if ((swapHand == Hand.MAIN_HAND && player.mainHandStack.item != selection.item) ||
484+
(swapHand == Hand.OFF_HAND && player.offHandStack.item != selection.item)
485+
) runSafeAutomated {
486+
if (!swap) return@runSafe
487+
var crystalSlot = player.hotbarStacks.indexOfFirst { selection.filterStack(it) }
488+
if (crystalSlot < 0) {
489+
val swapTo = when (swapHand) {
490+
Hand.MAIN_HAND -> HotbarContainer
491+
Hand.OFF_HAND -> OffHandContainer
492+
}
493+
if (!selection.transfer(swapTo)) return@runSafe
494+
crystalSlot = player.hotbarStacks.indexOfFirst { selection.filterStack(it) }
495+
}
496+
if (!HotbarRequest(crystalSlot, this).submit().done) return@runSafe
497+
}
492498

493499
placeTimer.runSafeIfPassed(placeDelay.milliseconds) {
494500
placeInternal(this@Opportunity, swapHand)

0 commit comments

Comments
 (0)