basic impl of place options

This commit is contained in:
Leijurv
2021-05-17 02:12:51 -07:00
parent 4848e901c9
commit d9591e089d
6 changed files with 48 additions and 9 deletions

View File

@@ -36,6 +36,7 @@ public class Blip {
public static final int HALF_BLOCK = 8;
public static final int PLAYER_HEIGHT = 29;
public static final int TWO_BLOCKS = 2 * FULL_BLOCK;
public static final int FEET_TO_EYE_APPROX = (int) (IPlayerContext.eyeHeight(false) / RATIO);
public static double playerEyeFromFeetBlips(int feetBlips, boolean sneaking) {
return feetBlips * RATIO + IPlayerContext.eyeHeight(sneaking);

View File

@@ -64,10 +64,11 @@ public final class BlockStateCachedData {
return Main.RAND.nextInt(10) < 8;
}
PlaceAgainstData against = againstMe[placement.against.oppositeIndex];
if (against == null) {
return false;
}
return possible(placement, against);
return against != null && possible(placement, against);
}
public PlaceAgainstData againstMe(BlockStatePlacementOption placement) {
return againstMe[placement.against.oppositeIndex];
}
public static boolean possible(BlockStatePlacementOption placement, PlaceAgainstData against) {

View File

@@ -112,6 +112,13 @@ public class DependencyGraphScaffoldingOverlay {
}
}
public BlockStateCachedData data(long pos) {
if (Main.DEBUG && !real(pos)) {
throw new IllegalStateException();
}
return delegate.data(pos);
}
/**
* Remember that this returns a collapsed graph that will be updated in-place as positions are enabled. It does not return a copy.
*/

View File

@@ -17,12 +17,42 @@
package baritone.builder;
import baritone.api.utils.BetterBlockPos;
public class PlaceOptions {
IReachabilityProvider provider;
double blockReachDistance = 4;
DependencyGraphScaffoldingOverlay overlay;
IReachabilityProvider provider = IReachabilityProvider.get(overlay, new PlayerReachSphere(blockReachDistance));
public void go(int playerX, int playerFeetBlips, int playerZ) {
public void whatCouldIDo(int playerX, int playerFeetBlips, int playerZ) {
int playerEyeBlips = playerFeetBlips + Blip.FEET_TO_EYE_APPROX;
// TODO ugh how tf to deal with sneaking UGH. maybe like if (playerEyeBlips % 16 < 2) { also run all candidates from one voxel lower down because if we snuck our eye would be in there}
int voxelY = playerEyeBlips / Blip.FULL_BLOCK;
long pos = BetterBlockPos.toLong(playerX, voxelY, playerZ);
for (long blockPos : provider.candidates(pos)) {
BlockStateCachedData placingAgainst = overlay.data(blockPos);
outer:
for (Face againstToPlace : Face.VALUES) {
Face placeToAgainst = againstToPlace.opposite();
if (overlay.outgoingEdge(blockPos, againstToPlace)) {
long placingBlockAt = againstToPlace.offset(blockPos);
BlockStateCachedData blockBeingPlaced = overlay.data(placingBlockAt);
for (BlockStatePlacementOption option : blockBeingPlaced.options) {
if (option.against == placeToAgainst) {
PlaceAgainstData againstData = placingAgainst.againstMe(option);
int relativeX = playerX - BetterBlockPos.XfromLong(placingBlockAt);
int relativeY = playerFeetBlips - Blip.FULL_BLOCK * BetterBlockPos.YfromLong(placingBlockAt);
int relativeZ = playerZ - BetterBlockPos.ZfromLong(placingBlockAt);
for (Raytracer.Raytrace trace : option.computeTraceOptions(againstData, relativeX, relativeY, relativeZ, PlayerVantage.LOOSE_CENTER, blockReachDistance)) {
// yay, gold star
}
continue outer;
}
}
throw new IllegalStateException();
}
}
}
}
}

View File

@@ -59,7 +59,7 @@ public class PlaceOrderDependencyGraph {
}
}
private BlockStateCachedData data(long pos) {
public BlockStateCachedData data(long pos) {
int state = state(pos);
if (treatAsScaffolding(state)) {
return BlockStateCachedData.SCAFFOLDING;

View File

@@ -278,7 +278,7 @@ public class Testing {
public static int lookupBlockState(IBlockState state) {
int stateMaybe = states.getInt(state);
if (stateMaybe > 0) {
if (stateMaybe >= 0) {
return stateMaybe;
}
int realState = Block.BLOCK_STATE_IDS.get(state); // uses slow REAL hashcode that walks through the Map of properties, gross