Skip to content

Commit

Permalink
Fixed ChestStealer not having click delays for swaps, throws, and add…
Browse files Browse the repository at this point in the history
…ed a NotInContainers option to InventoryCleaner. (CCBlueX#1728)
  • Loading branch information
mems01 authored Dec 22, 2023
1 parent fd75e60 commit 07dd68c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 48 deletions.
6 changes: 4 additions & 2 deletions src/main/kotlin/net/ccbluex/liquidbounce/event/Sequence.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,15 @@ open class Sequence<T : Event>(val owner: Listenable, val handler: SuspendableHa
/**
* Waits until the fixed amount of ticks ran out or the [breakLoop] says to continue.
*/
suspend fun waitConditional(ticks: Int, breakLoop: () -> Boolean = { false }) {
suspend fun waitConditional(ticks: Int, breakLoop: () -> Boolean = { false }): Boolean {
// Don't wait if ticks is 0
if (ticks == 0) {
return
return true
}

wait { if (breakLoop()) 0 else ticks }

return elapsedTicks >= ticks
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ object ModuleAutoGapple : Module("AutoGapple", Category.COMBAT) {

val delay = inventoryConstraints.clickDelay.random()

waitConditional(delay) { !canUseItem() }

if (!canUseItem()) {
if (!waitConditional(delay) { !canUseItem() }) {
return@repeatable
}

Expand All @@ -88,9 +86,7 @@ object ModuleAutoGapple : Module("AutoGapple", Category.COMBAT) {
if (player.isUsingItem) {
interaction.stopUsingItem(player)

waitConditional(1) { !canUseItem() }

if (!canUseItem()) {
if (!waitConditional(1) { !canUseItem() }) {
SilentHotbar.resetSlot(this)

return@repeatable
Expand Down Expand Up @@ -167,9 +163,7 @@ object ModuleAutoGapple : Module("AutoGapple", Category.COMBAT) {
val startDelay = inventoryConstraints.startDelay.random()

if (startDelay > 0) {
waitConditional(startDelay) { shouldCancelInvMove() }

if (shouldCancelInvMove()) {
if (!waitConditional(startDelay) { shouldCancelInvMove() }) {
return false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,54 +47,58 @@ object ModuleChestStealer : Module("ChestStealer", Category.PLAYER) {

private var lastSlot = 0

private var shouldClose = false
private var isFirstTime = true

val repeatable = repeatable {
if (shouldClose) {
player.closeHandledScreen()
shouldClose = false
isFirstTime = true
}

val screen = mc.currentScreen

if (screen !is GenericContainerScreen || checkTitle && !isScreenTitleChest(screen)) {
if (!screenIsChest()) {
isFirstTime = true
return@repeatable
}

val cleanupPlan = createCleanupPlan(screen)
val screen = mc.currentScreen as GenericContainerScreen

// Quick swap items in hotbar (i.e. swords)
if (performQuickSwaps(cleanupPlan, screen)) {
return@repeatable
}
val cleanupPlan = createCleanupPlan(screen)
val itemsToCollect = cleanupPlan.usefulItems.filterIsInstance<ContainerItemSlot>()

var itemsToCollect = cleanupPlan.usefulItems.filterIsInstance<ContainerItemSlot>()
val startDelay = startDelay.random()

// Are there items to steal? Did we just now open the chest?
if (isFirstTime && itemsToCollect.isNotEmpty()) {
if (isFirstTime && (cleanupPlan.swaps.isNotEmpty() || itemsToCollect.isNotEmpty())) {
isFirstTime = false

waitTicks(startDelay.random())
if (startDelay > 0) {
waitConditional(startDelay - 1) { !screenIsChest() }

return@repeatable
}
}

val shouldSwap = !ModuleInventoryCleaner.enabled || !ModuleInventoryCleaner.notInContainers

// Re-check in case items are not the same as before
itemsToCollect = cleanupPlan.usefulItems.filterIsInstance<ContainerItemSlot>()
// Quick swap items in hotbar (i.e. swords)
if (shouldSwap && performQuickSwaps(cleanupPlan, screen) != null) {
return@repeatable
}

var stillRequiredSpace = getStillRequiredSpace(cleanupPlan, itemsToCollect.size, screen)
var stillRequiredSpace = getStillRequiredSpace(cleanupPlan, itemsToCollect.size)

val sortedItemsToCollect = selectionMode.processor(itemsToCollect)

val delay = clickDelay.random()

for (slot in sortedItemsToCollect) {
val hasFreeSpace = (0..35).any { player.inventory.getStack(it).isNothing() }

if (!hasFreeSpace && stillRequiredSpace > 0) {
val shouldReturn = makeSpace(cleanupPlan, 1, screen)

if (shouldReturn == true)
return@repeatable
if (shouldReturn == true) {
if (delay > 0) {
waitConditional(delay - 1) { !screenIsChest() }
return@repeatable
}

continue
}

if (shouldReturn != null)
stillRequiredSpace -= 1
Expand All @@ -110,16 +114,13 @@ object ModuleChestStealer : Module("ChestStealer", Category.PLAYER) {

lastSlot = slot.slotInContainer

val delay = clickDelay.random()

if (delay > 0) {
waitTicks(delay - 1)
waitConditional(delay - 1) { !screenIsChest() }
return@repeatable
}
}


waitTicks(closeDelay.random())
waitConditional(closeDelay.random()) { !screenIsChest() }

if (sortedItemsToCollect.isEmpty()) {
player.closeHandledScreen()
Expand Down Expand Up @@ -161,7 +162,6 @@ object ModuleChestStealer : Module("ChestStealer", Category.PLAYER) {
private fun getStillRequiredSpace(
cleanupPlan: InventoryCleanupPlan,
slotsToCollect: Int,
screen: GenericContainerScreen
): Int {
val freeSlotsInInv = (0..35).count { player.inventory.getStack(it).isNothing() }

Expand Down Expand Up @@ -202,12 +202,13 @@ object ModuleChestStealer : Module("ChestStealer", Category.PLAYER) {
private suspend fun Sequence<*>.performQuickSwaps(
cleanupPlan: InventoryCleanupPlan,
screen: GenericContainerScreen
): Boolean {
): Boolean? {
for (hotbarSwap in cleanupPlan.swaps) {
// We only care about swaps from the chest to the hotbar
if (hotbarSwap.from.slotType != ItemSlotType.CONTAINER) {
continue
}

if (hotbarSwap.to !is HotbarItemSlot) {
continue
}
Expand All @@ -227,18 +228,14 @@ object ModuleChestStealer : Module("ChestStealer", Category.PLAYER) {
)
)


val delay = clickDelay.random()

if (delay > 0) {
waitTicks(delay - 1)

return true
return waitConditional(delay - 1) { !screenIsChest() }
}

}

return false
return null
}

/**
Expand Down Expand Up @@ -287,4 +284,16 @@ object ModuleChestStealer : Module("ChestStealer", Category.PLAYER) {
RANDOM("Random", List<ContainerItemSlot>::shuffled),
}

private fun screenIsChest(): Boolean {
val screen = mc.currentScreen

if (screen !is GenericContainerScreen || checkTitle && !isScreenTitleChest(screen)) {
isFirstTime = true

return false
}

return true
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ object ModuleInventoryCleaner : Module("InventoryCleaner", Category.PLAYER) {
)

val isGreedy by boolean("Greedy", true)
val notInContainers by boolean("NotInContainers", false)

val offHandItem by enumChoice("OffHandItem", ItemSortChoice.SHIELD, ItemSortChoice.values())
val slotItem1 by enumChoice("SlotItem-1", ItemSortChoice.SWORD, ItemSortChoice.values())
Expand Down

0 comments on commit 07dd68c

Please sign in to comment.