highlight walkaround blocks better
This commit is contained in:
parent
462ac1b03a
commit
7c175bac67
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user