Skip to content
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
wants to merge 7 commits into
base: nextgen
Choose a base branch
from
Open

Conversation

baihuamen
Copy link

The branch carried AutoRod from legacy to nextgen.

Copy link
Contributor

@EclipsesDev EclipsesDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting header

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this. Use Chronometer.

return -1
}

private fun getAllNearbyEnemies(): List<Entity?>? {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TargetTracker

Comment on lines 212 to 223
/**
* Find rod in inventory
*/
private fun findRod(startSlot: Int, endSlot: Int): Int {
for (i in startSlot until endSlot) {
val stack = mc.player?.inventory?.getStack(i)
if (stack != null && stack.item == Items.FISHING_ROD) {
return i
}
}
return -1
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slots.Hotbar.findSlotIndex(Items.FISHING_ROD)


init {


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format

@1zun4 1zun4 added this to the 0.26.0 milestone Jan 25, 2025
Copy link
Member

@1zun4 1zun4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is clearly a lot that has to be changed on this code, as it does not pass our code standards. However, I will take it in my own hand and look if I can work with your code instead of writing it from scratch.

@1zun4 1zun4 changed the title AutoRodCarriedToNextgen feat: Auto Rod Jan 25, 2025

object ModuleAutoRod : ClientModule("AutoRod", Category.COMBAT) {

object facingEnemy : ToggleableConfigurable(this, "FacingEnemy", true) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"FacingEnemy" - Follow Kotlin Naming Convention


object facingEnemy : ToggleableConfigurable(this, "FacingEnemy", true) {

object ignoreOnEnemyLowHealth : ToggleableConfigurable(this, "IgnoreOnEnemyLowHealth", true) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IgnoreOnEnemyLowHealth same here with Naming Convention.


}
}
} else mc.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.
private val pushTimer = Chronometer()
private val rodPullTimer = Chronometer()
private var rodInUse = false
private var switchBack: Int? = -1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type of Int? is not required to be defined in this case.

Comment on lines +60 to +61
private val pushDelay by int("PushDelay", 100, 50..1000)
private val pullbackDelay by int("PullbackDelay", 500, 50..1000)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No suffix parameter.

val tickHandler = tickHandler {
// Check if player is using rod
val usingRod =
(mc.player?.isUsingItem == true && mc.player?.mainHandStack?.item == Items.FISHING_ROD) || rodInUse
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mc.player.isUsingItem can be replaced with player.isUsingItem

Suggested change
(mc.player?.isUsingItem == true && mc.player?.mainHandStack?.item == Items.FISHING_ROD) || rodInUse
(player.isUsingItem && player.mainHandStack.item == Items.FISHING_ROD) || rodInUse


} else {
// Stop using rod
mc.player?.stopUsingItem()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mc.player?.stopUsingItem()
player.stopUsingItem()

var facingEntity = mc.targetedEntity
if (facingEntity == null) {

var finaltarget: Entity? = null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finaltarget does not follow Kotlin Naming Convention as well - should be finalTarget instead.

Comment on lines 108 to 110
if(finaltarget == null){
return@tickHandler
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(finaltarget == null){
return@tickHandler
}
if(finaltarget == null) {
return@tickHandler
}


if (rod && pushTimer.hasElapsed(pushDelay.toLong())) {
// Check if player has rod in hand
if (mc.player?.mainHandStack != Items.FISHING_ROD) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (mc.player?.mainHandStack != Items.FISHING_ROD) {
if (player.mainHandStack != Items.FISHING_ROD) {

return@tickHandler
}
// Switch to rod
switchBack = mc.player?.inventory?.getSlotWithStack(mc.player?.inventory?.mainHandStack)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
switchBack = mc.player?.inventory?.getSlotWithStack(mc.player?.inventory?.mainHandStack)
switchBack = player.inventory.getSlotWithStack(player.inventory.mainHandStack)

if (rod == null) {
return
}
mc.player?.inventory?.selectedSlot = rod
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not change the selected slot like that in LiquidBounce Nextgen. LiquidBounce Nextgen offers a much util for that instead called SilentHotbar.

}
mc.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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not set key press states in LiquidBounce Nextgen like that. It should rather use the KeybindIsPressedEvent instead.

@baihuamen
Copy link
Author

@1zun4 modified,but I have no idea about using KeybindIsPressedEvent and make it work.So I keep it as it.

Comment on lines +280 to +281


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

private val pushTimer = Chronometer()
private val rodPullTimer = Chronometer()
private var rodInUse = false
private var switchBack: Int = -1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private var switchBack: Int = -1
private var switchBack = -1

Comment on lines +44 to +46
val enemyHealthThreshold by int(
"EnemyHealthThreshold", 5, 1..20
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val enemyHealthThreshold by int(
"EnemyHealthThreshold", 5, 1..20
)
val enemyHealthThreshold by int("EnemyHealthThreshold", 5, 1..20)

object ModuleAutoRod : ClientModule("AutoRod", Category.COMBAT) {

object FacingEnemy : ToggleableConfigurable(this, "FacingEnemy", true) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change



object ModuleAutoRod : ClientModule("AutoRod", Category.COMBAT) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment on lines 163 to 170
val rod = Slots.Hotbar.findSlot(Items.FISHING_ROD)?.hotbarSlot
if (rod == null) {
// There is no rod in hotbar
return@tickHandler
}
// Switch to rod


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val rod = Slots.Hotbar.findSlot(Items.FISHING_ROD)?.hotbarSlot
if (rod == null) {
// There is no rod in hotbar
return@tickHandler
}
// Switch to rod
val rod = Slots.Hotbar.findSlot(Items.FISHING_ROD)?.hotbarSlot ?: return@tickHandler
// Switch to rod

Comment on lines 74 to 75
val usingRod =
(player.isUsingItem == true && player.mainHandStack?.item == Items.FISHING_ROD) || rodInUse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val usingRod =
(player.isUsingItem == true && player.mainHandStack?.item == Items.FISHING_ROD) || rodInUse
val usingRod = player.isUsingItem && player.mainHandStack?.item == Items.FISHING_ROD || rodInUse

// Switch back to previous item
player.inventory?.selectedSlot = switchBack!!
interaction.syncSelectedSlot()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

if (usingRod) {
// Check if rod pull timer has reached delay
// mc.player.fishEntity?.caughtEntity != null is always null

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

} else {
var rod = false

if (FacingEnemy.enabled && player.getActualHealth()!! >= IgnoreOnEnemyLowHealth.playerHealthThreshold) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (FacingEnemy.enabled && player.getActualHealth()!! >= IgnoreOnEnemyLowHealth.playerHealthThreshold) {
if (FacingEnemy.enabled && player.getActualHealth() >= IgnoreOnEnemyLowHealth.playerHealthThreshold) {

any reason you're using getActualHealth here?

return@tickHandler
}
finalTarget.distanceTo(player).let { it1 ->
if (it1 > range || it1 < ModuleKillAura.range && ModuleKillAura.enabled) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you using killaura range?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adapt KillAura simply

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elaborate

Comment on lines 122 to 123
(player.isUsingItem) ||
KillAuraAutoBlock.blockVisual
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(player.isUsingItem) ||
KillAuraAutoBlock.blockVisual
player.isUsingItem || KillAuraAutoBlock.blockVisual

// Check if the enemy's health is below the threshold.
if (IgnoreOnEnemyLowHealth.enabled) {
if ((facingEntity is LivingEntity) &&
facingEntity.health >= IgnoreOnEnemyLowHealth.enemyHealthThreshold
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use getActualHealth() for other entities

Comment on lines +105 to +109
var finalTarget: Entity? = null
finalTarget = targetTracker.lockedOnTarget
if(finalTarget == null) {
return@tickHandler
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var finalTarget: Entity? = null
finalTarget = targetTracker.lockedOnTarget
if(finalTarget == null) {
return@tickHandler
}
val finalTarget = targetTracker.lockedOnTarget ?: return@tickHandler

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.

5 participants