Begin path api prep

This commit is contained in:
Brady 2018-10-08 19:23:43 -05:00
parent 336154fd9b
commit 1245e222a7
No known key found for this signature in database
GPG Key ID: 73A788379A197567
3 changed files with 90 additions and 19 deletions

View File

@ -30,6 +30,7 @@ import baritone.pathing.calc.AStarPathFinder;
import baritone.pathing.calc.AbstractNodeCostSearch;
import baritone.pathing.calc.IPathFinder;
import baritone.pathing.movement.MovementHelper;
import baritone.pathing.path.CutoffResult;
import baritone.pathing.path.IPath;
import baritone.pathing.path.PathExecutor;
import baritone.utils.BlockBreakHelper;
@ -283,9 +284,30 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
Optional<IPath> path = findPath(start, previous);
if (Baritone.settings().cutoffAtLoadBoundary.get()) {
path = path.map(IPath::cutoffAtLoadedChunks);
path = path.map(p -> {
CutoffResult result = p.cutoffAtLoadedChunks();
if (result.wasCut()) {
logDebug("Cutting off path at edge of loaded chunks");
logDebug("Length decreased by " + result.getRemoved());
} else {
logDebug("Path ends within loaded chunks");
}
return result.getPath();
});
}
Optional<PathExecutor> executor = path.map(p -> p.staticCutoff(goal)).map(PathExecutor::new);
Optional<PathExecutor> executor = path.map(p -> {
CutoffResult result = p.staticCutoff(goal);
if (result.wasCut()) {
logDebug("Static cutoff " + p.length() + " to " + result.getPath().length());
}
return result.getPath();
}).map(PathExecutor::new);
synchronized (pathPlanLock) {
if (current == null) {
if (executor.isPresent()) {

View File

@ -0,0 +1,54 @@
/*
* 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.pathing.path;
/**
* @author Brady
* @since 10/8/2018
*/
public final class CutoffResult {
private final IPath path;
private final int removed;
private CutoffResult(IPath path, int removed) {
this.path = path;
this.removed = removed;
}
public final boolean wasCut() {
return this.removed > 0;
}
public final int getRemoved() {
return this.removed;
}
public final IPath getPath() {
return this.path;
}
public static CutoffResult cutoffPath(IPath path, int index) {
return new CutoffResult(new CutoffPath(path, index), path.positions().size() - index - 1);
}
public static CutoffResult preservePath(IPath path) {
return new CutoffResult(path, 0);
}
}

View File

@ -17,10 +17,9 @@
package baritone.pathing.path;
import baritone.Baritone;
import baritone.api.BaritoneAPI;
import baritone.api.pathing.goals.Goal;
import baritone.pathing.movement.Movement;
import baritone.utils.Helper;
import baritone.utils.Utils;
import baritone.utils.pathing.BetterBlockPos;
import net.minecraft.client.Minecraft;
@ -33,7 +32,7 @@ import java.util.List;
/**
* @author leijurv
*/
public interface IPath extends Helper {
public interface IPath {
/**
* Ordered list of movements to carry out.
@ -87,7 +86,7 @@ public interface IPath extends Helper {
/**
* Where does this path start
*/
default BetterBlockPos getSrc() {
default BlockPos getSrc() {
return positions().get(0);
}
@ -110,29 +109,25 @@ public interface IPath extends Helper {
int getNumNodesConsidered();
default IPath cutoffAtLoadedChunks() {
default CutoffResult cutoffAtLoadedChunks() {
for (int i = 0; i < positions().size(); i++) {
BlockPos pos = positions().get(i);
if (Minecraft.getMinecraft().world.getChunk(pos) instanceof EmptyChunk) {
logDebug("Cutting off path at edge of loaded chunks");
logDebug("Length decreased by " + (positions().size() - i - 1));
return new CutoffPath(this, i);
return CutoffResult.cutoffPath(this, i);
}
}
logDebug("Path ends within loaded chunks");
return this;
return CutoffResult.preservePath(this);
}
default IPath staticCutoff(Goal destination) {
if (length() < Baritone.settings().pathCutoffMinimumLength.get()) {
return this;
default CutoffResult staticCutoff(Goal destination) {
if (length() < BaritoneAPI.getSettings().pathCutoffMinimumLength.get()) {
return CutoffResult.preservePath(this);
}
if (destination == null || destination.isInGoal(getDest())) {
return this;
return CutoffResult.preservePath(this);
}
double factor = Baritone.settings().pathCutoffFactor.get();
double factor = BaritoneAPI.getSettings().pathCutoffFactor.get();
int newLength = (int) (length() * factor);
logDebug("Static cutoff " + length() + " to " + newLength);
return new CutoffPath(this, newLength);
return CutoffResult.cutoffPath(this, newLength);
}
}