highlight walkaround blocks better

This commit is contained in:
Leijurv 2018-08-12 08:40:44 -07:00
parent 462ac1b03a
commit 7c175bac67
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
4 changed files with 54 additions and 2 deletions

View File

@ -195,6 +195,7 @@ public class PathingBehavior extends Behavior {
if (current != null) { if (current != null) {
PathRenderer.drawManySelectionBoxes(player(), current.toBreak(), partialTicks, Color.RED); PathRenderer.drawManySelectionBoxes(player(), current.toBreak(), partialTicks, Color.RED);
PathRenderer.drawManySelectionBoxes(player(), current.toPlace(), partialTicks, Color.GREEN); 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 // If there is a path calculation currently running, render the path calculation process

View File

@ -218,6 +218,7 @@ public abstract class Movement implements Helper, MovementHelper {
public ArrayList<BlockPos> toBreakCached = null; public ArrayList<BlockPos> toBreakCached = null;
public ArrayList<BlockPos> toPlaceCached = null; public ArrayList<BlockPos> toPlaceCached = null;
public ArrayList<BlockPos> toWalkIntoCached = null;
public ArrayList<BlockPos> toBreak() { public ArrayList<BlockPos> toBreak() {
if (toBreakCached != null) { if (toBreakCached != null) {
@ -246,4 +247,11 @@ public abstract class Movement implements Helper, MovementHelper {
toPlaceCached = result; toPlaceCached = result;
return result; return result;
} }
public ArrayList<BlockPos> toWalkInto() {
if (toWalkIntoCached == null) {
toWalkIntoCached = new ArrayList<>();
}
return toWalkIntoCached;
}
} }

View File

@ -26,6 +26,8 @@ import net.minecraft.block.BlockMagma;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import java.util.ArrayList;
public class MovementDiagonal extends Movement { public class MovementDiagonal extends Movement {
private static final double SQRT_2 = Math.sqrt(2); private static final double SQRT_2 = Math.sqrt(2);
@ -115,4 +117,34 @@ public class MovementDiagonal extends Movement {
protected boolean prepared(MovementState state) { protected boolean prepared(MovementState state) {
return true; return true;
} }
@Override
public ArrayList<BlockPos> toBreak() {
if (toBreakCached != null) {
return toBreakCached;
}
ArrayList<BlockPos> 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<BlockPos> toWalkInto() {
if (toWalkIntoCached == null) {
toWalkIntoCached = new ArrayList<>();
}
ArrayList<BlockPos> result = new ArrayList<>();
for (int i = 0; i < 4; i++) {
if (!MovementHelper.canWalkThrough(positionsToBreak[i])) {
result.add(positionsToBreak[i]);
}
}
toWalkIntoCached = result;
return toWalkIntoCached;
}
} }

View File

@ -52,6 +52,7 @@ public class PathExecutor extends Behavior {
private boolean recalcBP = true; private boolean recalcBP = true;
private HashSet<BlockPos> toBreak = new HashSet<>(); private HashSet<BlockPos> toBreak = new HashSet<>();
private HashSet<BlockPos> toPlace = new HashSet<>(); private HashSet<BlockPos> toPlace = new HashSet<>();
private HashSet<BlockPos> toWalkInto = new HashSet<>();
public PathExecutor(IPath path) { public PathExecutor(IPath path) {
this.path = path; this.path = path;
@ -151,27 +152,33 @@ public class PathExecutor extends Behavior {
Movement m = path.movements().get(i); Movement m = path.movements().get(i);
HashSet<BlockPos> prevBreak = new HashSet<>(m.toBreak()); HashSet<BlockPos> prevBreak = new HashSet<>(m.toBreak());
HashSet<BlockPos> prevPlace = new HashSet<>(m.toPlace()); HashSet<BlockPos> prevPlace = new HashSet<>(m.toPlace());
HashSet<BlockPos> prevWalkInto = new HashSet<>(m.toWalkInto());
m.toBreakCached = null; m.toBreakCached = null;
m.toPlaceCached = null; m.toPlaceCached = null;
m.toBreak(); m.toWalkIntoCached = null;
m.toPlace();
if (!prevBreak.equals(new HashSet<>(m.toBreak()))) { if (!prevBreak.equals(new HashSet<>(m.toBreak()))) {
recalcBP = true; recalcBP = true;
} }
if (!prevPlace.equals(new HashSet<>(m.toPlace()))) { if (!prevPlace.equals(new HashSet<>(m.toPlace()))) {
recalcBP = true; recalcBP = true;
} }
if (!prevWalkInto.equals(new HashSet<>(m.toWalkInto()))) {
recalcBP = true;
}
} }
} }
if (recalcBP) { if (recalcBP) {
HashSet<BlockPos> newBreak = new HashSet<>(); HashSet<BlockPos> newBreak = new HashSet<>();
HashSet<BlockPos> newPlace = new HashSet<>(); HashSet<BlockPos> newPlace = new HashSet<>();
HashSet<BlockPos> newWalkInto = new HashSet<>();
for (int i = 0; i < path.movements().size(); i++) { for (int i = 0; i < path.movements().size(); i++) {
newBreak.addAll(path.movements().get(i).toBreak()); newBreak.addAll(path.movements().get(i).toBreak());
newPlace.addAll(path.movements().get(i).toPlace()); newPlace.addAll(path.movements().get(i).toPlace());
newWalkInto.addAll(path.movements().get(i).toWalkInto());
} }
toBreak = newBreak; toBreak = newBreak;
toPlace = newPlace; toPlace = newPlace;
toWalkInto = newWalkInto;
recalcBP = false; recalcBP = false;
} }
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
@ -236,4 +243,8 @@ public class PathExecutor extends Behavior {
public Set<BlockPos> toPlace() { public Set<BlockPos> toPlace() {
return Collections.unmodifiableSet(toPlace); return Collections.unmodifiableSet(toPlace);
} }
public Set<BlockPos> toWalkInto() {
return Collections.unmodifiableSet(toWalkInto);
}
} }