misc
This commit is contained in:
@@ -44,7 +44,7 @@ public class CuboidBounds implements Bounds {
|
||||
this.sizeZMinusOne = sizeZ - 1;
|
||||
this.size = sizeX * sizeY * sizeZ;
|
||||
this.sizeMinusOne = size - 1;
|
||||
if (Main.DEBUG) {
|
||||
if (Main.SLOW_DEBUG) {
|
||||
sanityCheck();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,8 +35,8 @@ import java.util.stream.Stream;
|
||||
public class Main {
|
||||
|
||||
public static final boolean DEBUG = true;
|
||||
public static final boolean SLOW_DEBUG = true;
|
||||
public static final boolean VERY_SLOW_DEBUG = true;
|
||||
public static final boolean SLOW_DEBUG = false;
|
||||
public static final boolean VERY_SLOW_DEBUG = false;
|
||||
|
||||
/**
|
||||
* If true, many different parts of the builder switch to a more efficient mode where blocks can only be placed adjacent or upwards, never downwards
|
||||
|
||||
@@ -20,23 +20,22 @@ package baritone.builder;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.builder.utils.com.github.btrekkie.connectivity.ConnGraph;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
public class NavigableSurface {
|
||||
// the encapsulation / separation of concerns is not great, but this is better for testing purposes than the fully accurate stuff in https://github.com/cabaletta/baritone/tree/builder-2/src/main/java/baritone/builder lol
|
||||
public final int sizeX;
|
||||
public final int sizeY;
|
||||
public final int sizeZ;
|
||||
public final CuboidBounds bounds;
|
||||
|
||||
private final boolean[][][] blocks;
|
||||
private final BlockStateCachedData[] blocks;
|
||||
|
||||
private final ConnGraph connGraph;
|
||||
|
||||
public NavigableSurface(int x, int y, int z) {
|
||||
this.sizeX = x;
|
||||
this.sizeY = y;
|
||||
this.sizeZ = z;
|
||||
this.blocks = new boolean[x][y][z];
|
||||
this.bounds = new CuboidBounds(x, y, z);
|
||||
this.blocks = new BlockStateCachedData[bounds.volume()];
|
||||
Arrays.fill(blocks, BlockStateCachedData.AIR);
|
||||
|
||||
this.connGraph = new ConnGraph(Attachment::new);
|
||||
}
|
||||
|
||||
@@ -89,7 +88,7 @@ public class NavigableSurface {
|
||||
if (previously == place) {
|
||||
return; // this is already the case
|
||||
}
|
||||
blocks[where.x][where.y][where.z] = place;
|
||||
blocks[bounds.toIndex(where.x, where.y, where.z)] = place ? BlockStateCachedData.SCAFFOLDING : BlockStateCachedData.AIR;
|
||||
// first let's set some vertex info for where the player can and cannot stand
|
||||
for (int dy = -1; dy <= 1; dy++) {
|
||||
BetterBlockPos couldHaveChanged = where.up(dy);
|
||||
@@ -144,16 +143,12 @@ public class NavigableSurface {
|
||||
return surfaceSize(new BetterBlockPos(x, y, z)).getAsInt();
|
||||
}
|
||||
|
||||
public boolean inRange(int x, int y, int z) {
|
||||
return (x | y | z | (sizeX - (x + 1)) | (sizeY - (y + 1)) | (sizeZ - (z + 1))) >= 0; // ">= 0" is used here in the sense of "most significant bit is not set"
|
||||
}
|
||||
|
||||
public boolean getBlock(BetterBlockPos where) {
|
||||
return blocks[where.x][where.y][where.z];
|
||||
return blocks[bounds.toIndex(where.x, where.y, where.z)].collidesWithPlayer;
|
||||
}
|
||||
|
||||
public boolean getBlockOrAir(BetterBlockPos where) {
|
||||
if (!inRange(where.x, where.y, where.z)) {
|
||||
if (!bounds.inRange(where.x, where.y, where.z)) {
|
||||
return false;
|
||||
}
|
||||
return getBlock(where);
|
||||
|
||||
@@ -216,11 +216,11 @@ public class NavigableSurfaceTest {
|
||||
}
|
||||
|
||||
private String reportBottomToTop(NavigableSurface surface) {
|
||||
int len = surface.sizeY * ((surface.sizeX + 1) * surface.sizeZ + 1);
|
||||
int len = surface.bounds.sizeY * ((surface.bounds.sizeX + 1) * surface.bounds.sizeZ + 1);
|
||||
StringBuilder report = new StringBuilder(len);
|
||||
for (int y = 0; y < surface.sizeY; y++) {
|
||||
for (int z = 0; z < surface.sizeZ; z++) {
|
||||
for (int x = 0; x < surface.sizeX; x++) {
|
||||
for (int y = 0; y < surface.bounds.sizeY; y++) {
|
||||
for (int z = 0; z < surface.bounds.sizeZ; z++) {
|
||||
for (int x = 0; x < surface.bounds.sizeX; x++) {
|
||||
report.append(surface.getBlock(new BetterBlockPos(x, y, z)) ? 'X' : ' ');
|
||||
}
|
||||
report.append('\n');
|
||||
@@ -234,10 +234,10 @@ public class NavigableSurfaceTest {
|
||||
}
|
||||
|
||||
private String reportSlice(NavigableSurface surface, int y) {
|
||||
int len = (surface.sizeX + 1) * surface.sizeZ;
|
||||
int len = (surface.bounds.sizeX + 1) * surface.bounds.sizeZ;
|
||||
StringBuilder report = new StringBuilder(len);
|
||||
for (int z = 0; z < surface.sizeZ; z++) {
|
||||
for (int x = 0; x < surface.sizeX; x++) {
|
||||
for (int z = 0; z < surface.bounds.sizeZ; z++) {
|
||||
for (int x = 0; x < surface.bounds.sizeX; x++) {
|
||||
report.append(surface.getBlock(new BetterBlockPos(x, y, z)) ? 'X' : ' ');
|
||||
}
|
||||
report.append('\n');
|
||||
@@ -249,20 +249,20 @@ public class NavigableSurfaceTest {
|
||||
}
|
||||
|
||||
private static List<BetterBlockPos> genReportedWallOrder(NavigableSurface surface, int y) {
|
||||
List<BetterBlockPos> ret = new ArrayList<>((surface.sizeX + surface.sizeZ) * 2);
|
||||
for (int x = 0; x < surface.sizeX; x++) {
|
||||
List<BetterBlockPos> ret = new ArrayList<>((surface.bounds.sizeX + surface.bounds.sizeZ) * 2);
|
||||
for (int x = 0; x < surface.bounds.sizeX; x++) {
|
||||
ret.add(new BetterBlockPos(x, y, 0));
|
||||
}
|
||||
// start at 1 not 0 so that we don't repeat the last iteration of the previous loop (that would make the report look bad because the staircase would repeat one column for no reason)
|
||||
for (int z = 1; z < surface.sizeZ; z++) {
|
||||
ret.add(new BetterBlockPos(surface.sizeX - 1, y, z));
|
||||
for (int z = 1; z < surface.bounds.sizeZ; z++) {
|
||||
ret.add(new BetterBlockPos(surface.bounds.sizeX - 1, y, z));
|
||||
}
|
||||
// same deal for starting at -2 rather than -1
|
||||
for (int x = surface.sizeX - 2; x >= 0; x--) {
|
||||
ret.add(new BetterBlockPos(x, y, surface.sizeZ - 1));
|
||||
for (int x = surface.bounds.sizeX - 2; x >= 0; x--) {
|
||||
ret.add(new BetterBlockPos(x, y, surface.bounds.sizeZ - 1));
|
||||
}
|
||||
// and same again
|
||||
for (int z = surface.sizeZ - 2; z > 0; z--) {
|
||||
for (int z = surface.bounds.sizeZ - 2; z > 0; z--) {
|
||||
ret.add(new BetterBlockPos(0, y, z));
|
||||
}
|
||||
return ret;
|
||||
@@ -277,23 +277,23 @@ public class NavigableSurfaceTest {
|
||||
}
|
||||
|
||||
private String reportAllFourWalls(NavigableSurface surface) {
|
||||
int len = surface.sizeY * (surface.sizeX + surface.sizeZ) * 2;
|
||||
int len = surface.bounds.sizeY * (surface.bounds.sizeX + surface.bounds.sizeZ) * 2;
|
||||
StringBuilder report = new StringBuilder(len);
|
||||
for (int y = surface.sizeY - 1; y >= 0; y--) {
|
||||
for (int y = surface.bounds.sizeY - 1; y >= 0; y--) {
|
||||
// make a report of what all four walls look like
|
||||
for (int x = 0; x < surface.sizeX - 1; x++) {
|
||||
for (int x = 0; x < surface.bounds.sizeX - 1; x++) {
|
||||
report.append(surface.getBlock(new BetterBlockPos(x, y, 0)) ? 'X' : ' ');
|
||||
}
|
||||
report.append('|');
|
||||
for (int z = 0; z < surface.sizeZ - 1; z++) {
|
||||
report.append(surface.getBlock(new BetterBlockPos(surface.sizeX - 1, y, z)) ? 'X' : ' ');
|
||||
for (int z = 0; z < surface.bounds.sizeZ - 1; z++) {
|
||||
report.append(surface.getBlock(new BetterBlockPos(surface.bounds.sizeX - 1, y, z)) ? 'X' : ' ');
|
||||
}
|
||||
report.append('|');
|
||||
for (int x = surface.sizeX - 1; x > 0; x--) {
|
||||
report.append(surface.getBlock(new BetterBlockPos(x, y, surface.sizeZ - 1)) ? 'X' : ' ');
|
||||
for (int x = surface.bounds.sizeX - 1; x > 0; x--) {
|
||||
report.append(surface.getBlock(new BetterBlockPos(x, y, surface.bounds.sizeZ - 1)) ? 'X' : ' ');
|
||||
}
|
||||
report.append('|');
|
||||
for (int z = surface.sizeZ - 1; z > 0; z--) {
|
||||
for (int z = surface.bounds.sizeZ - 1; z > 0; z--) {
|
||||
report.append(surface.getBlock(new BetterBlockPos(0, y, z)) ? 'X' : ' ');
|
||||
}
|
||||
report.append('\n');
|
||||
|
||||
Reference in New Issue
Block a user