Move Minecraft to IPlayerContext

This commit is contained in:
Brady
2023-06-13 21:17:42 -05:00
parent ab3d9e9c47
commit 382f82b0e0
7 changed files with 19 additions and 16 deletions

View File

@@ -97,7 +97,7 @@ public class Baritone implements IBaritone {
this.gameEventHandler = new GameEventHandler(this);
// Define this before behaviors try and get it, or else it will be null and the builds will fail!
this.playerContext = new BaritonePlayerContext(this);
this.playerContext = new BaritonePlayerContext(this, mc);
{
// the Behavior constructor calls baritone.registerBehavior(this) so this populates the behaviors arraylist
@@ -226,10 +226,6 @@ public class Baritone implements IBaritone {
}).start();
}
public Minecraft getMinecraft() {
return this.mc;
}
public static Settings settings() {
return BaritoneAPI.getSettings();
}

View File

@@ -176,7 +176,7 @@ public final class LookBehavior extends Behavior implements ILookBehavior {
}
private float mouseToAngle(int mouseDelta) {
final float f = baritone.getMinecraft().gameSettings.mouseSensitivity * 0.6f + 0.2f;
final float f = ctx.minecraft().gameSettings.mouseSensitivity * 0.6f + 0.2f;
return mouseDelta * f * f * f * 8.0f * 0.15f;
}

View File

@@ -238,14 +238,13 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
@Override
public void onPlayerUpdate(PlayerUpdateEvent event) {
if (current != null) {
final GameSettings settings = baritone.getMinecraft().gameSettings;
switch (event.getState()) {
case PRE:
lastAutoJump = settings.autoJump;
settings.autoJump = false;
lastAutoJump = ctx.minecraft().gameSettings.autoJump;
ctx.minecraft().gameSettings.autoJump = false;
break;
case POST:
settings.autoJump = lastAutoJump;
ctx.minecraft().gameSettings.autoJump = lastAutoJump;
break;
default:
break;

View File

@@ -99,7 +99,7 @@ public final class InputOverrideHandler extends Behavior implements IInputOverri
}
} else {
if (ctx.player().movementInput.getClass() == PlayerMovementInput.class) { // allow other movement inputs that aren't this one, e.g. for a freecam
ctx.player().movementInput = new MovementInputFromOptions(baritone.getMinecraft().gameSettings);
ctx.player().movementInput = new MovementInputFromOptions(ctx.minecraft().gameSettings);
}
}
// only set it if it was previously incorrect

View File

@@ -37,10 +37,15 @@ public final class BaritonePlayerContext implements IPlayerContext {
private final Minecraft mc;
private final IPlayerController playerController;
public BaritonePlayerContext(Baritone baritone) {
public BaritonePlayerContext(Baritone baritone, Minecraft mc) {
this.baritone = baritone;
this.mc = baritone.getMinecraft();
this.playerController = new BaritonePlayerController(baritone);
this.mc = mc;
this.playerController = new BaritonePlayerController(mc);
}
@Override
public Minecraft minecraft() {
return this.mc;
}
@Override

View File

@@ -44,8 +44,8 @@ public final class BaritonePlayerController implements IPlayerController {
private final Minecraft mc;
public BaritonePlayerController(Baritone baritone) {
this.mc = baritone.getMinecraft();
public BaritonePlayerController(Minecraft mc) {
this.mc = mc;
}
@Override