From dbd760fbcb0c9ac97411c6cdcf2dafb2958de17d Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 13 Feb 2019 18:26:30 -0800 Subject: [PATCH] some polish on ascend sprinting --- src/api/java/baritone/api/Settings.java | 5 +++ .../baritone/pathing/path/PathExecutor.java | 36 ++++++++++++++----- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 95d56a0e4..97ee278ed 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -164,6 +164,11 @@ public final class Settings { */ public final Setting considerPotionEffects = new Setting<>(true); + /** + * Sprint and jump a block early on ascends wherever possible + */ + public final Setting sprintAscends = new Setting<>(true); + /** * This is the big A* setting. * As long as your cost heuristic is an *underestimate*, it's guaranteed to find you the best path. diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 23b5861b9..4321eba29 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -386,11 +386,16 @@ public class PathExecutor implements IPathExecutor, Helper { if (current instanceof MovementTraverse && pathPosition < path.length() - 2) { IMovement next = path.movements().get(pathPosition + 1); if (next instanceof MovementAscend && sprintableAscend(ctx, (MovementTraverse) current, (MovementAscend) next)) { - logDebug("Skipping traverse to straight ascend"); - pathPosition++; - onChangeInPathPosition(); - onTick(); - return true; + if (skipNow(ctx, current, next)) { + logDebug("Skipping traverse to straight ascend"); + pathPosition++; + onChangeInPathPosition(); + onTick(); + behavior.baritone.getInputOverrideHandler().setInputForceState(Input.JUMP, true); + return true; + } else { + logDebug("Too far to the side to safely sprint ascend"); + } } } @@ -445,16 +450,31 @@ public class PathExecutor implements IPathExecutor, Helper { return false; } + private static boolean skipNow(IPlayerContext ctx, IMovement current, IMovement next) { + double offTarget = Math.abs(current.getDirection().getX() * (current.getSrc().z + 0.5D - ctx.player().posZ)) + Math.abs(current.getDirection().getZ() * (current.getSrc().x + 0.5D - ctx.player().posX)); + if (offTarget > 0.1) { + return false; + } + // we are centered + BlockPos headBonk = current.getSrc().subtract(current.getDirection()).up(2); + if (MovementHelper.fullyPassable(ctx.world().getBlockState(headBonk))) { + return true; + } + // wait 0.3 + double flatDist = Math.abs(current.getDirection().getX() * (headBonk.getX() + 0.5D - ctx.player().posX)) + Math.abs(current.getDirection().getZ() * (headBonk.getZ() + 0.5 - ctx.player().posZ)); + return flatDist > 0.8; + } + private static boolean sprintableAscend(IPlayerContext ctx, MovementTraverse current, MovementAscend next) { + if (!Baritone.settings().sprintAscends.get()) { + return false; + } if (!current.getDirection().equals(next.getDirection().down())) { return false; } if (!MovementHelper.canWalkOn(ctx, current.getDest().down())) { return false; } - if (!next.headBonkClear()) { - return false; - } for (int x = 0; x < 2; x++) { for (int y = 0; y < 3; y++) { BlockPos chk = current.getSrc().up(y);