This commit is contained in:
Leijurv 2019-01-09 15:07:06 -08:00
parent c74c01271d
commit b109fc7420
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
2 changed files with 35 additions and 8 deletions

View File

@ -279,7 +279,7 @@ public class MovementTraverse extends Movement {
state.setTarget(new MovementState.MovementTarget(rot, true)); state.setTarget(new MovementState.MovementTarget(rot, true));
EnumFacing side = ctx.objectMouseOver().sideHit; 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); return state.setInput(Input.CLICK_RIGHT, true);
} }
if (ctx.playerRotations().isReallyCloseTo(rot)) { if (ctx.playerRotations().isReallyCloseTo(rot)) {

View File

@ -150,13 +150,13 @@ public class BuilderProcess extends BaritoneProcessHelper {
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
} }
Goal[] goals = assemble(bcc); Goal goal = assemble(bcc);
if (goals.length == 0) { if (goal == null) {
logDirect("Unable to do it =("); logDirect("Unable to do it =(");
onLostControl(); onLostControl();
return null; 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) { 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<IBlockState> approxPlacable = placable(); List<IBlockState> approxPlacable = placable();
List<BetterBlockPos> 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()); List<BetterBlockPos> 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()) { Goal[] toBreak = incorrectPositions.stream().filter(pos -> bcc.bsi.get0(pos).getBlock() != Blocks.AIR).map(GoalBreak::new).toArray(Goal[]::new);
return placable.stream().filter(pos -> !placable.contains(pos.down()) && !placable.contains(pos.down(2))).map(GoalPlace::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 { public static class GoalBreak extends GoalGetToBlock {