From ee79b0772bc1f8e4be0ccef50dbc7edff3a5e141 Mon Sep 17 00:00:00 2001 From: lucas Date: Thu, 5 Dec 2024 15:22:43 +0200 Subject: [PATCH 1/5] feat(ClickScheduler): smart toggle only attacks when needed, might need refactoring --- .../utils/combat/ClickScheduler.kt | 49 +++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/utils/combat/ClickScheduler.kt b/src/main/kotlin/net/ccbluex/liquidbounce/utils/combat/ClickScheduler.kt index a8df184d820..360c5027198 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/utils/combat/ClickScheduler.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/utils/combat/ClickScheduler.kt @@ -18,15 +18,21 @@ */ package net.ccbluex.liquidbounce.utils.combat +import net.ccbluex.liquidbounce.api.oauth.ClientAccountManager.boolean import net.ccbluex.liquidbounce.config.types.Configurable import net.ccbluex.liquidbounce.config.types.NamedChoice import net.ccbluex.liquidbounce.config.types.ToggleableConfigurable import net.ccbluex.liquidbounce.event.EventListener +import net.ccbluex.liquidbounce.event.events.AttackEntityEvent import net.ccbluex.liquidbounce.event.events.GameTickEvent import net.ccbluex.liquidbounce.event.handler import net.ccbluex.liquidbounce.features.module.modules.render.ModuleDebug +import net.ccbluex.liquidbounce.utils.client.chat +import net.ccbluex.liquidbounce.utils.client.player import net.ccbluex.liquidbounce.utils.kotlin.EventPriorityConvention import net.ccbluex.liquidbounce.utils.kotlin.random +import net.fabricmc.fabric.impl.`object`.builder.FabricEntityTypeImpl.Builder.Living +import net.minecraft.entity.LivingEntity import kotlin.random.Random import kotlin.random.nextInt @@ -56,12 +62,16 @@ open class ClickScheduler(val parent: T, showCooldown: Boolean, maxCps: Int = newClickCycle() } private val clickTechnique by enumChoice("Technique", ClickTechnique.STABILIZED) + private val smart by boolean("Smart", false) + private val test by int("test", 5, 1..10) class Cooldown(module: T) : ToggleableConfigurable(module, "Cooldown", true) - where T: EventListener { + where T : EventListener { - private val minimumCooldown by floatRange("Minimum", - 1.0f..1.0f, 0.0f..2.0f) + private val minimumCooldown by floatRange( + "Minimum", + 1.0f..1.0f, 0.0f..2.0f + ) private var nextCooldown = minimumCooldown.random() @@ -114,7 +124,40 @@ open class ClickScheduler(val parent: T, showCooldown: Boolean, maxCps: Int = private fun isOvertime(ticks: Int = 0) = lastClickPassed + (ticks * 50L) > 1000L || (cooldown?.enabled == true && cooldown.readyToAttack(ticks)) + private var shouldClick = true + private var currentEnemy: LivingEntity? = null + + val attackHandler = handler { event -> + val enemy = event.entity + if (enemy is LivingEntity) { + currentEnemy = enemy + } + + shouldClick = player.hurtTime > 0 || + (enemy is LivingEntity && enemy.hurtTime <= test || enemy !is LivingEntity) + + ModuleDebug.debugParameter(this, "ShouldClick", shouldClick) + } + + val gameTickHandler = handler { + resetEnemyIfInvalid() + + if (currentEnemy != null) { + shouldClick = player.hurtTime > 0 || currentEnemy?.hurtTime!! <= 3 + } + } + + private fun resetEnemyIfInvalid() { + if (currentEnemy?.isAlive == false) { + currentEnemy = null + } + } + fun clicks(click: () -> Boolean) { + if (smart && !shouldClick) { + return + } + val clicks = clickCycle?.clicksAt(isOvertime = isOvertime()) ?: return clickCycle?.let { cycle -> From c81ac61054f51ad08ba7146acb1760b1264b954d Mon Sep 17 00:00:00 2001 From: lucas Date: Thu, 5 Dec 2024 15:23:36 +0200 Subject: [PATCH 2/5] i forgot --- .../net/ccbluex/liquidbounce/utils/combat/ClickScheduler.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/utils/combat/ClickScheduler.kt b/src/main/kotlin/net/ccbluex/liquidbounce/utils/combat/ClickScheduler.kt index 360c5027198..9cc017f570a 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/utils/combat/ClickScheduler.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/utils/combat/ClickScheduler.kt @@ -63,7 +63,6 @@ open class ClickScheduler(val parent: T, showCooldown: Boolean, maxCps: Int = } private val clickTechnique by enumChoice("Technique", ClickTechnique.STABILIZED) private val smart by boolean("Smart", false) - private val test by int("test", 5, 1..10) class Cooldown(module: T) : ToggleableConfigurable(module, "Cooldown", true) where T : EventListener { @@ -134,7 +133,7 @@ open class ClickScheduler(val parent: T, showCooldown: Boolean, maxCps: Int = } shouldClick = player.hurtTime > 0 || - (enemy is LivingEntity && enemy.hurtTime <= test || enemy !is LivingEntity) + (enemy is LivingEntity && enemy.hurtTime <= 3 || enemy !is LivingEntity) ModuleDebug.debugParameter(this, "ShouldClick", shouldClick) } From 248c6df651e872232d4202f7394da43343effdfd Mon Sep 17 00:00:00 2001 From: lucas Date: Thu, 5 Dec 2024 16:03:16 +0200 Subject: [PATCH 3/5] added criticals check --- .../ccbluex/liquidbounce/utils/combat/ClickScheduler.kt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/utils/combat/ClickScheduler.kt b/src/main/kotlin/net/ccbluex/liquidbounce/utils/combat/ClickScheduler.kt index 9cc017f570a..9702fc3edcd 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/utils/combat/ClickScheduler.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/utils/combat/ClickScheduler.kt @@ -18,7 +18,6 @@ */ package net.ccbluex.liquidbounce.utils.combat -import net.ccbluex.liquidbounce.api.oauth.ClientAccountManager.boolean import net.ccbluex.liquidbounce.config.types.Configurable import net.ccbluex.liquidbounce.config.types.NamedChoice import net.ccbluex.liquidbounce.config.types.ToggleableConfigurable @@ -26,12 +25,11 @@ import net.ccbluex.liquidbounce.event.EventListener import net.ccbluex.liquidbounce.event.events.AttackEntityEvent import net.ccbluex.liquidbounce.event.events.GameTickEvent import net.ccbluex.liquidbounce.event.handler +import net.ccbluex.liquidbounce.features.module.modules.combat.criticals.ModuleCriticals import net.ccbluex.liquidbounce.features.module.modules.render.ModuleDebug -import net.ccbluex.liquidbounce.utils.client.chat import net.ccbluex.liquidbounce.utils.client.player import net.ccbluex.liquidbounce.utils.kotlin.EventPriorityConvention import net.ccbluex.liquidbounce.utils.kotlin.random -import net.fabricmc.fabric.impl.`object`.builder.FabricEntityTypeImpl.Builder.Living import net.minecraft.entity.LivingEntity import kotlin.random.Random import kotlin.random.nextInt @@ -133,7 +131,8 @@ open class ClickScheduler(val parent: T, showCooldown: Boolean, maxCps: Int = } shouldClick = player.hurtTime > 0 || - (enemy is LivingEntity && enemy.hurtTime <= 3 || enemy !is LivingEntity) + (enemy is LivingEntity && enemy.hurtTime <= 3 || enemy !is LivingEntity) || + ModuleCriticals.canDoCriticalHit() ModuleDebug.debugParameter(this, "ShouldClick", shouldClick) } @@ -142,7 +141,7 @@ open class ClickScheduler(val parent: T, showCooldown: Boolean, maxCps: Int = resetEnemyIfInvalid() if (currentEnemy != null) { - shouldClick = player.hurtTime > 0 || currentEnemy?.hurtTime!! <= 3 + shouldClick = player.hurtTime > 0 || currentEnemy?.hurtTime!! <= 3 || ModuleCriticals.canDoCriticalHit() } } From 1cb62828bc83d63ab67925abffd4cbcc69cf65aa Mon Sep 17 00:00:00 2001 From: lucas Date: Thu, 5 Dec 2024 21:23:18 +0200 Subject: [PATCH 4/5] refactor --- .../utils/combat/ClickScheduler.kt | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/utils/combat/ClickScheduler.kt b/src/main/kotlin/net/ccbluex/liquidbounce/utils/combat/ClickScheduler.kt index 9702fc3edcd..d0d5371da98 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/utils/combat/ClickScheduler.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/utils/combat/ClickScheduler.kt @@ -121,7 +121,18 @@ open class ClickScheduler(val parent: T, showCooldown: Boolean, maxCps: Int = private fun isOvertime(ticks: Int = 0) = lastClickPassed + (ticks * 50L) > 1000L || (cooldown?.enabled == true && cooldown.readyToAttack(ticks)) - private var shouldClick = true + private val shouldClick: Boolean + get() { + if (player.hurtTime > 0 || ModuleCriticals.canDoCriticalHit()) return true + + val enemy = currentEnemy + if (enemy is LivingEntity) { + return enemy.hurtTime <= 3 + } + + return false + } + private var currentEnemy: LivingEntity? = null val attackHandler = handler { event -> @@ -129,20 +140,11 @@ open class ClickScheduler(val parent: T, showCooldown: Boolean, maxCps: Int = if (enemy is LivingEntity) { currentEnemy = enemy } - - shouldClick = player.hurtTime > 0 || - (enemy is LivingEntity && enemy.hurtTime <= 3 || enemy !is LivingEntity) || - ModuleCriticals.canDoCriticalHit() - ModuleDebug.debugParameter(this, "ShouldClick", shouldClick) } val gameTickHandler = handler { resetEnemyIfInvalid() - - if (currentEnemy != null) { - shouldClick = player.hurtTime > 0 || currentEnemy?.hurtTime!! <= 3 || ModuleCriticals.canDoCriticalHit() - } } private fun resetEnemyIfInvalid() { From 06cfd1ece2535f02c7507869b8bbc491e458e675 Mon Sep 17 00:00:00 2001 From: lucas Date: Thu, 5 Dec 2024 21:24:16 +0200 Subject: [PATCH 5/5] fix --- .../net/ccbluex/liquidbounce/utils/combat/ClickScheduler.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/utils/combat/ClickScheduler.kt b/src/main/kotlin/net/ccbluex/liquidbounce/utils/combat/ClickScheduler.kt index d0d5371da98..995ca152c36 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/utils/combat/ClickScheduler.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/utils/combat/ClickScheduler.kt @@ -130,7 +130,7 @@ open class ClickScheduler(val parent: T, showCooldown: Boolean, maxCps: Int = return enemy.hurtTime <= 3 } - return false + return true } private var currentEnemy: LivingEntity? = null