Skip to content

feature(AutoTool): Delay switch Item - #8542

Open
KeiiKaruizawa wants to merge 1 commit into
CCBlueX:nextgenfrom
KeiiKaruizawa:auto-tool
Open

feature(AutoTool): Delay switch Item#8542
KeiiKaruizawa wants to merge 1 commit into
CCBlueX:nextgenfrom
KeiiKaruizawa:auto-tool

Conversation

@KeiiKaruizawa

@KeiiKaruizawa KeiiKaruizawa commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Meant for this Feature Request

Adds delay/activation time to swapping items, Also adds a filter list.

Whitelist: Skips delay everything else gets delay
Blacklist: The items ticked is delayed, everything else has no delay

Not sure if thats what they wanted might have misunderstood.

@Pro0101-2b2fr

Pro0101-2b2fr commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Thanks for working on this!

I noticed a few issues with the current approach and wanted to suggest an alternative:

Issues

  1. PacketMine regressionswitchToBreakBlock() is called by CivMineMode and SwitchMethod (packet mining). Those callers need instant swaps — applying the delay there would break packet mine timing.

  2. waitTicks in a tickHandler — This suspends the entire handler coroutine, which means no other logic in that handler runs during the wait. If the player switches targets mid-delay, the old pending swap still fires.

  3. Default of 20 ticks (1 second) is very high — the feature request asks for ~150ms (~3 ticks). Also the range starts at 1, so there's no way to disable the delay (instant swap).

  4. Race conditionpendingPos gets overwritten if you start breaking a new block before the tick handler processes the old one, but lastSwappedPos retains the stale value.

Suggested approach

Instead of a tickHandler + waitTicks, track how many ticks the player has been continuously mining the same block, and only swap once the threshold is reached. This keeps switchToBreakBlock() instant for PacketMine callers:

private val switchDelay by int("SwitchDelay", 0, 0..20, "ticks")

private var breakingPos: BlockPos? = null
private var breakingTicks = 0

@Suppress("unused")
private val handleBlockBreakingProgress = handler<BlockBreakingProgressEvent> { event ->
    if (event.pos == breakingPos) {
        breakingTicks++
    } else {
        breakingPos = event.pos
        breakingTicks = 0
    }

    if (breakingTicks >= switchDelay) {
        switchToBreakBlock(event.pos)
    }
}

@Suppress("unused")
private val handleCancelBlockBreaking = handler<CancelBlockBreakingEvent> {
    breakingPos = null
    breakingTicks = 0
    if (isInventoryConsidered) {
        DynamicSelectMode.ConsiderInventory.onNoTool()
    }
}

Key differences:

  • Default 0 = no behavior change unless the user opts in (backward compatible)
  • PacketMine unaffectedswitchToBreakBlock() stays instant, no delay logic inside it
  • No coroutine/suspend — just a simple counter, resets cleanly when target changes
  • No race conditions — state is managed synchronously in the event handler

Also consider renaming to SwitchDelay (matching the existing SwapPreviousDelay pattern) and capping at 20 ticks (1 second max is more than enough for anti-cheat purposes).

Happy to help if you'd like — I can push a commit to your branch or open an alternative PR. Let me know!

@Pro0101-2b2fr

Copy link
Copy Markdown
Contributor

Regarding the item exclusion feature you mentioned — here's how to implement it using the existing Filter + items() pattern already used in the codebase (see ModuleNoEntityInteract for reference):

// Add these fields after the existing settings (e.g. after notDuringCombat):

private val heldItemFilter by enumChoice("HeldItemFilter", Filter.BLACKLIST)
private val heldItems by items("HeldItems", mutableListOf())

Then add a check at the top of switchToBreakBlock():

fun switchToBreakBlock(pos: BlockPos) {
    // Don't swap away from excluded items (e.g. sword during combat, totem, etc.)
    val currentItem = player.mainHandItem.item
    if (!heldItemFilter(currentItem, heldItems)) {
        return
    }

    val cancelDueToCombat = notDuringCombat && CombatManager.isInCombat
    // ... rest of existing logic
}

That's it — the Filter enum already handles whitelist/blacklist logic via its invoke operator, and items() gives the user a searchable item picker in the GUI. No custom code needed.

What this does:

  • BLACKLIST mode (default) + empty list = swaps from any item (current behavior, backward compatible)
  • BLACKLIST + [Diamond Sword, Totem] = won't swap away if holding those items
  • WHITELIST + [Wooden Pickaxe] = only swaps away from wooden pickaxe

The import you need is already there: net.ccbluex.liquidbounce.utils.collection.Filter.

Combined with the delay approach from my previous comment, the full feature becomes:

  1. Player starts mining
  2. After SwitchDelay ticks of continuous mining → check if held item is excluded → if not, swap to best tool

Let me know if you want me to push this to your branch directly!

@KeiiKaruizawa

Copy link
Copy Markdown
Contributor Author

For the suggested approach, I still prefer using waitTicks() i dont want a custom one sorry. But i did consider that option but chose not to use it.

@KeiiKaruizawa KeiiKaruizawa changed the title feature(AutoTool): Delay switch Item feature(AutoTool): Delay switch Item, Exclude Items Jun 23, 2026
@KeiiKaruizawa

Copy link
Copy Markdown
Contributor Author

I think i fixed the issue on CivMineMode and SwitchMethod? But i did added the Exclusion. Sorry don't have the time to test right now.

@Pro0101-2b2fr

Copy link
Copy Markdown
Contributor

I think i fixed the issue on CivMineMode and SwitchMethod? But i did added the Exclusion. Sorry don't have the time to test right now.

Yes, this should be fixed!

@MukjepScarlet

MukjepScarlet commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Please split 2 features into independent PRs

@KeiiKaruizawa

Copy link
Copy Markdown
Contributor Author

ok 👍

@KeiiKaruizawa KeiiKaruizawa changed the title feature(AutoTool): Delay switch Item, Exclude Items feature(AutoTool): Delay switch Item Jul 11, 2026
@KeiiKaruizawa

Copy link
Copy Markdown
Contributor Author

i'll do exclusion some time later

@KeiiKaruizawa

Copy link
Copy Markdown
Contributor Author

messed this up, oops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants