blip staircases work

This commit is contained in:
Leijurv
2023-04-07 17:47:29 -07:00
parent 3e17352e99
commit 8c118401f3
4 changed files with 135 additions and 5 deletions

View File

@@ -73,7 +73,7 @@ public class CountingSurface extends NavigableSurface {
}
private void placeOrRemoveBlock(BetterBlockPos where, boolean place) {
setBlock(where, place ? FakeStates.SOLID : FakeStates.AIR);
setBlock(where.toLong(), place ? FakeStates.SOLID : FakeStates.AIR);
}
public void placeBlock(BetterBlockPos where) {

View File

@@ -58,10 +58,10 @@ public class NavigableSurface {
column.init();
}
protected void setBlock(BetterBlockPos where, BlockStateCachedData data) {
blocks[bounds.toIndex(where.x, where.y, where.z)] = data;
protected void setBlock(long pos, BlockStateCachedData data) {
blocks[bounds.toIndex(pos)] = data;
for (int dy = -2; dy <= 1; dy++) {
long couldHaveChanged = where.up(dy).toLong();
long couldHaveChanged = BetterBlockPos.offsetBy(pos, 0, dy, 0);
columnFrom(col1, couldHaveChanged);
boolean currentlyAllowed = col1.standing();
if (currentlyAllowed) {
@@ -93,6 +93,10 @@ public class NavigableSurface {
}
}
protected void setBlock(int x, int y, int z, BlockStateCachedData data) {
setBlock(BetterBlockPos.toLong(x, y, z), data);
}
public CuboidBounds bounds() {
return bounds;
}

View File

@@ -22,7 +22,7 @@ class VertexInfo {
* vertex. Lookups take O(1) expected time and O(log N / log log N) time with high probability, because "edges" is a
* HashMap, and ConnVertex.hashCode() returns a random integer.
*/
public Long2ObjectOpenHashMap<ConnEdge> edges = new Long2ObjectOpenHashMap<>();
public Long2ObjectOpenHashMap<ConnEdge> edges = new Long2ObjectOpenHashMap<>(); // TODO in my use case, each vertex will have at most 4 edges (at most one each to north, south, east, west). there's probably a MASSIVE performance improvement to be had by simply switching this to such an array. it might require some bitwise twiddling because the key is a long so we'd have to subtract xyz, but, it would work pretty easily just by copying the Face.horizontalIndex approach (x & 1 | (x | z) & 2)
public VertexInfo(EulerTourVertex vertex) {
this.vertex = vertex;

View File

@@ -0,0 +1,126 @@
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.builder;
import baritone.api.utils.BetterBlockPos;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class NavigableSurfaceBlipTest {
@Test
public void testBasicSolo() {
CountingSurface surface = new CountingSurface(10, 10, 10);
for (int i = 0; i <= Blip.FULL_BLOCK; i++) {
surface.setBlock(0, 0, 0, FakeStates.BY_HEIGHT[i]);
assertEquals(i != 0 && i != Blip.FULL_BLOCK, surface.surfaceSize(new BetterBlockPos(0, 0, 0)).isPresent());
}
}
@Test
public void testBasicConnected() {
CountingSurface surface = new CountingSurface(10, 10, 10);
surface.setBlock(1, 0, 0, FakeStates.SOLID);
for (int i = 0; i <= Blip.FULL_BLOCK; i++) {
surface.setBlock(0, 0, 0, FakeStates.BY_HEIGHT[i]);
assertEquals(i == 0 ? 1 : 2, surface.requireSurfaceSize(1, 1, 0));
}
for (int i = 0; i <= Blip.FULL_BLOCK; i++) {
surface.setBlock(0, 1, 0, FakeStates.BY_HEIGHT[i]);
assertEquals(2, surface.requireSurfaceSize(1, 1, 0));
}
for (int i = 0; i <= Blip.FULL_BLOCK; i++) {
surface.setBlock(0, 2, 0, FakeStates.BY_HEIGHT[i]);
assertEquals(i <= Blip.JUMP - Blip.FULL_BLOCK ? 2 : 1, surface.requireSurfaceSize(1, 1, 0));
}
}
@Test
public void testStaircaseWithoutBlips() {
CountingSurface surface = new CountingSurface(10, 10, 10);
surface.setBlock(0, 0, 1, FakeStates.SOLID);
int startY = 0;
for (int x = 0; x < 5; x++) {
// increase height of the (x,0) column as much as possible
int y = startY;
while (true) {
surface.setBlock(x, y, 0, FakeStates.SOLID);
if (!surface.connected(new BetterBlockPos(0, 1, 1), new BetterBlockPos(x, y + 1, 0))) {
surface.setBlock(x, y, 0, FakeStates.AIR);
y--;
break;
}
y++;
}
startY = y;
assertEquals(x + 1, y); // only +1 because blocks start at zero, so (0, 1, 0) is already two blocks high, since (0, 0, 1) is the one block high starting point
}
}
private static void fillColumnToHeight(CountingSurface surface, int x, int z, int yHeightBlips) {
for (int i = 0; i < yHeightBlips / Blip.PER_BLOCK; i++) {
surface.setBlock(x, i, z, FakeStates.SOLID);
}
surface.setBlock(x, yHeightBlips / Blip.PER_BLOCK, z, FakeStates.BY_HEIGHT[yHeightBlips % Blip.PER_BLOCK]);
}
@Test
public void testStaircaseWithFullBlockBlips() {
CountingSurface surface = new CountingSurface(10, 10, 10);
surface.setBlock(0, 0, 1, FakeStates.SOLID);
int step = Blip.FULL_BLOCK;
int startY = step;
for (int x = 0; x < 5; x++) {
// increase height of the (x,0) column as much as possible
int y = startY;
while (true) {
fillColumnToHeight(surface, x, 0, y);
if (!surface.connected(new BetterBlockPos(0, 1, 1), new BetterBlockPos(x, y / Blip.PER_BLOCK, 0))) {
fillColumnToHeight(surface, x, 0, y - step);
y -= step;
break;
}
y += step;
}
startY = y;
assertEquals((x + 2) * Blip.FULL_BLOCK, y); // +2 because we start at 16 blips due to (0,0,1) being full, so (0,1,0) being full on top of (0,0,0) being full means x=0 should be 32 blips high
}
}
@Test
public void testStaircaseBlips() {
CountingSurface surface = new CountingSurface(10, 10, 10);
surface.setBlock(0, 0, 1, FakeStates.SOLID);
int startY = 1;
for (int x = 0; x < 5; x++) {
// increase height of the (x,0) column as much as possible
int y = startY;
while (true) {
fillColumnToHeight(surface, x, 0, y);
if (!surface.connected(new BetterBlockPos(0, 1, 1), new BetterBlockPos(x, y / Blip.PER_BLOCK, 0))) {
fillColumnToHeight(surface, x, 0, y - 1);
y--;
break;
}
y++;
}
startY = y;
assertEquals((x + 1) * Blip.JUMP + Blip.FULL_BLOCK, y); // we start on a full block at (0,0,1) then everything after that (inclusive of x=0, therefore the +1) adds one more jump
}
}
}