From 9f85297b2e91e583efef06c15ad27785c75b602e Mon Sep 17 00:00:00 2001 From: 1zuna <1zuna@ccbluex.net> Date: Mon, 16 Dec 2024 20:09:38 +0100 Subject: [PATCH] feat(TickBase): post and future mode (#4929) This also changes the event the TickBase is being triggered on, which seems to work better. --- .../module/modules/combat/ModuleTickBase.kt | 75 ++++++++++--------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/ModuleTickBase.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/ModuleTickBase.kt index d66211cb28e..8f727c7f5f6 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/ModuleTickBase.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/ModuleTickBase.kt @@ -18,9 +18,10 @@ */ package net.ccbluex.liquidbounce.features.module.modules.combat +import net.ccbluex.liquidbounce.config.types.NamedChoice import net.ccbluex.liquidbounce.event.events.* import net.ccbluex.liquidbounce.event.handler -import net.ccbluex.liquidbounce.event.sequenceHandler +import net.ccbluex.liquidbounce.event.tickHandler import net.ccbluex.liquidbounce.features.module.Category import net.ccbluex.liquidbounce.features.module.ClientModule import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.ModuleKillAura @@ -44,6 +45,8 @@ import kotlin.math.min */ internal object ModuleTickBase : ClientModule("TickBase", Category.COMBAT) { + private val mode by enumChoice("Mode", TickBaseMode.PAST) + /** * The range defines where we want to tickbase into. The first value is the minimum range, which we can * tick into, and the second value is the range where we cannot tickbase at all. @@ -68,7 +71,7 @@ internal object ModuleTickBase : ClientModule("TickBase", Category.COMBAT) { private val tickBuffer = mutableListOf() @Suppress("unused") - private val tickHandler = handler { + private val playerTickHandler = handler { // We do not want this module to conflict with blink if (player.vehicle != null || ModuleBlink.running) { return@handler @@ -79,20 +82,14 @@ internal object ModuleTickBase : ClientModule("TickBase", Category.COMBAT) { } } - var duringTickModification = false - @Suppress("unused") - private val postTickHandler = sequenceHandler { + private val tickHandler = tickHandler { // We do not want this module to conflict with blink - if (player.vehicle != null || ModuleBlink.running || duringTickModification) { - return@sequenceHandler - } - - if (tickBuffer.isEmpty()) { - return@sequenceHandler + if (player.vehicle != null || ModuleBlink.running || tickBuffer.isEmpty()) { + return@tickHandler } - val nearbyEnemy = world.findEnemy(0f..range.endInclusive) ?: return@sequenceHandler + val nearbyEnemy = world.findEnemy(0f..range.endInclusive) ?: return@tickHandler val currentDistance = player.pos.squaredDistanceTo(nearbyEnemy.pos) // Find the best tick that is able to hit the target and is not too far away from the player, as well as @@ -117,31 +114,37 @@ internal object ModuleTickBase : ClientModule("TickBase", Category.COMBAT) { val (bestTick, _) = criticalTick ?: possibleTicks.minByOrNull { (index, _) -> index - } ?: return@sequenceHandler + } ?: return@tickHandler if (bestTick == 0) { - return@sequenceHandler + return@tickHandler } // We do not want to tickbase if killaura is not ready to attack if (requiresKillAura && !(ModuleKillAura.running && ModuleKillAura.clickScheduler.isClickOnNextTick(bestTick))) { - return@sequenceHandler + return@tickHandler } - // Tick as much as we can - duringTickModification = true - - ticksToSkip = bestTick + pauseAfterTick - - waitTicks(ticksToSkip) + when (mode) { + TickBaseMode.PAST -> { + ticksToSkip = bestTick + pauseAfterTick + waitTicks(ticksToSkip) + repeat(bestTick) { + player.tick() + tickBalance -= 1 + } + } - repeat(bestTick) { - player.tick() - tickBalance -= 1 + TickBaseMode.FUTURE -> { + repeat(bestTick) { + player.tick() + tickBalance -= 1 + } + ticksToSkip = bestTick + pauseAfterTick + waitTicks(ticksToSkip) + } } - - duringTickModification = false } @Suppress("unused") @@ -172,12 +175,12 @@ internal object ModuleTickBase : ClientModule("TickBase", Category.COMBAT) { val tickRange = 0 until min(tickBalance.toInt(), maxTicksAtATime) val snapshots = simulatedPlayer.getSnapshotsBetween(tickRange) - snapshots.forEach { + snapshots.forEach { snapshot -> tickBuffer += TickData( - it.pos, - it.fallDistance, - it.velocity, - it.onGround + snapshot.pos, + snapshot.fallDistance, + snapshot.velocity, + snapshot.onGround ) } } @@ -202,11 +205,6 @@ internal object ModuleTickBase : ClientModule("TickBase", Category.COMBAT) { } } - override fun disable() { - duringTickModification = false - super.disable() - } - data class TickData( val position: Vec3d, val fallDistance: Float, @@ -214,4 +212,9 @@ internal object ModuleTickBase : ClientModule("TickBase", Category.COMBAT) { val onGround: Boolean ) + private enum class TickBaseMode(override val choiceName: String) : NamedChoice { + PAST("Past"), + FUTURE("Future") + } + }