From 7c175bac67feffd15988804ea784bb46410d6b50 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 12 Aug 2018 08:40:44 -0700 Subject: [PATCH] highlight walkaround blocks better --- .../bot/behavior/impl/PathingBehavior.java | 1 + .../bot/pathing/movement/Movement.java | 8 +++++ .../movement/movements/MovementDiagonal.java | 32 +++++++++++++++++++ .../bot/pathing/path/PathExecutor.java | 15 +++++++-- 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java index 7de59a45..06c300e8 100644 --- a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java @@ -195,6 +195,7 @@ public class PathingBehavior extends Behavior { if (current != null) { PathRenderer.drawManySelectionBoxes(player(), current.toBreak(), partialTicks, Color.RED); PathRenderer.drawManySelectionBoxes(player(), current.toPlace(), partialTicks, Color.GREEN); + PathRenderer.drawManySelectionBoxes(player(), current.toWalkInto(), partialTicks, Color.MAGENTA); } // If there is a path calculation currently running, render the path calculation process diff --git a/src/main/java/baritone/bot/pathing/movement/Movement.java b/src/main/java/baritone/bot/pathing/movement/Movement.java index ce291de8..e0f59591 100644 --- a/src/main/java/baritone/bot/pathing/movement/Movement.java +++ b/src/main/java/baritone/bot/pathing/movement/Movement.java @@ -218,6 +218,7 @@ public abstract class Movement implements Helper, MovementHelper { public ArrayList toBreakCached = null; public ArrayList toPlaceCached = null; + public ArrayList toWalkIntoCached = null; public ArrayList toBreak() { if (toBreakCached != null) { @@ -246,4 +247,11 @@ public abstract class Movement implements Helper, MovementHelper { toPlaceCached = result; return result; } + + public ArrayList toWalkInto() { + if (toWalkIntoCached == null) { + toWalkIntoCached = new ArrayList<>(); + } + return toWalkIntoCached; + } } diff --git a/src/main/java/baritone/bot/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/bot/pathing/movement/movements/MovementDiagonal.java index 1f140d80..1a9ca99e 100644 --- a/src/main/java/baritone/bot/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/bot/pathing/movement/movements/MovementDiagonal.java @@ -26,6 +26,8 @@ import net.minecraft.block.BlockMagma; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; +import java.util.ArrayList; + public class MovementDiagonal extends Movement { private static final double SQRT_2 = Math.sqrt(2); @@ -115,4 +117,34 @@ public class MovementDiagonal extends Movement { protected boolean prepared(MovementState state) { return true; } + + @Override + public ArrayList toBreak() { + if (toBreakCached != null) { + return toBreakCached; + } + ArrayList result = new ArrayList<>(); + for (int i = 4; i < 6; i++) { + if (!MovementHelper.canWalkThrough(positionsToBreak[i])) { + result.add(positionsToBreak[i]); + } + } + toBreakCached = result; + return result; + } + + @Override + public ArrayList toWalkInto() { + if (toWalkIntoCached == null) { + toWalkIntoCached = new ArrayList<>(); + } + ArrayList result = new ArrayList<>(); + for (int i = 0; i < 4; i++) { + if (!MovementHelper.canWalkThrough(positionsToBreak[i])) { + result.add(positionsToBreak[i]); + } + } + toWalkIntoCached = result; + return toWalkIntoCached; + } } diff --git a/src/main/java/baritone/bot/pathing/path/PathExecutor.java b/src/main/java/baritone/bot/pathing/path/PathExecutor.java index 62084ecd..d37fa3cc 100644 --- a/src/main/java/baritone/bot/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/bot/pathing/path/PathExecutor.java @@ -52,6 +52,7 @@ public class PathExecutor extends Behavior { private boolean recalcBP = true; private HashSet toBreak = new HashSet<>(); private HashSet toPlace = new HashSet<>(); + private HashSet toWalkInto = new HashSet<>(); public PathExecutor(IPath path) { this.path = path; @@ -151,27 +152,33 @@ public class PathExecutor extends Behavior { Movement m = path.movements().get(i); HashSet prevBreak = new HashSet<>(m.toBreak()); HashSet prevPlace = new HashSet<>(m.toPlace()); + HashSet prevWalkInto = new HashSet<>(m.toWalkInto()); m.toBreakCached = null; m.toPlaceCached = null; - m.toBreak(); - m.toPlace(); + m.toWalkIntoCached = null; if (!prevBreak.equals(new HashSet<>(m.toBreak()))) { recalcBP = true; } if (!prevPlace.equals(new HashSet<>(m.toPlace()))) { recalcBP = true; } + if (!prevWalkInto.equals(new HashSet<>(m.toWalkInto()))) { + recalcBP = true; + } } } if (recalcBP) { HashSet newBreak = new HashSet<>(); HashSet newPlace = new HashSet<>(); + HashSet newWalkInto = new HashSet<>(); for (int i = 0; i < path.movements().size(); i++) { newBreak.addAll(path.movements().get(i).toBreak()); newPlace.addAll(path.movements().get(i).toPlace()); + newWalkInto.addAll(path.movements().get(i).toWalkInto()); } toBreak = newBreak; toPlace = newPlace; + toWalkInto = newWalkInto; recalcBP = false; } long end = System.currentTimeMillis(); @@ -236,4 +243,8 @@ public class PathExecutor extends Behavior { public Set toPlace() { return Collections.unmodifiableSet(toPlace); } + + public Set toWalkInto() { + return Collections.unmodifiableSet(toWalkInto); + } }