Merge branch 'master' into builder

This commit is contained in:
Leijurv 2019-01-14 13:01:25 -08:00
commit 261d02e67b
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
7 changed files with 17 additions and 45 deletions

View File

@ -21,6 +21,7 @@ import baritone.api.behavior.ILookBehavior;
import baritone.api.behavior.IPathingBehavior; import baritone.api.behavior.IPathingBehavior;
import baritone.api.cache.IWorldProvider; import baritone.api.cache.IWorldProvider;
import baritone.api.event.listener.IEventBus; import baritone.api.event.listener.IEventBus;
import baritone.api.pathing.calc.IPathingControlManager;
import baritone.api.process.ICustomGoalProcess; import baritone.api.process.ICustomGoalProcess;
import baritone.api.process.IFollowProcess; import baritone.api.process.IFollowProcess;
import baritone.api.process.IGetToBlockProcess; import baritone.api.process.IGetToBlockProcess;
@ -64,6 +65,8 @@ public interface IBaritone {
*/ */
IWorldProvider getWorldProvider(); IWorldProvider getWorldProvider();
IPathingControlManager getPathingControlManager();
IInputOverrideHandler getInputOverrideHandler(); IInputOverrideHandler getInputOverrideHandler();
ICustomGoalProcess getCustomGoalProcess(); ICustomGoalProcess getCustomGoalProcess();

View File

@ -129,6 +129,7 @@ public class Baritone implements IBaritone {
this.initialized = true; this.initialized = true;
} }
@Override
public PathingControlManager getPathingControlManager() { public PathingControlManager getPathingControlManager() {
return this.pathingControlManager; return this.pathingControlManager;
} }

View File

