forked from RepoMirrors/baritone
path cleanup
This commit is contained in:
parent
96da078219
commit
842e50adb9
|
@ -90,7 +90,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
||||||
this.cancelRequested = false;
|
this.cancelRequested = false;
|
||||||
try {
|
try {
|
||||||
Optional<IPath> path = calculate0(timeout);
|
Optional<IPath> path = calculate0(timeout);
|
||||||
path.ifPresent(IPath::postProcess);
|
path = path.map(IPath::postProcess);
|
||||||
isFinished = true;
|
isFinished = true;
|
||||||
if (cancelRequested) {
|
if (cancelRequested) {
|
||||||
return new PathCalculationResult(PathCalculationResult.Type.CANCELLATION, path);
|
return new PathCalculationResult(PathCalculationResult.Type.CANCELLATION, path);
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
package baritone.pathing.calc;
|
package baritone.pathing.calc;
|
||||||
|
|
||||||
import baritone.api.BaritoneAPI;
|
|
||||||
import baritone.api.pathing.calc.IPath;
|
import baritone.api.pathing.calc.IPath;
|
||||||
import baritone.api.pathing.goals.Goal;
|
import baritone.api.pathing.goals.Goal;
|
||||||
import baritone.api.pathing.movement.IMovement;
|
import baritone.api.pathing.movement.IMovement;
|
||||||
|
@ -26,9 +25,7 @@ import baritone.pathing.movement.Movement;
|
||||||
import baritone.pathing.movement.Moves;
|
import baritone.pathing.movement.Moves;
|
||||||
import baritone.pathing.path.CutoffPath;
|
import baritone.pathing.path.CutoffPath;
|
||||||
import baritone.utils.Helper;
|
import baritone.utils.Helper;
|
||||||
import net.minecraft.client.Minecraft;
|
import baritone.utils.pathing.PathBase;
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.world.chunk.EmptyChunk;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -40,7 +37,7 @@ import java.util.List;
|
||||||
*
|
*
|
||||||
* @author leijurv
|
* @author leijurv
|
||||||
*/
|
*/
|
||||||
class Path implements IPath {
|
class Path extends PathBase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The start position of this path
|
* The start position of this path
|
||||||
|
@ -188,28 +185,4 @@ class Path implements IPath {
|
||||||
public BetterBlockPos getDest() {
|
public BetterBlockPos getDest() {
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPath cutoffAtLoadedChunks() {
|
|
||||||
for (int i = 0; i < positions().size(); i++) {
|
|
||||||
BlockPos pos = positions().get(i);
|
|
||||||
if (Minecraft.getMinecraft().world.getChunk(pos) instanceof EmptyChunk) {
|
|
||||||
return new CutoffPath(this, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPath staticCutoff(Goal destination) {
|
|
||||||
if (length() < BaritoneAPI.getSettings().pathCutoffMinimumLength.get()) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
if (destination == null || destination.isInGoal(getDest())) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
double factor = BaritoneAPI.getSettings().pathCutoffFactor.get();
|
|
||||||
int newLength = (int) (length() * factor);
|
|
||||||
return new CutoffPath(this, newLength);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,11 +21,12 @@ import baritone.api.pathing.calc.IPath;
|
||||||
import baritone.api.pathing.goals.Goal;
|
import baritone.api.pathing.goals.Goal;
|
||||||
import baritone.api.pathing.movement.IMovement;
|
import baritone.api.pathing.movement.IMovement;
|
||||||
import baritone.api.utils.BetterBlockPos;
|
import baritone.api.utils.BetterBlockPos;
|
||||||
|
import baritone.utils.pathing.PathBase;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CutoffPath implements IPath {
|
public class CutoffPath extends PathBase {
|
||||||
|
|
||||||
private final List<BetterBlockPos> path;
|
private final List<BetterBlockPos> path;
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,11 @@ import baritone.api.pathing.calc.IPath;
|
||||||
import baritone.api.pathing.goals.Goal;
|
import baritone.api.pathing.goals.Goal;
|
||||||
import baritone.api.pathing.movement.IMovement;
|
import baritone.api.pathing.movement.IMovement;
|
||||||
import baritone.api.utils.BetterBlockPos;
|
import baritone.api.utils.BetterBlockPos;
|
||||||
|
import baritone.utils.pathing.PathBase;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class SplicedPath implements IPath {
|
public class SplicedPath extends PathBase {
|
||||||
private final List<BetterBlockPos> path;
|
private final List<BetterBlockPos> path;
|
||||||
|
|
||||||
private final List<IMovement> movements;
|
private final List<IMovement> movements;
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* 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.utils.pathing;
|
||||||
|
|
||||||
|
import baritone.api.BaritoneAPI;
|
||||||
|
import baritone.api.pathing.calc.IPath;
|
||||||
|
import baritone.api.pathing.goals.Goal;
|
||||||
|
import baritone.pathing.path.CutoffPath;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.chunk.EmptyChunk;
|
||||||
|
|
||||||
|
public abstract class PathBase implements IPath {
|
||||||
|
@Override
|
||||||
|
public IPath cutoffAtLoadedChunks() {
|
||||||
|
for (int i = 0; i < positions().size(); i++) {
|
||||||
|
BlockPos pos = positions().get(i);
|
||||||
|
if (Minecraft.getMinecraft().world.getChunk(pos) instanceof EmptyChunk) {
|
||||||
|
return new CutoffPath(this, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPath staticCutoff(Goal destination) {
|
||||||
|
if (length() < BaritoneAPI.getSettings().pathCutoffMinimumLength.get()) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
if (destination == null || destination.isInGoal(getDest())) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
double factor = BaritoneAPI.getSettings().pathCutoffFactor.get();
|
||||||
|
int newLength = (int) ((length() - 1) * factor);
|
||||||
|
return new CutoffPath(this, newLength);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue