This commit is contained in:
Brady 2023-06-29 14:14:49 -05:00
parent 48462da473
commit fbb66a0586
No known key found for this signature in database
GPG Key ID: 73A788379A197567
2 changed files with 43 additions and 38 deletions

View File

@ -61,9 +61,6 @@ public final class Settings {
public final Setting<Boolean> elytraAutoJump = new Setting<>(false); public final Setting<Boolean> elytraAutoJump = new Setting<>(false);
public final Setting<Boolean> smoothLook = new Setting<>(false); public final Setting<Boolean> smoothLook = new Setting<>(false);
// Experimental Elytra Settings
public final Setting<Boolean> experimentalTakeoff = new Setting<>(false);
/** /**
* Allow Baritone to break blocks * Allow Baritone to break blocks
*/ */

View File

@ -54,7 +54,6 @@ import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.function.Supplier;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
public final class ElytraBehavior extends Behavior implements IElytraBehavior, Helper { public final class ElytraBehavior extends Behavior implements IElytraBehavior, Helper {
@ -540,19 +539,17 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
for (int i = Math.min(playerNear + 20, path.size() - 1); i >= minStep; i--) { for (int i = Math.min(playerNear + 20, path.size() - 1); i >= minStep; i--) {
final List<Pair<Vec3d, Integer>> candidates = new ArrayList<>(); final List<Pair<Vec3d, Integer>> candidates = new ArrayList<>();
for (int dy : heights) { for (int dy : heights) {
if (relaxation == 0 || i == minStep) { if (i == minStep) {
// no interp // no interp
candidates.add(new Pair<>(path.getVec(i).add(0, dy, 0), dy)); candidates.add(new Pair<>(path.getVec(i).add(0, dy, 0), dy));
} else if (relaxation == 1) { } else if (relaxation < 2) {
// Create 4 points along the segment final double[] interps = relaxation == 0
final double[] interps = new double[]{1.0, 0.75, 0.5, 0.25}; ? new double[]{1.0, 0.75, 0.5, 0.25}
: new double[]{1.0, 0.875, 0.75, 0.625, 0.5, 0.375, 0.25, 0.125};
for (double interp : interps) { for (double interp : interps) {
Vec3d dest; final Vec3d dest = interp == 1.0
if (interp == 1) { ? path.getVec(i)
dest = path.getVec(i); : path.getVec(i).scale(interp).add(path.getVec(i - 1).scale(1.0 - interp));
} else {
dest = path.getVec(i).scale(interp).add(path.getVec(i - 1).scale(1.0d - interp));
}
candidates.add(new Pair<>(dest.add(0, dy, 0), dy)); candidates.add(new Pair<>(dest.add(0, dy, 0), dy));
} }
} else { } else {
@ -641,7 +638,7 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
logDirect("no fireworks"); logDirect("no fireworks");
return; return;
} }
logDirect("attempting to use firework" + (forceUseFirework ? " takeoff" : "")); logDirect("attempting to use firework" + (forceUseFirework ? " (forced)" : ""));
ctx.playerController().processRightClick(ctx.player(), ctx.world(), EnumHand.MAIN_HAND); ctx.playerController().processRightClick(ctx.player(), ctx.world(), EnumHand.MAIN_HAND);
this.minimumBoostTicks = 10 * (1 + getFireworkBoost(ctx.player().getHeldItemMainhand()).orElse(0)); this.minimumBoostTicks = 10 * (1 + getFireworkBoost(ctx.player().getHeldItemMainhand()).orElse(0));
this.remainingFireworkTicks = 10; this.remainingFireworkTicks = 10;
@ -885,17 +882,19 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
} }
@FunctionalInterface @FunctionalInterface
private interface IntBiFunction<T> { private interface IntTriFunction<T> {
T apply(int left, int right); T apply(int first, int second, int third);
} }
private static final class IntPair { private static final class IntTriple {
public final int first; public final int first;
public final int second; public final int second;
public final int third;
public IntPair(int first, int second) { public IntTriple(int first, int second, int third) {
this.first = first; this.first = first;
this.second = second; this.second = second;
this.third = third;
} }
} }
@ -906,44 +905,52 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
final float goodPitch = RotationUtils.calcRotationFromVec3d(context.start, goal, ctx.playerRotations()).getPitch(); final float goodPitch = RotationUtils.calcRotationFromVec3d(context.start, goal, ctx.playerRotations()).getPitch();
final FloatArrayList pitches = pitchesToSolveFor(goodPitch, desperate); final FloatArrayList pitches = pitchesToSolveFor(goodPitch, desperate);
final IntBiFunction<PitchResult> solve = (ticks, ticksBoosted) -> final IntTriFunction<PitchResult> solve = (ticks, ticksBoosted, ticksBoostDelay) ->
this.solvePitch(context, goal, relaxation, pitches.iterator(), ticks, ticksBoosted, ignoreLava); this.solvePitch(context, goal, relaxation, pitches.iterator(), ticks, ticksBoosted, ticksBoostDelay, ignoreLava);
final List<IntPair> tests = new ArrayList<>(); final List<IntTriple> tests = new ArrayList<>();
if (context.boost.isBoosted()) { if (context.boost.isBoosted()) {
final int guaranteed = context.boost.getGuaranteedBoostTicks(); final int guaranteed = context.boost.getGuaranteedBoostTicks();
if (guaranteed == 0) { if (guaranteed == 0) {
// uncertain when boost will run out // uncertain when boost will run out
final int lookahead = Math.max(4, 10 - context.boost.getMaximumBoostTicks()); final int lookahead = Math.max(4, 10 - context.boost.getMaximumBoostTicks());
tests.add(new IntPair(lookahead, 1)); tests.add(new IntTriple(lookahead, 1, 0));
tests.add(new IntPair(5, 5)); tests.add(new IntTriple(5, 5, 0));
} else if (guaranteed <= 5) { } else if (guaranteed <= 5) {
// boost will run out within 5 ticks // boost will run out within 5 ticks
tests.add(new IntPair(guaranteed + 5, guaranteed)); tests.add(new IntTriple(guaranteed + 5, guaranteed, 0));
} else { } else {
// there's plenty of guaranteed boost // there's plenty of guaranteed boost
tests.add(new IntPair(guaranteed + 1, guaranteed)); tests.add(new IntTriple(guaranteed + 1, guaranteed, 0));
} }
} }
// Standard test, assume (not) boosted for entire duration // Standard test, assume (not) boosted for entire duration
final int ticks = desperate ? 3 : context.boost.isBoosted() ? Math.max(5, context.boost.getGuaranteedBoostTicks()) : Baritone.settings().elytraSimulationTicks.value; final int ticks = desperate ? 3 : context.boost.isBoosted() ? Math.max(5, context.boost.getGuaranteedBoostTicks()) : Baritone.settings().elytraSimulationTicks.value;
tests.add(new IntPair(ticks, context.boost.isBoosted() ? ticks : 0)); tests.add(new IntTriple(ticks, context.boost.isBoosted() ? ticks : 0, 0));
final Optional<PitchResult> result = tests.stream() final Optional<PitchResult> result = tests.stream()
.map(i -> solve.apply(i.first, i.second)) .map(i -> solve.apply(i.first, i.second, i.third))
.filter(Objects::nonNull) .filter(Objects::nonNull)
.findFirst(); .findFirst();
if (result.isPresent()) { if (result.isPresent()) {
return new Pair<>(result.get().pitch, false); return new Pair<>(result.get().pitch, false);
} }
if (Baritone.settings().experimentalTakeoff.value && relaxation > 0) { // If we used a firework would we be able to get out of the current situation??? perhaps
// Simulate as if we were boosted for the entire duration if (relaxation > 0) {
final PitchResult usingFirework = solve.apply(ticks, ticks); final List<IntTriple> testsBoost = new ArrayList<>();
if (usingFirework != null) { testsBoost.add(new IntTriple(ticks, 10, 3));
return new Pair<>(usingFirework.pitch, true); testsBoost.add(new IntTriple(ticks, 10, 2));
testsBoost.add(new IntTriple(ticks, 10, 1));
final Optional<PitchResult> resultBoost = testsBoost.stream()
.map(i -> solve.apply(i.first, i.second, i.third))
.filter(Objects::nonNull)
.findFirst();
if (resultBoost.isPresent()) {
return new Pair<>(resultBoost.get().pitch, true);
} }
} }
@ -952,7 +959,7 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
private PitchResult solvePitch(final SolverContext context, final Vec3d goal, final int relaxation, private PitchResult solvePitch(final SolverContext context, final Vec3d goal, final int relaxation,
final FloatIterator pitches, final int ticks, final int ticksBoosted, final FloatIterator pitches, final int ticks, final int ticksBoosted,
final boolean ignoreLava) { final int ticksBoostDelay, final boolean ignoreLava) {
// we are at a certain velocity, but we have a target velocity // we are at a certain velocity, but we have a target velocity
// what pitch would get us closest to our target velocity? // what pitch would get us closest to our target velocity?
// yaw is easy so we only care about pitch // yaw is easy so we only care about pitch
@ -971,6 +978,7 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
pitch, pitch,
ticks, ticks,
ticksBoosted, ticksBoosted,
ticksBoostDelay,
ignoreLava ignoreLava
); );
if (displacement == null) { if (displacement == null) {
@ -980,7 +988,7 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
final Vec3d last = displacement.get(lastIndex); final Vec3d last = displacement.get(lastIndex);
final double goodness = goalDirection.dotProduct(last.normalize()); final double goodness = goalDirection.dotProduct(last.normalize());
if (result == null || goodness > result.dot) { if (result == null || goodness > result.dot) {
if (relaxation == 0) { if (relaxation < 2) {
// Ensure that the goal is visible along the entire simulated path // Ensure that the goal is visible along the entire simulated path
// Reverse order iteration since the last position is most likely to fail // Reverse order iteration since the last position is most likely to fail
for (int i = lastIndex; i >= 1; i--) { for (int i = lastIndex; i >= 1; i--) {
@ -988,7 +996,7 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
continue outer; continue outer;
} }
} }
} else if (relaxation == 1) { } else {
// Ensure that the goal is visible from the final position // Ensure that the goal is visible from the final position
if (!clearView(context.start.add(last), goal, false)) { if (!clearView(context.start.add(last), goal, false)) {
continue; continue;
@ -1004,7 +1012,7 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
} }
private List<Vec3d> simulate(final ITickableAimProcessor aimProcessor, final Vec3d goalDelta, final float pitch, private List<Vec3d> simulate(final ITickableAimProcessor aimProcessor, final Vec3d goalDelta, final float pitch,
final int ticks, int ticksBoosted, final boolean ignoreLava) { final int ticks, int ticksBoosted, final int ticksBoostDelay, final boolean ignoreLava) {
Vec3d delta = goalDelta; Vec3d delta = goalDelta;
Vec3d motion = ctx.playerMotion(); Vec3d motion = ctx.playerMotion();
AxisAlignedBB hitbox = ctx.player().getEntityBoundingBox(); AxisAlignedBB hitbox = ctx.player().getEntityBoundingBox();
@ -1042,7 +1050,7 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
hitbox = hitbox.offset(motion); hitbox = hitbox.offset(motion);
displacement.add(displacement.get(displacement.size() - 1).add(motion)); displacement.add(displacement.get(displacement.size() - 1).add(motion));
if (ticksBoosted-- > 0) { if (i >= ticksBoostDelay && ticksBoosted-- > 0) {
// See EntityFireworkRocket // See EntityFireworkRocket
motion = motion.add( motion = motion.add(
lookDirection.x * 0.1 + (lookDirection.x * 1.5 - motion.x) * 0.5, lookDirection.x * 0.1 + (lookDirection.x * 1.5 - motion.x) * 0.5,