@ -64,7 +64,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
MutableMoveResult res = new MutableMoveResult(); MutableMoveResult res = new MutableMoveResult();
Favoring favored = favoring; Favoring favored = favoring;
BetterWorldBorder worldBorder = new BetterWorldBorder(calcContext.world.getWorldBorder()); BetterWorldBorder worldBorder = new BetterWorldBorder(calcContext.world.getWorldBorder());
long startTime = System.nanoTime() / 1000000L; long startTime = System.currentTimeMillis();
boolean slowPath = Baritone.settings().slowPath.get(); boolean slowPath = Baritone.settings().slowPath.get();
if (slowPath) { if (slowPath) {
logDebug("slowPath is on, path timeout will be " + Baritone.settings().slowPathTimeoutMS.<Long>get() + "ms instead of " + primaryTimeout + "ms"); logDebug("slowPath is on, path timeout will be " + Baritone.settings().slowPathTimeoutMS.<Long>get() + "ms instead of " + primaryTimeout + "ms");
@ -81,7 +81,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
boolean minimumImprovementRepropagation = Baritone.settings().minimumImprovementRepropagation.get(); boolean minimumImprovementRepropagation = Baritone.settings().minimumImprovementRepropagation.get();
while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && !cancelRequested) { while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && !cancelRequested) {
if ((numNodes & (timeCheckInterval - 1)) == 0) { // only call this once every 64 nodes (about half a millisecond) if ((numNodes & (timeCheckInterval - 1)) == 0) { // only call this once every 64 nodes (about half a millisecond)
long now = System.nanoTime() / 1000000L; // since nanoTime is slow on windows (takes many microseconds) long now = System.currentTimeMillis(); // since nanoTime is slow on windows (takes many microseconds)
if (now - failureTimeoutTime >= 0 || (!failing && now - primaryTimeoutTime >= 0)) { if (now - failureTimeoutTime >= 0 || (!failing && now - primaryTimeoutTime >= 0)) {
break; break;
} }
@ -96,7 +96,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
mostRecentConsidered = currentNode; mostRecentConsidered = currentNode;
numNodes++; numNodes++;
if (goal.isInGoal(currentNode.x, currentNode.y, currentNode.z)) { if (goal.isInGoal(currentNode.x, currentNode.y, currentNode.z)) {
logDebug("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, " + numMovementsConsidered + " movements considered"); logDebug("Took " + (System.currentTimeMillis() - startTime) + "ms, " + numMovementsConsidered + " movements considered");
return Optional.of(new Path(startNode, currentNode, numNodes, goal, calcContext)); return Optional.of(new Path(startNode, currentNode, numNodes, goal, calcContext));
} }
for (Moves moves : Moves.values()) { for (Moves moves : Moves.values()) {
@ -125,10 +125,10 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
if (actionCost <= 0 || Double.isNaN(actionCost)) { if (actionCost <= 0 || Double.isNaN(actionCost)) {
throw new IllegalStateException(moves + " calculated implausible cost " + actionCost); throw new IllegalStateException(moves + " calculated implausible cost " + actionCost);
} }
// check destination after verifying it's not COST_INF -- some movements return a static IMPOSSIBLE object with COST_INF and destination being 0,0,0 to avoid allocating a new result for every failed calculation
if (moves.dynamicXZ && !worldBorder.entirelyContains(res.x, res.z)) { // see issue #218 if (moves.dynamicXZ && !worldBorder.entirelyContains(res.x, res.z)) { // see issue #218
continue; continue;
} }
// check destination after verifying it's not COST_INF -- some movements return a static IMPOSSIBLE object with COST_INF and destination being 0,0,0 to avoid allocating a new result for every failed calculation
if (!moves.dynamicXZ && (res.x != newX || res.z != newZ)) { if (!moves.dynamicXZ && (res.x != newX || res.z != newZ)) {
throw new IllegalStateException(moves + " " + res.x + " " + newX + " " + res.z + " " + newZ); throw new IllegalStateException(moves + " " + res.x + " " + newX + " " + res.z + " " + newZ);
} }
@ -181,7 +181,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
System.out.println(numMovementsConsidered + " movements considered"); System.out.println(numMovementsConsidered + " movements considered");
System.out.println("Open set size: " + openSet.size()); System.out.println("Open set size: " + openSet.size());
System.out.println("PathNode map size: " + mapSize()); System.out.println("PathNode map size: " + mapSize());
System.out.println((int) (numNodes * 1.0 / ((System.nanoTime() / 1000000L - startTime) / 1000F)) + " nodes per second"); System.out.println((int) (numNodes * 1.0 / ((System.currentTimeMillis() - startTime) / 1000F)) + " nodes per second");
double bestDist = 0; double bestDist = 0;
for (int i = 0; i < bestSoFar.length; i++) { for (int i = 0; i < bestSoFar.length; i++) {
if (bestSoFar[i] == null) { if (bestSoFar[i] == null) {
@ -192,7 +192,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
bestDist = dist; bestDist = dist;
} }
if (dist > MIN_DIST_PATH * MIN_DIST_PATH) { // square the comparison since distFromStartSq is squared if (dist > MIN_DIST_PATH * MIN_DIST_PATH) { // square the comparison since distFromStartSq is squared
logDebug("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, A* cost coefficient " + COEFFICIENTS[i] + ", " + numMovementsConsidered + " movements considered"); logDebug("Took " + (System.currentTimeMillis() - startTime) + "ms, A* cost coefficient " + COEFFICIENTS[i] + ", " + numMovementsConsidered + " movements considered");
if (COEFFICIENTS[i] >= 3) { if (COEFFICIENTS[i] >= 3) {
System.out.println("Warning: cost coefficient is greater than three! Probably means that"); System.out.println("Warning: cost coefficient is greater than three! Probably means that");
System.out.println("the path I found is pretty terrible (like sneak-bridging for dozens of blocks)"); System.out.println("the path I found is pretty terrible (like sneak-bridging for dozens of blocks)");

View File

@ -127,7 +127,7 @@ public abstract class Movement implements IMovement, MovementHelper {
currentState.getInputStates().forEach((input, forced) -> { currentState.getInputStates().forEach((input, forced) -> {
baritone.getInputOverrideHandler().setInputForceState(input, forced); baritone.getInputOverrideHandler().setInputForceState(input, forced);
}); });
currentState.getInputStates().replaceAll((input, forced) -> false); currentState.getInputStates().clear();
// If the current status indicates a completed movement // If the current status indicates a completed movement
if (currentState.getStatus().isComplete()) { if (currentState.getStatus().isComplete()) {

View File

@ -20,7 +20,6 @@ package baritone.pathing.movement;
import baritone.api.pathing.movement.MovementStatus; import baritone.api.pathing.movement.MovementStatus;
import baritone.api.utils.Rotation; import baritone.api.utils.Rotation;
import baritone.api.utils.input.Input; import baritone.api.utils.input.Input;
import net.minecraft.util.math.Vec3d;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -29,7 +28,6 @@ import java.util.Optional;
public class MovementState { public class MovementState {
private MovementStatus status; private MovementStatus status;
private MovementTarget goal = new MovementTarget();
private MovementTarget target = new MovementTarget(); private MovementTarget target = new MovementTarget();
private final Map<Input, Boolean> inputState = new HashMap<>(); private final Map<Input, Boolean> inputState = new HashMap<>();
@ -42,15 +40,6 @@ public class MovementState {
return status; return status;
} }
public MovementTarget getGoal() {
return this.goal;
}
public MovementState setGoal(MovementTarget goal) {
this.goal = goal;
return this;
}
public MovementTarget getTarget() { public MovementTarget getTarget() {
return this.target; return this.target;
} }
@ -65,23 +54,12 @@ public class MovementState {
return this; return this;
} }
public boolean getInput(Input input) {
return this.inputState.getOrDefault(input, false);
}
public Map<Input, Boolean> getInputStates() { public Map<Input, Boolean> getInputStates() {
return this.inputState; return this.inputState;
} }
public static class MovementTarget { public static class MovementTarget {
/**
* Necessary movement to achieve
* <p>
* TODO: Decide desiredMovement type
*/
public Vec3d position;
/** /**
* Yaw and pitch angles that must be matched * Yaw and pitch angles that must be matched
*/ */
@ -95,27 +73,14 @@ public class MovementState {
private boolean forceRotations; private boolean forceRotations;
public MovementTarget() { public MovementTarget() {
this(null, null, false); this(null, false);
}
public MovementTarget(Vec3d position) {
this(position, null, false);
} }
public MovementTarget(Rotation rotation, boolean forceRotations) { public MovementTarget(Rotation rotation, boolean forceRotations) {
this(null, rotation, forceRotations);
}
public MovementTarget(Vec3d position, Rotation rotation, boolean forceRotations) {
this.position = position;
this.rotation = rotation; this.rotation = rotation;
this.forceRotations = forceRotations; this.forceRotations = forceRotations;
} }
public final Optional<Vec3d> getPosition() {
return Optional.ofNullable(this.position);
}
public final Optional<Rotation> getRotation() { public final Optional<Rotation> getRotation() {
return Optional.ofNullable(this.rotation); return Optional.ofNullable(this.rotation);
} }

View File

@ -141,7 +141,7 @@ public class MovementTraverse extends Movement {
if (srcDown == Blocks.FLOWING_WATER || srcDown == Blocks.WATER) { if (srcDown == Blocks.FLOWING_WATER || srcDown == Blocks.WATER) {
return COST_INF; // this is obviously impossible return COST_INF; // this is obviously impossible
} }
WC = WC * SNEAK_ONE_BLOCK_COST / WALK_ONE_BLOCK_COST;//since we are sneak backplacing, we are sneaking lol WC = WC * (SNEAK_ONE_BLOCK_COST / WALK_ONE_BLOCK_COST);//since we are sneak backplacing, we are sneaking lol
return WC + placeCost + hardness1 + hardness2; return WC + placeCost + hardness1 + hardness2;
} }
return COST_INF; return COST_INF;

View File

@ -46,6 +46,8 @@ public class BlockStateInterface {
private Chunk prev = null; private Chunk prev = null;
private CachedRegion prevCached = null; private CachedRegion prevCached = null;
private final boolean useTheRealWorld;
private static final IBlockState AIR = Blocks.AIR.getDefaultState(); private static final IBlockState AIR = Blocks.AIR.getDefaultState();
public BlockStateInterface(IPlayerContext ctx) { public BlockStateInterface(IPlayerContext ctx) {
@ -64,6 +66,7 @@ public class BlockStateInterface {
} else { } else {
this.loadedChunks = worldLoaded; // this will only be used on the main thread this.loadedChunks = worldLoaded; // this will only be used on the main thread
} }
this.useTheRealWorld = !Baritone.settings().pathThroughCachedOnly.get();
if (!Minecraft.getMinecraft().isCallingFromMinecraftThread()) { if (!Minecraft.getMinecraft().isCallingFromMinecraftThread()) {
throw new IllegalStateException(); throw new IllegalStateException();
} }
@ -94,7 +97,7 @@ public class BlockStateInterface {
return AIR; return AIR;
} }
if (!Baritone.settings().pathThroughCachedOnly.get()) { if (useTheRealWorld) {
Chunk cached = prev; Chunk cached = prev;
// there's great cache locality in block state lookups // there's great cache locality in block state lookups
// generally it's within each movement // generally it's within each movement