fixes to descend, and goto coords

This commit is contained in:
Leijurv 2019-02-07 15:55:39 -08:00
parent 6faa7344aa
commit 67fa91abe8
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
3 changed files with 50 additions and 31 deletions

View File

@ -245,7 +245,7 @@ public class MovementDescend extends Movement {
// (dest - src) + dest is offset 1 more in the same direction // (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 // 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); 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 // 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; return true;
} }
@ -256,4 +256,9 @@ public class MovementDescend extends Movement {
} }
return false; 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));
}
} }

View File

@ -398,7 +398,7 @@ public class PathExecutor implements IPathExecutor, Helper {
IMovement current = path.movements().get(pathPosition); IMovement current = path.movements().get(pathPosition);
if (current instanceof MovementDescend) { if (current instanceof MovementDescend) {
if (((MovementDescend) current).safeMode()) { if (((MovementDescend) current).safeMode() && !((MovementDescend) current).skipToAscend()) {
logDebug("Sprinting would be unsafe"); logDebug("Sprinting would be unsafe");
return false; return false;
} }

View File

@ -163,36 +163,19 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
} }
if (msg.startsWith("goal")) { if (msg.startsWith("goal")) {
String[] params = msg.substring(4).trim().split(" "); String rest = msg.substring(4).trim();
if (params[0].equals("")) {
params = new String[]{};
}
Goal goal; Goal goal;
try { if (rest.equals("clear") || rest.equals("none")) {
switch (params.length) { goal = null;
case 0: } else {
goal = new GoalBlock(ctx.playerFeet()); String[] params = rest.split(" ");
break; if (params[0].equals("")) {
case 1: params = new String[]{};
if (params[0].equals("clear") || params[0].equals("none")) { }
goal = null; goal = parseGoal(params);
} else { if (goal == null) {
goal = new GoalYLevel(Integer.parseInt(params[0])); return true;
}
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;
} }
} catch (NumberFormatException ex) {
logDirect("unable to parse integer " + ex);
return true;
} }
customGoalProcess.setGoal(goal); customGoalProcess.setGoal(goal);
logDirect("Goal: " + goal); logDirect("Goal: " + goal);
@ -469,7 +452,11 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
if (block == null) { if (block == null) {
waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getAllWaypoints().stream().filter(w -> w.getName().equalsIgnoreCase(mining)).max(Comparator.comparingLong(IWaypoint::getCreationTimestamp)).orElse(null); waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getAllWaypoints().stream().filter(w -> w.getName().equalsIgnoreCase(mining)).max(Comparator.comparingLong(IWaypoint::getCreationTimestamp)).orElse(null);
if (waypoint == 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; return true;
} }
} else { } 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;
}
} }