Begin path api prep
This commit is contained in:
parent
336154fd9b
commit
1245e222a7
@ -30,6 +30,7 @@ import baritone.pathing.calc.AStarPathFinder;
|
|||||||
import baritone.pathing.calc.AbstractNodeCostSearch;
|
import baritone.pathing.calc.AbstractNodeCostSearch;
|
||||||
import baritone.pathing.calc.IPathFinder;
|
import baritone.pathing.calc.IPathFinder;
|
||||||
import baritone.pathing.movement.MovementHelper;
|
import baritone.pathing.movement.MovementHelper;
|
||||||
|
import baritone.pathing.path.CutoffResult;
|
||||||
import baritone.pathing.path.IPath;
|
import baritone.pathing.path.IPath;
|
||||||
import baritone.pathing.path.PathExecutor;
|
import baritone.pathing.path.PathExecutor;
|
||||||
import baritone.utils.BlockBreakHelper;
|
import baritone.utils.BlockBreakHelper;
|
||||||
@ -283,9 +284,30 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
|
|
||||||
Optional<IPath> path = findPath(start, previous);
|
Optional<IPath> path = findPath(start, previous);
|
||||||
if (Baritone.settings().cutoffAtLoadBoundary.get()) {
|
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) {
|
synchronized (pathPlanLock) {
|
||||||
if (current == null) {
|
if (current == null) {
|
||||||
if (executor.isPresent()) {
|
if (executor.isPresent()) {
|
||||||
|
54
src/main/java/baritone/pathing/path/CutoffResult.java
Normal file
54
src/main/java/baritone/pathing/path/CutoffResult.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -17,10 +17,9 @@
|
|||||||
|
|
||||||
package baritone.pathing.path;
|
package baritone.pathing.path;
|
||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.api.BaritoneAPI;
|
||||||
import baritone.api.pathing.goals.Goal;
|
import baritone.api.pathing.goals.Goal;
|
||||||
import baritone.pathing.movement.Movement;
|
import baritone.pathing.movement.Movement;
|
||||||
import baritone.utils.Helper;
|
|
||||||
import baritone.utils.Utils;
|
import baritone.utils.Utils;
|
||||||
import baritone.utils.pathing.BetterBlockPos;
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
@ -33,7 +32,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* @author leijurv
|
* @author leijurv
|
||||||
*/
|
*/
|
||||||
public interface IPath extends Helper {
|
public interface IPath {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ordered list of movements to carry out.
|
* Ordered list of movements to carry out.
|
||||||
@ -87,7 +86,7 @@ public interface IPath extends Helper {
|
|||||||
/**
|
/**
|
||||||
* Where does this path start
|
* Where does this path start
|
||||||
*/
|
*/
|
||||||
default BetterBlockPos getSrc() {
|
default BlockPos getSrc() {
|
||||||
return positions().get(0);
|
return positions().get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,29 +109,25 @@ public interface IPath extends Helper {
|
|||||||
|
|
||||||
int getNumNodesConsidered();
|
int getNumNodesConsidered();
|
||||||
|
|
||||||
default IPath cutoffAtLoadedChunks() {
|
default CutoffResult cutoffAtLoadedChunks() {
|
||||||
for (int i = 0; i < positions().size(); i++) {
|
for (int i = 0; i < positions().size(); i++) {
|
||||||
BlockPos pos = positions().get(i);
|
BlockPos pos = positions().get(i);
|
||||||
if (Minecraft.getMinecraft().world.getChunk(pos) instanceof EmptyChunk) {
|
if (Minecraft.getMinecraft().world.getChunk(pos) instanceof EmptyChunk) {
|
||||||
logDebug("Cutting off path at edge of loaded chunks");
|
return CutoffResult.cutoffPath(this, i);
|
||||||
logDebug("Length decreased by " + (positions().size() - i - 1));
|
|
||||||
return new CutoffPath(this, i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logDebug("Path ends within loaded chunks");
|
return CutoffResult.preservePath(this);
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default IPath staticCutoff(Goal destination) {
|
default CutoffResult staticCutoff(Goal destination) {
|
||||||
if (length() < Baritone.settings().pathCutoffMinimumLength.get()) {
|
if (length() < BaritoneAPI.getSettings().pathCutoffMinimumLength.get()) {
|
||||||
return this;
|
return CutoffResult.preservePath(this);
|
||||||
}
|
}
|
||||||
if (destination == null || destination.isInGoal(getDest())) {
|
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);
|
int newLength = (int) (length() * factor);
|
||||||
logDebug("Static cutoff " + length() + " to " + newLength);
|
return CutoffResult.cutoffPath(this, newLength);
|
||||||
return new CutoffPath(this, newLength);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user