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) {
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

View File

@ -218,6 +218,7 @@ public abstract class Movement implements Helper, MovementHelper {
public ArrayList<BlockPos> toBreakCached = null;
public ArrayList<BlockPos> toPlaceCached = null;
public ArrayList<BlockPos> toWalkIntoCached = null;
public ArrayList<BlockPos> toBreak() {
if (toBreakCached != null) {
@ -246,4 +247,11 @@ public abstract class Movement implements Helper, MovementHelper {
toPlaceCached = 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.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<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 HashSet<BlockPos> toBreak = new HashSet<>();
private HashSet<BlockPos> toPlace = new HashSet<>();
private HashSet<BlockPos> 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<BlockPos> prevBreak = new HashSet<>(m.toBreak());
HashSet<BlockPos> prevPlace = new HashSet<>(m.toPlace());
HashSet<BlockPos> 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<BlockPos> newBreak = new HashSet<>();
HashSet<BlockPos> newPlace = new HashSet<>();
HashSet<BlockPos> 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<BlockPos> toPlace() {
return Collections.unmodifiableSet(toPlace);
}
public Set<BlockPos> toWalkInto() {
return Collections.unmodifiableSet(toWalkInto);
}
}