From 67fa91abe8c1e53651b286e07b3bdfad5efbe7ab Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 7 Feb 2019 15:55:39 -0800 Subject: [PATCH] fixes to descend, and goto coords --- .../movement/movements/MovementDescend.java | 7 +- .../baritone/pathing/path/PathExecutor.java | 2 +- .../utils/ExampleBaritoneControl.java | 72 +++++++++++-------- 3 files changed, 50 insertions(+), 31 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index 4f1bce4d..914a2993 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -245,7 +245,7 @@ public class MovementDescend extends Movement { // (dest - src) + dest is offset 1 more in the same direction // so it's the block we'd need to worry about running into if we decide to sprint straight through this descend BlockPos into = dest.subtract(src.down()).add(dest); - if (!MovementHelper.canWalkThrough(ctx, new BetterBlockPos(into)) && MovementHelper.canWalkThrough(ctx, new BetterBlockPos(into).up()) && MovementHelper.canWalkThrough(ctx, new BetterBlockPos(into).up(2))) { + if (skipToAscend()) { // if dest extends into can't walk through, but the two above are can walk through, then we can overshoot and glitch in that weird way return true; } @@ -256,4 +256,9 @@ public class MovementDescend extends Movement { } return false; } + + public boolean skipToAscend() { + BlockPos into = dest.subtract(src.down()).add(dest); + return !MovementHelper.canWalkThrough(ctx, new BetterBlockPos(into)) && MovementHelper.canWalkThrough(ctx, new BetterBlockPos(into).up()) && MovementHelper.canWalkThrough(ctx, new BetterBlockPos(into).up(2)); + } } diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 1b59f8e3..fffae13f 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -398,7 +398,7 @@ public class PathExecutor implements IPathExecutor, Helper { IMovement current = path.movements().get(pathPosition); if (current instanceof MovementDescend) { - if (((MovementDescend) current).safeMode()) { + if (((MovementDescend) current).safeMode() && !((MovementDescend) current).skipToAscend()) { logDebug("Sprinting would be unsafe"); return false; } diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index a5b2b57e..97282a63 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -163,36 +163,19 @@ public class ExampleBaritoneControl extends Behavior implements Helper { } if (msg.startsWith("goal")) { - String[] params = msg.substring(4).trim().split(" "); - if (params[0].equals("")) { - params = new String[]{}; - } + String rest = msg.substring(4).trim(); Goal goal; - try { - switch (params.length) { - case 0: - goal = new GoalBlock(ctx.playerFeet()); - break; - case 1: - if (params[0].equals("clear") || params[0].equals("none")) { - goal = null; - } else { - goal = new GoalYLevel(Integer.parseInt(params[0])); - } - break; - case 2: - goal = new GoalXZ(Integer.parseInt(params[0]), Integer.parseInt(params[1])); - break; - case 3: - goal = new GoalBlock(new BlockPos(Integer.parseInt(params[0]), Integer.parseInt(params[1]), Integer.parseInt(params[2]))); - break; - default: - logDirect("unable to understand lol"); - return true; + if (rest.equals("clear") || rest.equals("none")) { + goal = null; + } else { + String[] params = rest.split(" "); + if (params[0].equals("")) { + params = new String[]{}; + } + goal = parseGoal(params); + if (goal == null) { + return true; } - } catch (NumberFormatException ex) { - logDirect("unable to parse integer " + ex); - return true; } customGoalProcess.setGoal(goal); logDirect("Goal: " + goal); @@ -469,7 +452,11 @@ public class ExampleBaritoneControl extends Behavior implements Helper { if (block == null) { waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getAllWaypoints().stream().filter(w -> w.getName().equalsIgnoreCase(mining)).max(Comparator.comparingLong(IWaypoint::getCreationTimestamp)).orElse(null); if (waypoint == null) { - logDirect("No locations for " + mining + " known, cancelling"); + Goal goal = parseGoal(waypointType.split(" ")); + if (goal != null) { + logDirect("Going to " + goal); + customGoalProcess.setGoalAndPath(goal); + } return true; } } else { @@ -548,4 +535,31 @@ public class ExampleBaritoneControl extends Behavior implements Helper { } } } + + private Goal parseGoal(String[] params) { + Goal goal; + try { + switch (params.length) { + case 0: + goal = new GoalBlock(ctx.playerFeet()); + break; + case 1: + goal = new GoalYLevel(Integer.parseInt(params[0])); + break; + case 2: + goal = new GoalXZ(Integer.parseInt(params[0]), Integer.parseInt(params[1])); + break; + case 3: + goal = new GoalBlock(new BlockPos(Integer.parseInt(params[0]), Integer.parseInt(params[1]), Integer.parseInt(params[2]))); + break; + default: + logDirect("unable to understand lol"); + return null; + } + } catch (NumberFormatException ex) { + logDirect("unable to parse integer " + ex); + return null; + } + return goal; + } }