Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/HEAD'
Browse files Browse the repository at this point in the history
# Conflicts:
#	dist/baritone-api-1.0.0.jar
#	dist/baritone-api-forge-1.0.0.jar
#	dist/baritone-deobf-1.0.0.jar
#	dist/baritone-standalone-1.0.0.jar
#	dist/baritone-standalone-forge-1.0.0.jar
#	dist/baritone-unoptimized-1.0.0.jar
#	dist/checksums.txt
  • Loading branch information
onixiya1337 committed Dec 10, 2023
2 parents 0745fcc + ce2e671 commit b2adf34
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 60 deletions.
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ sourceSets {
compileClasspath += main.compileClasspath + main.runtimeClasspath + main.output
runtimeClasspath += main.compileClasspath + main.runtimeClasspath + main.output
}

test {
compileClasspath += main.compileClasspath + main.runtimeClasspath + main.output
runtimeClasspath += main.compileClasspath + main.runtimeClasspath + main.output
}
}

minecraft {
Expand Down Expand Up @@ -78,6 +83,8 @@ dependencies {
extraLibs("it.unimi.dsi:fastutil:7.1.0")
compile("it.unimi.dsi:fastutil:7.1.0")
compileOnly("com.google.code.findbugs:jsr305:3.0.1")
extraLibs("org.apache.commons:commons-math3:3.6")
compile("org.apache.commons:commons-math3:3.6")
runtime launchCompile("me.djtheredstoner:DevAuth-forge-legacy:1.1.2")
runtime launchCompile('com.github.ImpactDevelopment:SimpleTweaker:1.2')
runtime launchCompile('org.spongepowered:mixin:0.7.11-SNAPSHOT') {
Expand All @@ -87,6 +94,8 @@ dependencies {
exclude module: 'commons-io'
exclude module: 'log4j-core'
}

testImplementation 'junit:junit:4.12'
}

mixin {
Expand Down
1 change: 1 addition & 0 deletions scripts/proguard.pro
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
-libraryjars 'tempLibraries/jopt-simple-4.6.jar'
-libraryjars 'tempLibraries/jsr305-3.0.1.jar'
-libraryjars 'tempLibraries/jutils-1.0.0.jar'
-libraryjars 'tempLibraries/commons-math3-3.6.jar'
-libraryjars 'tempLibraries/libraryjavasound-20101123.jar'
-libraryjars 'tempLibraries/librarylwjglopenal-20100824.jar'
-libraryjars 'tempLibraries/log4j-api-2.0-beta9.jar'
Expand Down
16 changes: 9 additions & 7 deletions src/api/java/baritone/api/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ public class Settings {

public final Setting<Float> pathingMapLoadFactor = new Setting<>(0.75f);

public final Setting<Boolean> allowParkour = new Setting<>(true);
public final Setting<Boolean> allowParkour = new Setting<>(false);

public final Setting<Boolean> allowJumpAt256 = new Setting<>(true);

public final Setting<Boolean> allowParkourAscend = new Setting<>(true);
public final Setting<Boolean> allowParkourAscend = new Setting<>(false);

public final Setting<Float> yawSmoothingFactor = new Setting<>(4f);
public final Setting<Float> yawSmoothingFactor = new Setting<>(0.2f);

public final Setting<Float> pitchSmoothingFactor = new Setting<>(2f);
public final Setting<Float> pitchSmoothingFactor = new Setting<>(0.22f);

public final Setting<Boolean> safeMode = new Setting<>(true);

Expand Down Expand Up @@ -139,9 +139,11 @@ public class Settings {

public final Setting<Boolean> pathThroughCachedOnly = new Setting<>(false);

public final Setting<Double> randomLooking = new Setting<>(1d);
public final Setting<Double> randomLooking = new Setting<>(0d);

public final Setting<Double> randomLooking113 = new Setting<>(0.1d);
public final Setting<Float> blockReachDistance = new Setting<>(4.5f);

public final Setting<Double> randomLooking113 = new Setting<>(0d);

public final Setting<Boolean> freeLook = new Setting<>(false);

Expand All @@ -151,7 +153,7 @@ public class Settings {

public final Setting<Boolean> shortBaritonePrefix = new Setting<>(false);

public final Setting<Boolean> chatDebug = new Setting<>(false);
public final Setting<Boolean> chatDebug = new Setting<>(true);

public final Setting<Boolean> desktopNotifications = new Setting<>(false);

Expand Down
2 changes: 0 additions & 2 deletions src/api/java/baritone/api/utils/CubicBezier.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package baritone.api.utils;

import net.minecraft.util.MathHelper;

import java.util.function.Function;

public class CubicBezier {
Expand Down
3 changes: 2 additions & 1 deletion src/api/java/baritone/api/utils/IPlayerController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package baritone.api.utils;

import baritone.api.BaritoneAPI;
import baritone.api.utils.input.ClickType;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.player.EntityPlayer;
Expand Down Expand Up @@ -33,6 +34,6 @@ public interface IPlayerController {
void setHittingBlock(boolean hittingBlock);

default double getBlockReachDistance() {
return 4.5f;
return this.getGameType().isCreative() ? 5.0F : BaritoneAPI.getSettings().blockReachDistance.value;
}
}
115 changes: 83 additions & 32 deletions src/main/java/baritone/behavior/LookBehavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
import baritone.api.behavior.look.ITickableAimProcessor;
import baritone.api.event.events.*;
import baritone.api.utils.CubicBezier;
import baritone.api.utils.Helper;
import baritone.api.utils.IPlayerContext;
import baritone.api.utils.Interpolator;
import baritone.api.utils.Rotation;
import baritone.behavior.look.ForkableRandom;
import net.minecraft.network.play.client.C03PacketPlayer;
import net.minecraft.util.MathHelper;
import org.apache.commons.math3.analysis.interpolation.SplineInterpolator;
import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction;

import java.util.Optional;

Expand All @@ -25,14 +28,18 @@ public class LookBehavior extends Behavior implements ILookBehavior {

private final AimProcessor processor;

private boolean updated;

public LookBehavior(Baritone baritone) {
super(baritone);
this.processor = new AimProcessor(baritone.getPlayerContext());
this.updated = false;
}

@Override
public void updateTarget(Rotation rotation, boolean blockInteract) {
this.target = new Target(ctx.playerRotations(), rotation, Target.Mode.resolve(blockInteract));
this.updated = true;
}


Expand Down Expand Up @@ -69,21 +76,20 @@ public void onPlayerUpdate(PlayerUpdateEvent event) {
}
case POST: {
if (this.prevRotation != null) {

if (this.target.mode == Target.Mode.SERVER) {
if (this.target.mode == Target.Mode.SERVER && this.updated) {
ctx.player().rotationYaw = prevRotation.getYaw();
ctx.player().rotationPitch = prevRotation.getPitch();
}

this.prevRotation = null;
}

final Rotation interpolated = this.processor.interpolate(this.target.initial, this.target.rotation);
Rotation delta = interpolated.subtract(target.rotation).normalizeAndClamp();
if (Math.abs(delta.getYaw()) < Baritone.settings().randomLooking.value + Baritone.settings().randomLooking113.value &&
Math.abs(delta.getPitch()) < Baritone.settings().randomLooking.value) {
if (!this.updated) {
this.target = null;
}

this.updated = false;

break;
}
default: {
Expand Down Expand Up @@ -139,6 +145,27 @@ protected Rotation getPrevRotation() {
}
}

private static double calculateXForY(PolynomialSplineFunction bezierCurve, double targetY) {
double epsilon = 1e-6;

double x = 0.5;
double yValue = bezierCurve.value(x);
double derivative = bezierCurve.derivative().value(x);

while (Math.abs(yValue - targetY) > epsilon) {
x = x - (yValue - targetY) / derivative;
if (x > 1) {
return 1;
}
if (x < 0) {
return 0;
}
yValue = bezierCurve.value(x);
derivative = bezierCurve.derivative().value(x);
}
return x;
}

private static abstract class AbstractAimProcessor implements ITickableAimProcessor {

protected final IPlayerContext ctx;
Expand All @@ -147,17 +174,47 @@ private static abstract class AbstractAimProcessor implements ITickableAimProces
private double randomYawOffset;
private double randomPitchOffset;

private final PolynomialSplineFunction yawBezier;
private final PolynomialSplineFunction pitchBezier;


public AbstractAimProcessor(IPlayerContext ctx) {
this.ctx = ctx;
this.rand = new ForkableRandom();

CubicBezier yawBezier = new CubicBezier(0.56, 0.17, 0.29, 1); // TODO: Custom beziers perhaps fitting

double[] yawX = new double[11];
double[] yawY = new double[11];

for (int i = 0; i < 11; i++) {
float x = ((float) i) / 10f;
yawX[i] = x;
yawY[i] = yawBezier.calculateYWithX(x);
}

this.yawBezier = new SplineInterpolator().interpolate(yawX, yawY);

CubicBezier pitchBezier = new CubicBezier(0.22,1, 0.36,1);
double[] pitchX = new double[11];
double[] pitchY = new double[11];

for (int i = 0; i < 11; i++) {
float x = ((float) i) / 10f;
pitchX[i] = x;
pitchY[i] = pitchBezier.calculateYWithX(x);
}

this.pitchBezier = new SplineInterpolator().interpolate(pitchX, pitchY);
}

private AbstractAimProcessor(final AbstractAimProcessor source) {
this.ctx = source.ctx;
this.rand = source.rand.fork();
this.randomYawOffset = source.randomYawOffset;
this.randomPitchOffset = source.randomPitchOffset;
this.yawBezier = source.yawBezier;
this.pitchBezier = source.pitchBezier;
}

@Override
Expand All @@ -184,38 +241,32 @@ public final Rotation peekRotation(final Rotation rotation) {
public final Rotation interpolate(final Rotation initial, final Rotation rotation) {
final Rotation prev = this.getPrevRotation();

float yawSmoothingFactor = Baritone.settings().yawSmoothingFactor.value;
float pitchSmoothingFactor = Baritone.settings().pitchSmoothingFactor.value;

Rotation deltaInitial = prev.subtract(initial).normalizeAndClamp();
Rotation delta = rotation.subtract(initial).normalizeAndClamp();

if (Math.abs(delta.getYaw()) > 45) {
yawSmoothingFactor *= 2;
} else if (Math.abs(delta.getYaw()) > 90) {
yawSmoothingFactor *= 3;
double yawProgress = calculateXForY(yawBezier, deltaInitial.getYaw() / delta.getYaw());
yawProgress = Math.ceil(yawProgress * 10) / 10d + Baritone.settings().yawSmoothingFactor.value; // TODO: manage to get this with ticks instead of a factor somehow
if (yawProgress > 1) {
yawProgress = 1;
}
if (Math.abs(delta.getPitch()) > 45) {
pitchSmoothingFactor *= 2;
if (yawProgress < 0) {
yawProgress = 0;
}
float interpolatedYaw = (float) (initial.getYaw() + yawBezier.value(yawProgress) * delta.getYaw()); //TODO: the shit (factor) is to sensitive aswell

float yawProgress = Math.abs(Rotation.normalizeYaw(rotation.getYaw() - initial.getYaw()) / delta.getYaw());
float yawInterpolation = new CubicBezier(0.42,0.04,0.55,0.96).calculateYWithX(yawProgress);

float pitchProgress = Math.abs(Rotation.clampPitch(rotation.getPitch() - initial.getPitch()) / delta.getPitch());
float pitchInterpolation = new CubicBezier(0.33, 1, 0.68, 1).calculateYWithX(pitchProgress);

float desiredYaw = initial.getYaw() + delta.getYaw() * yawInterpolation;
float desiredPitch = initial.getPitch() + delta.getPitch() * pitchInterpolation;

float deltaYaw = Rotation.normalizeYaw(desiredYaw - prev.getYaw());
deltaYaw /= yawSmoothingFactor;

float deltaPitch = Rotation.clampPitch(desiredPitch - prev.getPitch());
deltaPitch /= pitchSmoothingFactor;
double pitchProgress = calculateXForY(pitchBezier, deltaInitial.getPitch() / delta.getPitch());
pitchProgress = Math.ceil(pitchProgress * 10) / 10d + Baritone.settings().pitchSmoothingFactor.value;
if (pitchProgress > 1) {
pitchProgress = 1;
}
if (pitchProgress < 0) {
pitchProgress = 0;
}
float interpolatedPitch = (float) (initial.getPitch() + pitchBezier.value(pitchProgress) * delta.getPitch());

return new Rotation(
this.calculateMouseMove(prev.getYaw(), prev.getYaw() + deltaYaw),
this.calculateMouseMove(prev.getPitch(), prev.getPitch() + deltaPitch)
this.calculateMouseMove(prev.getYaw(), interpolatedYaw),
this.calculateMouseMove(prev.getPitch(), interpolatedPitch)
).clamp();
}

Expand Down
10 changes: 4 additions & 6 deletions src/main/java/baritone/event/GameEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import baritone.api.event.listener.IEventBus;
import baritone.api.event.listener.IGameEventListener;
import baritone.api.pathing.goals.GoalXZ;
import baritone.api.utils.*;
import baritone.pathing.movement.MovementHelper;
import baritone.api.utils.IPlayerContext;
import baritone.utils.BlockStateInterface;

import java.util.List;
Expand Down Expand Up @@ -35,14 +34,13 @@ public void onTick(TickEvent event) {
} else {
baritone.bsi = null;
}
/*

IPlayerContext ctx = baritone.getPlayerContext();
if (ctx.minecraft().gameSettings.keyBindSneak.isPressed()) {
BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().setGoal(new GoalXZ(ctx.playerFeet().x + 50, ctx.playerFeet().z + 50));
BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().setGoal(new GoalXZ(10000, 50000));
BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().findPath(ctx.playerFeet());
}
*/

listeners.forEach(l -> l.onTick(event));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package baritone.pathing.movement;

import baritone.Baritone;
import baritone.KeepName;
import baritone.api.IBaritone;
import baritone.api.pathing.movement.ActionCosts;
import baritone.pathing.precompute.PrecomputedData;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/baritone/pathing/movement/MovementHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ static void setInputs(IPlayerContext ctx, MovementState state, Vec3 dest) {
continue;
}

simulation.copy(ctx.player());
simulation.copy(ctx.player(), ctx);
Vec3 prediction = movement.pred(simulation, ctx);

double distance = prediction.distanceTo(dest);
Expand Down Expand Up @@ -453,7 +453,7 @@ static void setInputsAccurate(IPlayerContext ctx, MovementState state, Vec3 dest
continue;
}

simulation.copy(ctx.player());
simulation.copy(ctx.player(), ctx);
movement.pred(simulation, ctx);
Vec3 prediction = nextMovement.pred(simulation, ctx);

Expand Down Expand Up @@ -484,7 +484,7 @@ static void decreaseMotion(MovementState state, IPlayerContext ctx) {
continue;
}

simulation.copy(ctx.player());
simulation.copy(ctx.player(), ctx);
movement.pred(simulation, ctx);

double distance = simulation.motionX * simulation.motionX + simulation.motionZ * simulation.motionZ;
Expand Down Expand Up @@ -513,7 +513,7 @@ static void decreaseMotion(InputOverrideHandler handler, IPlayerContext ctx) {
continue;
}

simulation.copy(ctx.player());
simulation.copy(ctx.player(), ctx);
movement.pred(simulation, ctx);

double distance = simulation.motionX * simulation.motionX + simulation.motionZ * simulation.motionZ;
Expand Down
Loading

0 comments on commit b2adf34

Please sign in to comment.