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
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a3da835
baritone settings
sqlerrorthing Dec 16, 2024
1f954e9
AutoWalk: Mode: Smart (Baritone) & refactor
sqlerrorthing Dec 16, 2024
c307c25
detekt'ions fix
sqlerrorthing Dec 16, 2024
371e6c1
Refactoring & PathManager for safety baritone api use
sqlerrorthing Dec 16, 2024
5d33c65
refactoring
sqlerrorthing Dec 16, 2024
f95f7f1
AutoWalk tag
sqlerrorthing Dec 16, 2024
474d3d8
mini fix
sqlerrorthing Dec 16, 2024
0f99074
MixinPlayerMovementInput & Freecam no view bob when baritone goal pro…
sqlerrorthing Dec 16, 2024
337dd4b
fix(freecam) movement while baritone goal
sqlerrorthing Dec 16, 2024
9585b2a
remove semicolon
sqlerrorthing Dec 17, 2024
c4756d8
custom baritone behavior process & rotation fixes
sqlerrorthing Dec 17, 2024
de974aa
Merge remote-tracking branch 'origin/baritone-integration' into barit…
sqlerrorthing Dec 17, 2024
e1adb81
add semicolon OOPS
sqlerrorthing Dec 17, 2024
2a87252
remove useless check
sqlerrorthing Dec 17, 2024
04f7e01
Baritone path control events & KillAura: Pause baritone (when target …
sqlerrorthing Dec 17, 2024
237911a
more settings
sqlerrorthing Dec 17, 2024
0c4b66e
small refactoring
sqlerrorthing Dec 17, 2024
182e8a4
small refactoring
sqlerrorthing Dec 17, 2024
3942d1c
small refactoring
sqlerrorthing Dec 17, 2024
d6e86ce
small refactoring
sqlerrorthing Dec 17, 2024
5c33c28
fix
sqlerrorthing Dec 17, 2024
f8f96c3
fix
sqlerrorthing Dec 17, 2024
c45d7f2
changes by ManInMyVan review
sqlerrorthing Dec 19, 2024
d53784e
ToggleableConfigurable support to baritone settings
sqlerrorthing Dec 19, 2024
7fa8b8e
baritone settings sync (#set ...)
sqlerrorthing Dec 19, 2024
b0087a0
kdoc
sqlerrorthing Dec 19, 2024
432d33d
fully fixed freecam with baritone
sqlerrorthing Dec 19, 2024
a76f779
mini refactoring
sqlerrorthing Dec 19, 2024
0671613
Improved setting implementation
superblaubeere27 Dec 19, 2024
9d9df04
Merge branch 'nextgen' into fork/sqlerrorthing/baritone-integration
superblaubeere27 Dec 19, 2024
578f2cb
Apply suggestions from code review
1zun4 Dec 21, 2024
7c67495
Apply suggestions from code review
1zun4 Dec 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ repositories {
name = "Lenni0451"
url = "https://maven.lenni0451.net/everything"
}
maven {
name = "meteor-maven-snapshots"
url = "https://maven.meteordev.org/snapshots"
}
maven {
name = 'babbaj-maven'
url = 'https://babbaj.github.io/maven/'
}
}

loom {
Expand All @@ -89,6 +97,8 @@ dependencies {
modRuntimeOnly "com.terraformersmc:modmenu:${project.mod_menu_version}"
modImplementation "maven.modrinth:sodium:${project.sodium_version}"
modCompileOnly "de.florianmichael:ViaFabricPlus:${project.viafabricplus_version}"
modImplementation "meteordevelopment:baritone:${project.baritone_version}-SNAPSHOT"
implementation 'dev.babbaj:nether-pathfinder:1.5'
sqlerrorthing marked this conversation as resolved.
Show resolved Hide resolved
superblaubeere27 marked this conversation as resolved.
Show resolved Hide resolved

// Minecraft Authlib
includeDependency ("com.github.CCBlueX:mc-authlib:${project.mc_authlib_version}") {
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ yarn_mappings=1.21.1+build.3
loader_version=0.16.9
min_loader_version=0.15.10

# https://github.com/cabaletta/baritone
baritone_version=1.21.1
# Fabric API
fabric_version=0.107.0+1.21.1
# Loom
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package net.ccbluex.liquidbounce.injection.mixins.baritone;

import baritone.Baritone;
import baritone.api.IBaritone;
import baritone.api.behavior.ILookBehavior;
import baritone.api.event.listener.IEventBus;
import net.ccbluex.liquidbounce.utils.client.baritone.behaviors.LiquidBounceLookBehavior;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

/**
* @author 00101110001100010111000101111
* @since 12/17/2024
**/
@Mixin(Baritone.class)
public abstract class MixinBaritone implements IBaritone {

@Shadow
public abstract IEventBus getGameEventHandler();

@Unique
private LiquidBounceLookBehavior lookBehavior;

@Inject(method = "getLookBehavior", at = @At("HEAD"), cancellable = true, remap = false)
public void hookLookBehavior(CallbackInfoReturnable<ILookBehavior> cir) {
if(lookBehavior == null) {
sqlerrorthing marked this conversation as resolved.
Show resolved Hide resolved
lookBehavior = new LiquidBounceLookBehavior();
getGameEventHandler().registerEventListener(lookBehavior);
}

cir.setReturnValue(lookBehavior);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package net.ccbluex.liquidbounce.injection.mixins.baritone;

import baritone.api.pathing.goals.Goal;
import baritone.process.CustomGoalProcess;
import net.ccbluex.liquidbounce.event.EventManager;
import net.ccbluex.liquidbounce.event.events.BaritoneCustomGoalProcessCreatedEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
* @author 00101110001100010111000101111
* @since 12/17/2024
**/
@Mixin(CustomGoalProcess.class)
public class MixinCustomGoalProcess {

@Inject(method = "setGoal", at = @At("HEAD"), cancellable = true, remap = false)
public void hookSetGoal(Goal goal, CallbackInfo ci) {
var event = new BaritoneCustomGoalProcessCreatedEvent(goal);
EventManager.INSTANCE.callEvent(event);

if(event.isCancelled()) ci.cancel();
sqlerrorthing marked this conversation as resolved.
Show resolved Hide resolved
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.ccbluex.liquidbounce.injection.mixins.baritone;

import baritone.behavior.PathingBehavior;
import net.ccbluex.liquidbounce.event.EventManager;
import net.ccbluex.liquidbounce.event.events.BaritonePathCancelEverythingEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

/**
* @author 00101110001100010111000101111
* @since 12/17/2024
**/
@Mixin(PathingBehavior.class)
public class MixinPathingBehavior {

@Inject(method = "cancelEverything", at = @At("TAIL"), remap = false)
public void hookCancelEverything(CallbackInfoReturnable<Boolean> cir) {
EventManager.INSTANCE.callEvent(new BaritonePathCancelEverythingEvent());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package net.ccbluex.liquidbounce.injection.mixins.baritone;

import baritone.utils.PlayerMovementInput;
import net.ccbluex.liquidbounce.injection.mixins.minecraft.client.MixinInput;
import net.ccbluex.liquidbounce.utils.movement.DirectionalInput;
import net.minecraft.client.MinecraftClient;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(PlayerMovementInput.class)
public class MixinPlayerMovementInput extends MixinInput {

@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, () -> {});
}
Comment on lines +15 to +25
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)


}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@

package net.ccbluex.liquidbounce.injection.mixins.minecraft.client;

import net.ccbluex.liquidbounce.event.EventManager;
import net.ccbluex.liquidbounce.event.events.MovementInputEvent;
import net.ccbluex.liquidbounce.features.module.modules.combat.ModuleSuperKnockback;
import net.ccbluex.liquidbounce.features.module.modules.combat.criticals.ModuleCriticals;
import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleSprint;
import net.ccbluex.liquidbounce.utils.movement.DirectionalInput;
import net.minecraft.client.input.Input;
import net.minecraft.client.input.KeyboardInput;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
Expand Down Expand Up @@ -59,4 +65,36 @@ private void hookOmnidirectionalSprintA(final CallbackInfoReturnable<Boolean> ca
callbackInfoReturnable.setReturnValue(!ModuleSprint.INSTANCE.shouldPreventSprint() && (ModuleSprint.INSTANCE.shouldSprintOmnidirectionally() ? hasMovement : callbackInfoReturnable.getReturnValue()));
}

@Unique
public void proceedKeyboardTick(DirectionalInput baseDirectionalInput, boolean jumping, boolean sneaking, boolean update, Runnable additive) {
var event = new MovementInputEvent(baseDirectionalInput, jumping, sneaking);

EventManager.INSTANCE.callEvent(event);

if (update) {
var directionalInput = event.getDirectionalInput();

this.pressingForward = directionalInput.getForwards();
this.pressingBack = directionalInput.getBackwards();
this.pressingLeft = directionalInput.getLeft();
this.pressingRight = directionalInput.getRight();
this.movementForward = KeyboardInput.getMovementMultiplier(directionalInput.getForwards(), directionalInput.getBackwards());
this.movementSideways = KeyboardInput.getMovementMultiplier(directionalInput.getLeft(), directionalInput.getRight());

additive.run();

if (ModuleSuperKnockback.INSTANCE.shouldStopMoving()) {
this.movementForward = 0f;

ModuleSprint sprint = ModuleSprint.INSTANCE;

if (sprint.shouldSprintOmnidirectionally()) {
this.movementSideways = 0f;
}
}

this.jumping = event.getJumping();
this.sneaking = event.getSneaking();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@
package net.ccbluex.liquidbounce.injection.mixins.minecraft.client;

import net.ccbluex.liquidbounce.event.EventManager;
import net.ccbluex.liquidbounce.event.events.MovementInputEvent;
import net.ccbluex.liquidbounce.event.events.RotatedMovementInputEvent;
import net.ccbluex.liquidbounce.features.module.modules.combat.ModuleSuperKnockback;
import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleInventoryMove;
import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleSprint;
import net.ccbluex.liquidbounce.utils.aiming.AimPlan;
import net.ccbluex.liquidbounce.utils.aiming.Rotation;
import net.ccbluex.liquidbounce.utils.aiming.RotationManager;
Expand All @@ -38,6 +35,7 @@
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
Expand Down Expand Up @@ -68,35 +66,10 @@ private void hookInventoryMoveSprint(boolean slowDown, float f, CallbackInfo ci)

@Inject(method = "tick", at = @At(value = "FIELD", target = "Lnet/minecraft/client/input/KeyboardInput;sneaking:Z", shift = At.Shift.AFTER), allow = 1)
private void injectMovementInputEvent(boolean slowDown, float f, CallbackInfo ci) {
var event = new MovementInputEvent(new DirectionalInput(this.pressingForward, this.pressingBack, this.pressingLeft, this.pressingRight), this.jumping, this.sneaking);

EventManager.INSTANCE.callEvent(event);

var directionalInput = event.getDirectionalInput();

this.pressingForward = directionalInput.getForwards();
this.pressingBack = directionalInput.getBackwards();
this.pressingLeft = directionalInput.getLeft();
this.pressingRight = directionalInput.getRight();
this.movementForward = KeyboardInput.getMovementMultiplier(directionalInput.getForwards(), directionalInput.getBackwards());
this.movementSideways = KeyboardInput.getMovementMultiplier(directionalInput.getLeft(), directionalInput.getRight());

this.fixStrafeMovement();

if (ModuleSuperKnockback.INSTANCE.shouldStopMoving()) {
this.movementForward = 0f;

ModuleSprint sprint = ModuleSprint.INSTANCE;

if (sprint.shouldSprintOmnidirectionally()) {
this.movementSideways = 0f;
}
}

this.jumping = event.getJumping();
this.sneaking = event.getSneaking();
this.proceedKeyboardTick(new DirectionalInput(this.pressingForward, this.pressingBack, this.pressingLeft, this.pressingRight), this.jumping, this.sneaking, true, this::fixStrafeMovement);
}

@Unique
private void fixStrafeMovement() {
ClientPlayerEntity player = MinecraftClient.getInstance().player;
RotationManager rotationManager = RotationManager.INSTANCE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import net.ccbluex.liquidbounce.utils.aiming.RaytracingExtensionsKt;
import net.ccbluex.liquidbounce.utils.aiming.Rotation;
import net.ccbluex.liquidbounce.utils.aiming.RotationManager;
import net.ccbluex.liquidbounce.utils.client.baritone.PathManager;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gl.PostEffectProcessor;
import net.minecraft.client.gui.DrawContext;
Expand Down Expand Up @@ -164,7 +165,8 @@ private void injectHurtCam(MatrixStack matrixStack, float f, CallbackInfo callba

@Inject(method = "bobView", at = @At("HEAD"), cancellable = true)
private void injectBobView(MatrixStack matrixStack, float f, CallbackInfo callbackInfo) {
if (ModuleNoBob.INSTANCE.getRunning() || ModuleTracers.INSTANCE.getRunning()) {
if ((ModuleNoBob.INSTANCE.getRunning() || ModuleTracers.INSTANCE.getRunning())
|| (ModuleFreeCam.INSTANCE.getRunning() && PathManager.Companion.isPathing())) {
callbackInfo.cancel();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ val ALL_EVENT_CLASSES: Array<KClass<out Event>> = arrayOf(
PlayerEquipmentChangeEvent::class,
ClickGuiValueChangeEvent::class,
BlockAttackEvent::class,
QueuePacketEvent::class
QueuePacketEvent::class,
BaritoneCustomGoalProcessCreatedEvent::class,
BaritonePathCancelEverythingEvent::class
sqlerrorthing marked this conversation as resolved.
Show resolved Hide resolved
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package net.ccbluex.liquidbounce.event.events

import baritone.api.pathing.goals.Goal
import net.ccbluex.liquidbounce.event.CancellableEvent
import net.ccbluex.liquidbounce.event.Event
import net.ccbluex.liquidbounce.integration.interop.protocol.event.WebSocketEvent
Expand Down Expand Up @@ -71,6 +72,12 @@ class CancelBlockBreakingEvent : CancellableEvent()
* All events which are related to the minecraft client
*/

@Nameable("baritonePathCancelEverythingEvent")
class BaritonePathCancelEverythingEvent : Event()

@Nameable("baritoneCustomGoalProcessCreated")
class BaritoneCustomGoalProcessCreatedEvent(val goal: Goal) : CancellableEvent()

@Nameable("session")
@WebSocketEvent
class SessionEvent(val session: Session) : Event()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ open class ClientModule(
* If the module is running and in game. Can be overridden to add additional checks.
*/
override val running: Boolean
get() = super.running && inGame && enabled
get() = (super.running && inGame && enabled) || disableActivation
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rotation works for Look behavior


val bind by bind("Bind", InputBind(InputUtil.Type.KEYSYM, bind, bindAction))
.doNotIncludeWhen { !AutoConfig.includeConfiguration.includeBinds }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ import net.ccbluex.liquidbounce.event.events.KeyboardKeyEvent
import net.ccbluex.liquidbounce.event.events.MouseButtonEvent
import net.ccbluex.liquidbounce.event.events.WorldChangeEvent
import net.ccbluex.liquidbounce.event.handler
import net.ccbluex.liquidbounce.features.module.modules.client.ModuleAutoConfig
import net.ccbluex.liquidbounce.features.module.modules.client.ModuleLiquidChat
import net.ccbluex.liquidbounce.features.module.modules.client.ModuleRichPresence
import net.ccbluex.liquidbounce.features.module.modules.client.ModuleTargets
import net.ccbluex.liquidbounce.features.module.modules.client.*
import net.ccbluex.liquidbounce.features.module.modules.combat.*
import net.ccbluex.liquidbounce.features.module.modules.combat.autoarmor.ModuleAutoArmor
import net.ccbluex.liquidbounce.features.module.modules.combat.criticals.ModuleCriticals
Expand Down Expand Up @@ -81,6 +78,7 @@ import net.ccbluex.liquidbounce.features.module.modules.world.packetmine.ModuleP
import net.ccbluex.liquidbounce.features.module.modules.world.scaffold.ModuleScaffold
import net.ccbluex.liquidbounce.features.module.modules.world.traps.ModuleAutoTrap
import net.ccbluex.liquidbounce.script.ScriptApiRequired
import net.ccbluex.liquidbounce.utils.client.baritone.BaritoneUtil
import net.ccbluex.liquidbounce.utils.client.mc
import net.ccbluex.liquidbounce.utils.input.InputBind
import net.ccbluex.liquidbounce.utils.kotlin.mapArray
Expand Down Expand Up @@ -364,6 +362,10 @@ object ModuleManager : EventListener, Iterable<ClientModule> by modules {
builtin += ModuleDebugRecorder
}

if (BaritoneUtil.isAvailable) {
builtin += ModuleBaritone
}
sqlerrorthing marked this conversation as resolved.
Show resolved Hide resolved

builtin.forEach {
addModule(it)
it.walkKeyPath()
Expand Down
Loading