-
-
Notifications
You must be signed in to change notification settings - Fork 514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Auto Rod #5419
Open
baihuamen
wants to merge
7
commits into
CCBlueX:nextgen
Choose a base branch
from
baihuamen:AutoRodCarriedToNextgen
base: nextgen
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+195
−0
Open
feat: Auto Rod #5419
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9740d0b
Add AutoRod and change ModuleManager.
baihuamen a52d81d
improve format and codes,add header and remove MSTimer.kt.
baihuamen c235abd
improve AutoRod TargetTracker
baihuamen 32d4346
Improve code format
baihuamen 084ec4a
modified
baihuamen f5d8aa6
modified
baihuamen 1cd824e
modified
baihuamen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
192 changes: 192 additions & 0 deletions
192
src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/ModuleAutoRod.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,192 @@ | ||||||||
/* | ||||||||
* This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce) | ||||||||
* | ||||||||
* Copyright (c) 2015 - 2025 CCBlueX | ||||||||
* | ||||||||
* LiquidBounce is free software: you can redistribute it and/or modify | ||||||||
* it under the terms of the GNU General Public License as published by | ||||||||
* the Free Software Foundation, either version 3 of the License, or | ||||||||
* (at your option) any later version. | ||||||||
* | ||||||||
* LiquidBounce is distributed in the hope that it will be useful, | ||||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||
* GNU General Public License for more details. | ||||||||
* | ||||||||
* You should have received a copy of the GNU General Public License | ||||||||
* along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>. | ||||||||
*/ | ||||||||
package net.ccbluex.liquidbounce.features.module.modules.combat | ||||||||
|
||||||||
import net.ccbluex.liquidbounce.config.types.ToggleableConfigurable | ||||||||
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.ModuleAutoRod.FacingEnemy.IgnoreOnEnemyLowHealth | ||||||||
import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.ModuleKillAura | ||||||||
import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.features.KillAuraAutoBlock | ||||||||
import net.ccbluex.liquidbounce.utils.client.Chronometer | ||||||||
import net.ccbluex.liquidbounce.utils.client.SilentHotbar | ||||||||
import net.ccbluex.liquidbounce.utils.combat.PriorityEnum | ||||||||
import net.ccbluex.liquidbounce.utils.combat.TargetTracker | ||||||||
import net.ccbluex.liquidbounce.utils.inventory.Slots | ||||||||
import net.minecraft.client.option.KeyBinding | ||||||||
import net.minecraft.entity.Entity | ||||||||
import net.minecraft.entity.LivingEntity | ||||||||
import net.minecraft.item.Items | ||||||||
|
||||||||
|
||||||||
object ModuleAutoRod : ClientModule("AutoRod", Category.COMBAT) { | ||||||||
|
||||||||
superblaubeere27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
object FacingEnemy : ToggleableConfigurable(this, "FacingEnemy", true) { | ||||||||
|
||||||||
superblaubeere27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
object IgnoreOnEnemyLowHealth : ToggleableConfigurable(this, "IgnoreOnEnemyLowHealth", true) { | ||||||||
val enemyHealthThreshold by int( | ||||||||
"EnemyHealthThreshold", 5, 1..20 | ||||||||
) | ||||||||
superblaubeere27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
val playerHealthThreshold by int("PlayerHealthThreshold", 5, 1..20) | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
init { | ||||||||
tree(FacingEnemy) | ||||||||
tree(IgnoreOnEnemyLowHealth) | ||||||||
} | ||||||||
|
||||||||
private val enemiesNearby by int("EnemiesNearby", 1, 1..5) | ||||||||
private val targetTracker = tree(TargetTracker(PriorityEnum.DIRECTION)) | ||||||||
private val escapeHealthThreshold by int("EscapeHealthThreshold", 10, 1..20) | ||||||||
private val pushDelay by int("PushDelay", 100, 50..1000) | ||||||||
private val pullbackDelay by int("PullbackDelay", 500, 50..1000) | ||||||||
superblaubeere27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
private val onUsingItem by boolean("OnUsingItem", false) | ||||||||
private val pushTimer = Chronometer() | ||||||||
private val rodPullTimer = Chronometer() | ||||||||
private var rodInUse = false | ||||||||
private var switchBack: Int = -1 | ||||||||
superblaubeere27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
private var range by float("Range", 5f, 1f..10f) | ||||||||
|
||||||||
override fun disable() { | ||||||||
KeyBinding.setKeyPressed(mc.options.useKey.boundKey, false) | ||||||||
} | ||||||||
|
||||||||
val tickHandler = tickHandler { | ||||||||
// Check if player is using rod | ||||||||
val usingRod = | ||||||||
(player.isUsingItem && player.mainHandStack?.item == Items.FISHING_ROD) || rodInUse | ||||||||
|
||||||||
if (usingRod) { | ||||||||
// Check if rod pull timer has reached delay | ||||||||
// mc.player.fishEntity?.caughtEntity != null is always null | ||||||||
|
||||||||
superblaubeere27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
if (rodPullTimer.hasElapsed(pullbackDelay.toLong())) { | ||||||||
if (switchBack != -1 && player.inventory?.selectedSlot != switchBack) { | ||||||||
// Switch back to previous item | ||||||||
player.inventory?.selectedSlot = switchBack!! | ||||||||
interaction.syncSelectedSlot() | ||||||||
|
||||||||
superblaubeere27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
} else { | ||||||||
// Stop using rod | ||||||||
player.stopUsingItem() | ||||||||
} | ||||||||
|
||||||||
switchBack = -1 | ||||||||
rodInUse = false | ||||||||
|
||||||||
// Reset push timer. Push will always wait for pullback delay. | ||||||||
pushTimer.reset() | ||||||||
} | ||||||||
} else { | ||||||||
var rod = false | ||||||||
|
||||||||
if (FacingEnemy.enabled && player.health >= IgnoreOnEnemyLowHealth.playerHealthThreshold) { | ||||||||
var facingEntity = mc.targetedEntity | ||||||||
if (facingEntity == null) { | ||||||||
|
||||||||
var finalTarget: Entity? = null | ||||||||
finalTarget = targetTracker.lockedOnTarget | ||||||||
if(finalTarget == null) { | ||||||||
return@tickHandler | ||||||||
} | ||||||||
superblaubeere27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
finalTarget.distanceTo(player).let { it1 -> | ||||||||
if (it1 > range || it1 < ModuleKillAura.range && ModuleKillAura.enabled) { | ||||||||
superblaubeere27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
return@tickHandler | ||||||||
} else { | ||||||||
facingEntity = finalTarget | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
// Check whether player is using items/blocking. | ||||||||
if (!onUsingItem) { | ||||||||
if (player.mainHandStack != Items.FISHING_ROD && | ||||||||
(player.isUsingItem) || | ||||||||
KillAuraAutoBlock.blockVisual | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
) { | ||||||||
return@tickHandler | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
if (facingEntity.isAttackable) { | ||||||||
// Checks how many enemy is nearby, if <= then should rod. | ||||||||
var enemieslist = | ||||||||
targetTracker.enemies().filter { it.isAttackable && player.distanceTo(it) < range } | ||||||||
enemieslist.size.let { it1 -> | ||||||||
if (it1 <= enemiesNearby) { | ||||||||
// Check if the enemy's health is below the threshold. | ||||||||
if (IgnoreOnEnemyLowHealth.enabled) { | ||||||||
if ((facingEntity is LivingEntity) && | ||||||||
facingEntity.health >= IgnoreOnEnemyLowHealth.enemyHealthThreshold | ||||||||
superblaubeere27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
) { | ||||||||
rod = true | ||||||||
} | ||||||||
} else { | ||||||||
rod = true | ||||||||
} | ||||||||
|
||||||||
} | ||||||||
} | ||||||||
} else player.health.let { it1 -> | ||||||||
Check warning Code scanning / detekt Braces do not comply with the specified policy Warning
Missing braces on this branch, add them.
|
||||||||
if (it1 <= escapeHealthThreshold) { | ||||||||
// use rod for escaping when health is low. | ||||||||
rod = true | ||||||||
} else if (!FacingEnemy.enabled) { | ||||||||
// Rod anyway, spam it. | ||||||||
rod = true | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
if (rod && pushTimer.hasElapsed(pushDelay.toLong())) { | ||||||||
// Check if player has rod in hand | ||||||||
if (player.mainHandStack != Items.FISHING_ROD) { | ||||||||
// Check if player has rod in hotbar | ||||||||
val rod = Slots.Hotbar.findSlot(Items.FISHING_ROD)?.hotbarSlot | ||||||||
if (rod == null) { | ||||||||
// There is no rod in hotbar | ||||||||
return@tickHandler | ||||||||
} | ||||||||
// Switch to rod | ||||||||
switchBack = player.inventory.getSlotWithStack(player.inventory?.mainHandStack) | ||||||||
SilentHotbar.selectSlotSilently(this,rod) | ||||||||
interaction.syncSelectedSlot() | ||||||||
} | ||||||||
rod() | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
* Use rod | ||||||||
*/ | ||||||||
private fun rod() { | ||||||||
val rod = Slots.Hotbar.findSlot(Items.FISHING_ROD)?.hotbarSlot | ||||||||
if (rod == null) { | ||||||||
return | ||||||||
} | ||||||||
superblaubeere27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
player.inventory?.selectedSlot = rod | ||||||||
// We do not need to send our own packet, because sendUseItem will handle it for us. | ||||||||
KeyBinding.setKeyPressed(mc.options.useKey.boundKey, true) | ||||||||
superblaubeere27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
rodInUse = true | ||||||||
rodPullTimer.reset() | ||||||||
} | ||||||||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.