From b109fc742093ccb9e2a1bf05afa9de7ce9fbef03 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 9 Jan 2019 15:07:06 -0800 Subject: [PATCH] fun =) --- .../movement/movements/MovementTraverse.java | 2 +- .../java/baritone/process/BuilderProcess.java | 41 +++++++++++++++---- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 57bc333c..1c5c4f2e 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -279,7 +279,7 @@ public class MovementTraverse extends Movement { state.setTarget(new MovementState.MovementTarget(rot, true)); EnumFacing side = ctx.objectMouseOver().sideHit; - if (Objects.equals(ctx.getSelectedBlock().orElse(null), against1) && (ctx.player().isSneaking() || Baritone.settings().assumeSafeWalk.get()) && ctx.getSelectedBlock().get().offset(side).equals(positionToPlace)) { + if ((Objects.equals(ctx.getSelectedBlock(), dest.down()) || (Objects.equals(ctx.getSelectedBlock().orElse(null), against1) && ctx.getSelectedBlock().get().offset(side).equals(positionToPlace))) && (ctx.player().isSneaking() || Baritone.settings().assumeSafeWalk.get())) { return state.setInput(Input.CLICK_RIGHT, true); } if (ctx.playerRotations().isReallyCloseTo(rot)) { diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index b4b13725..e64a6627 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -150,13 +150,13 @@ public class BuilderProcess extends BaritoneProcessHelper { return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); } - Goal[] goals = assemble(bcc); - if (goals.length == 0) { + Goal goal = assemble(bcc); + if (goal == null) { logDirect("Unable to do it =("); onLostControl(); return null; } - return new PathingCommandContext(new GoalComposite(goals), PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH, bcc); + return new PathingCommandContext(goal, PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH, bcc); } public boolean recalc(BuilderCalculationContext bcc) { @@ -211,13 +211,40 @@ public class BuilderProcess extends BaritoneProcessHelper { } } - private Goal[] assemble(BuilderCalculationContext bcc) { + private Goal assemble(BuilderCalculationContext bcc) { List approxPlacable = placable(); List placable = incorrectPositions.stream().filter(pos -> bcc.bsi.get0(pos).getBlock() == Blocks.AIR && approxPlacable.contains(bcc.getSchematic(pos.x, pos.y, pos.z))).collect(Collectors.toList()); - if (!placable.isEmpty()) { - return placable.stream().filter(pos -> !placable.contains(pos.down()) && !placable.contains(pos.down(2))).map(GoalPlace::new).toArray(Goal[]::new); + Goal[] toBreak = incorrectPositions.stream().filter(pos -> bcc.bsi.get0(pos).getBlock() != Blocks.AIR).map(GoalBreak::new).toArray(Goal[]::new); + Goal[] toPlace = placable.stream().filter(pos -> !placable.contains(pos.down()) && !placable.contains(pos.down(2))).map(GoalPlace::new).toArray(Goal[]::new); + + if (toPlace.length != 0) { + return new JankyGoalComposite(new GoalComposite(toPlace), new GoalComposite(toBreak)); + } + if (toBreak.length == 0) { + return null; + } + return new GoalComposite(toBreak); + } + + public static class JankyGoalComposite implements Goal { + private final Goal primary; + private final Goal fallback; + + public JankyGoalComposite(Goal primary, Goal fallback) { + this.primary = primary; + this.fallback = fallback; + } + + + @Override + public boolean isInGoal(int x, int y, int z) { + return primary.isInGoal(x, y, z) || fallback.isInGoal(x, y, z); + } + + @Override + public double heuristic(int x, int y, int z) { + return primary.heuristic(x, y, z); } - return incorrectPositions.stream().filter(pos -> bcc.bsi.get0(pos).getBlock() != Blocks.AIR).map(GoalBreak::new).toArray(Goal[]::new); } public static class GoalBreak extends GoalGetToBlock {