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(Nextgen): Baritone Integration #4918

Open
wants to merge 32 commits into
base: nextgen
Choose a base branch
from

Conversation

sqlerrorthing
Copy link
Contributor

@sqlerrorthing sqlerrorthing commented Dec 16, 2024

Baritone integration for [FEATURE] Add baritone integration? #4892
(for 1.21.1 i found & used this baritone fork by MeteorDevelopment

TODOs


  • Settings in ui
    java_MEadaPVAMQ
  • AutoWalk: Mode: Baritone
2024-12-16.20-38-15.mp4
  • Freecam: Fix...
    • Movement
    • Rotation
    • Interaction
2024-12-16.18-56-40.mp4

@larryngton2
Copy link
Contributor

great

@sqlerrorthing
Copy link
Contributor Author

@1zun4 please fix the freecam and baritone conflicts, I can't do it as I haven't quite figured out the codebase yet

build.gradle Show resolved Hide resolved
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.

I just wanted to say that the way the settings are made is just beautiful. Lol.

@1zun4
Copy link
Member

1zun4 commented Dec 16, 2024

@1zun4 please fix the freecam and baritone conflicts, I can't do it as I haven't quite figured out the codebase yet

Sure, I will do that.

@sqlerrorthing
Copy link
Contributor Author

I just wanted to say that the way the settings are made is just beautiful. Lol.

thank u

@sqlerrorthing
Copy link
Contributor Author

Fix it: the [MovementInputEvent] is no longer called when the baritone is pathing

@sqlerrorthing
Copy link
Contributor Author

sqlerrorthing commented Dec 16, 2024

i think we need to rewrite baritone's [LookBehavior] to fix all rotations & interact issues

2024-12-17.07-25-51.mp4

@sqlerrorthing
Copy link
Contributor Author

IMG_20241217_104545_031.jpg

@DataM0del
Copy link
Contributor

@sqlerrorthing
Copy link
Contributor Author

todo: fix baritone interactions through freecam

2024-12-17.14-58-37.mp4

@sqlerrorthing sqlerrorthing marked this pull request as ready for review December 17, 2024 10:22
@sqlerrorthing
Copy link
Contributor Author

The only thing left to fix is todo: fix baritone interactions through freecam.

@sqlerrorthing
Copy link
Contributor Author

sqlerrorthing commented Dec 17, 2024

Current settings structure (in gui):

  • Break (allowBreak)
  • Place (allowPlace)
  • Rotations
    • (Rotation....)
  • Movement
    • Sprint (allowSprint)
    • JumpAt256 (allowJumpAt256)
    • Ascends
      • Diagonal (allowDiagonalAscend)
      • WithSprint (sprintAscends)
      • Parkour (allowParkourAscend)
    • Descends
      • Diagonal (allowDiagonalDescend)
      • OvershootDiagonal (allowOvershootDiagonalDescend)
    • Parkour
      • Allow (allowParkour)
      • Place (allowParkourPlace)
  • Assumptions
    • Step (assumeStep)
    • Walk
      • Water (assumeWalkOnWater)
      • Lava (assumeWalkOnLava)
      • Safe (SafeWalk) (assumeSafeWalk)
  • Penalties
    • WalkOnWater (walkOnWaterOnePenalty)
    • Jump (jumpPenalty)
    • Blocks
      • Placement (blockPlacementPenalty)
      • BreakAdditional (blockBreakAdditionalPenalty)
      • BreakCorrectBlockMultiplier (breakCorrectBlockPenaltyMultiplier)
      • PlaceIncorrectBlockMultiplier (placeIncorrectBlockPenaltyMultiplier)
  • Mining
    • MinYLevel (minYLevelWhileMining)
    • MaxYLevel (maxYLevelWhileMining)
    • GoalUpdateInterval (mineGoalUpdateInterval)
    • MaxOreLocationsCount (mineMaxOreLocationsCount)
    • PauseForFallingBlocks (pauseMiningForFallingBlocks)
    • ForceInternal (forceInternalMining)
    • OnlyExposedOres (allowOnlyExposedOres)
    • UseSword (useSwordToMine)
    • NotificationOnMineFail (notificationOnMineFail)
    • Legit (Mine)
      • Allow (legitMine)
      • IncludeDiagonals (legitMineIncludeDiagonals)
      • YLevel (legitMineYLevel)
  • Items
    • (Allow) Inventory (allowInventory)
    • AutoTool (autoTool)
  • Elytra
    • SimulationTicks (elytraSimulationTicks)
    • PitchRange (elytraPitchRange)
    • MinimumAvoidance (elytraMinimumAvoidance)
    • PredictTerrain (elytraPredictTerrain)
    • EmergencyLand (elytraAllowEmergencyLand)
    • LandOnNetherFortress (elytraAllowLandOnNetherFortress)
    • Auto
      • Jump (elytraAutoJump)
      • Swap (elytraAutoSwap)
    • Firework
      • Speed (elytraFireworkSpeed)
      • SetbackUseDelay (elytraFireworkSetbackUseDelay)
      • Conserve (elytraConserveFireworks)
    • Render
      • Raytraces (elytraRenderRaytraces)
      • HitboxRaytraces (elytraRenderHitboxRaytraces)
      • Simulation (elytraRenderSimulation)
  • Waypoints
    • Bed (doBedWaypoints)
    • Death (doDeathWaypoints)
  • Colors
    • Path
      • Current (colorCurrentPath)
      • Next (colorNextPath)
      • BestPathSoFar (colorBestPathSoFar)
      • MostRecentConsidered (colorMostRecentConsidered)
    • Blocks
      • ToBreak (colorBlocksToBreak)
      • Next (colorBlocksToPlace)
      • ToWalkInto (colorBlocksToWalkInto)
    • Goal
      • Color (colorGoalBox)
      • Inverted (colorInvertedGoalBox)
    • Selection
      • Color (colorSelection)
      • PosFirst (colorSelectionPos1)
      • PosSecond (colorSelectionPos2)

@sqlerrorthing
Copy link
Contributor Author

2024-12-19.18-19-46.mp4

@sqlerrorthing
Copy link
Contributor Author

all tasks were done

@superblaubeere27 superblaubeere27 self-requested a review December 19, 2024 17:39
Copy link
Contributor

@superblaubeere27 superblaubeere27 left a comment

Choose a reason for hiding this comment

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

This is impressive work overall. Don't be bothered by the big number of complaints. This is a big feature with big changes. 1.5 complaints per 100 lines is not a lot under these circumstances!

build.gradle Show resolved Hide resolved
Comment on lines +15 to +25
@Inject(method = "tick", at = @At("HEAD"))
public void hookTick(boolean par1, float par2, CallbackInfo ci) {
var options = MinecraftClient.getInstance().options;

this.proceedKeyboardTick(new DirectionalInput(
options.forwardKey.isPressed(),
options.backKey.isPressed(),
options.leftKey.isPressed(),
options.rightKey.isPressed()
), options.jumpKey.isPressed(), options.sneakKey.isPressed(), false, () -> {});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure that this is the desired behavior? If LiquidBounce forced the W keybind to be on and the player pressed W at the same time, the moveForward value would end up at 2.0 (MixinInput.proceedKeyboardTick + PlayerMovementInput.tick)

@Mixin(SetCommand.class)
public class MixinSetCommand {

@Inject(method = "execute", at = @At(value = "INVOKE", target = "Lbaritone/command/defaults/SetCommand;logDirect(Ljava/lang/String;)V", ordinal = 9), remap = false)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a terrible injection point. This does not consider other code that might change the setting (bypassing the command). Additionally, using ordinal guarantees that the injection point breaks with the next baritone release.

Comment on lines +309 to +324
/**
* A mutable map for controlling Baritone settings through client-side wrapper ([ModuleBaritone]) settings.
*
* The map key represents a Baritone setting ([Settings.Setting]),
* and the value is a lambda function that serves as a setter for updating the setting's value.
*
* The lambda accepts the current setting value of type [Any], corresponding to
* the generic type T of the original [Settings.Setting.value].
*
* Used for dynamic management and synchronization of Baritone settings
* through intermediate client-side settings.
*
* @see Settings.Setting
* @see MixinSetCommand
*/
private val controlledBaritoneSettingsMutableMap = mutableMapOf<Settings.Setting<*>, (Any) -> Unit>()
Copy link
Contributor

Choose a reason for hiding this comment

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

This is good documentation 👍🏻

But it wouldn't need to be that verbose if you used "anonymous" function pointers ((Any) -> Unit) as a value type. I'd recommend using an interface for that, like:

private interface BaritoneSettingHandle<T> {
    /**
     * Accepts the current setting value of type [Any], corresponding to
     * the generic type T of the original [Settings.Setting.value].
     */
    fun onChange(newValue: T)
}

Comment on lines +326 to +337
/**
* Provides read-only access to the controlled Baritone settings map.
*
* This getter exposes the internal [controlledBaritoneSettingsMutableMap]
* as an immutable [Map], preventing direct modifications from outside the class.
*
* Contains Baritone settings mapped to their respective setter lambdas,
* where each lambda can update the corresponding setting's value.
*
* @return An immutable map of Baritone settings and their setter functions
*/
val controlledBaritoneSettings: Map<Settings.Setting<*>, (Any) -> Unit> get() = controlledBaritoneSettingsMutableMap
Copy link
Contributor

Choose a reason for hiding this comment

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

Again: If you have much documentation for a little, simple piece of code, there is probably something wrong with it.

I think the problem here is that you implemented the feature in the wrong place, here is what I mean:

The functionality of registering changes of a baritone setting is a feature of ModuleBaritone. It must implement it. The caller should not care about how it is implemented.

But you have big parts of the implementation in MixinSetCommand?:

        var onChangeListener = ModuleBaritoneKt.getControlledBaritoneSettings()
                .getOrDefault(setting, null);

        if(onChangeListener != null) {
            onChangeListener.invoke(setting.value);
        }

The mixin code isn't responsible for deciding what happens if the given setting is unknown. The mixin isn't responsible for looking it up in the first place. It's only job is to call ModuleBaritone.notifySettingChange (or a different name).

Comment on lines -107 to 138
fun cleanup() {
unlock()
fun cleanup(unpauseBaritone: Boolean = false) {
unlock(unpauseBaritone = unpauseBaritone)
}

fun lock(entity: LivingEntity, reportToUI: Boolean = true) {
fun lock(entity: LivingEntity, reportToUI: Boolean = true, pauseBaritone: Boolean = false) {
lockedOnTarget = entity

if (pauseBaritone && PathManager.isPathing) {
PathManager.pause()
}

if (entity is PlayerEntity && reportToUI) {
EventManager.callEvent(TargetChangeEvent(PlayerData.fromPlayer(entity)))
}
}

private fun unlock() {
private fun unlock(unpauseBaritone: Boolean = false) {
lockedOnTarget = null

if (unpauseBaritone && PathManager.hasPath) {
PathManager.resume()
}
}

fun validateLock(validator: (Entity) -> Boolean) {
fun validateLock(unpauseBaritone: Boolean = false, validator: (Entity) -> Boolean) {
val lockedOnTarget = lockedOnTarget ?: return

if (!validate(lockedOnTarget) || !validator(lockedOnTarget)) {
this.lockedOnTarget = null
unlock(unpauseBaritone)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I dislike that pauseBaritone is implemented in TargetTracker, while it is only a feature of KillAura. (If something is not a feature of a class, it should be never implemented there!)

The solution: Dependency injection:

class TargetTracker(
 // ...
    changeListener: ChangeListener = ChangeListener.Default
// ...
) {
// ...
interface ChangeListener {
    fun onLock(newTarget: Entity)
    fun onUnlock(oldTarget: Entity)

    object Default : ChangeListener {
        // ...
    }
}
// ...


fun shouldDisableRotations() = running && !allowRotationChange
fun shouldDisableRotations() = running && !allowRotationChange && !PathManager.isPathing
Copy link
Contributor

Choose a reason for hiding this comment

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

DRY. !allowRotationChange && !PathManager.isPathing is three times in this file. Bugs will occur when someone only changes one of them

Copy link
Contributor

Choose a reason for hiding this comment

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

(100% unfunny joke start) I will repeat myself.
I will repeat myself.
I will repeat myself. (100% unfunny joke end)

* - This interface supports basic pathing operations such as moving to a specific position, pausing, resuming,
* and stopping an active path.
*/
interface PathManager {
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, very good documentation 👍🏻

fun stop() {}

companion object : PathManager {
private val Default by lazy {
Copy link
Contributor

Choose a reason for hiding this comment

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

Naming convention

Comment on lines +25 to +29
* if (!PathManager) { ... }
* ```
* and
* ```
* if (!PathManager.isBaritone) { ... }
Copy link
Contributor

Choose a reason for hiding this comment

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

If you ask the question if not PathManager, do this else do that, the user expects the statement to do something like if PathManager is not null, ... while it really is if Baritone Pathing is available, ....

Kotlin has these cool features (like the not() operator) , but reducing the code intuitiveness by using them is not helpful.

superblaubeere27 and others added 4 commits December 19, 2024 21:46
# Conflicts:
#	src/main/kotlin/net/ccbluex/liquidbounce/features/module/ModuleManager.kt
#	src/main/resources/assets/liquidbounce/lang/en_us.json
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.

6 participants