cutoff at edge of loaded chunks
This commit is contained in:
parent
9190e82b20
commit
58a1f65044
@ -63,6 +63,11 @@ public class PathingBehavior extends Behavior {
|
|||||||
synchronized (pathPlanLock) {
|
synchronized (pathPlanLock) {
|
||||||
if (current.failed() || current.finished()) {
|
if (current.failed() || current.finished()) {
|
||||||
current = null;
|
current = null;
|
||||||
|
if (goal.isInGoal(playerFeet())) {
|
||||||
|
displayChatMessageRaw("All done. At " + goal);
|
||||||
|
next = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (next != null && !next.getPath().positions().contains(playerFeet())) {
|
if (next != null && !next.getPath().positions().contains(playerFeet())) {
|
||||||
// if the current path failed, we may not actually be on the next one, so make sure
|
// if the current path failed, we may not actually be on the next one, so make sure
|
||||||
displayChatMessageRaw("Discarding next path as it does not contain current position");
|
displayChatMessageRaw("Discarding next path as it does not contain current position");
|
||||||
@ -78,9 +83,6 @@ public class PathingBehavior extends Behavior {
|
|||||||
next = null;
|
next = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (goal.isInGoal(playerFeet())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// at this point, current just ended, but we aren't in the goal and have no plan for the future
|
// at this point, current just ended, but we aren't in the goal and have no plan for the future
|
||||||
synchronized (pathCalcLock) {
|
synchronized (pathCalcLock) {
|
||||||
if (isPathCalcInProgress) {
|
if (isPathCalcInProgress) {
|
||||||
@ -118,7 +120,7 @@ public class PathingBehavior extends Behavior {
|
|||||||
}
|
}
|
||||||
if (current.getPath().ticksRemainingFrom(current.getPosition()) < 200) {
|
if (current.getPath().ticksRemainingFrom(current.getPosition()) < 200) {
|
||||||
// and this path has 5 seconds or less left
|
// and this path has 5 seconds or less left
|
||||||
displayChatMessageRaw("Path almost over; planning ahead");
|
displayChatMessageRaw("Path almost over. Planning ahead...");
|
||||||
findPathInNewThread(current.getPath().getDest(), false);
|
findPathInNewThread(current.getPath().getDest(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -210,7 +212,7 @@ public class PathingBehavior extends Behavior {
|
|||||||
displayChatMessageRaw("Starting to search for path from " + start + " to " + goal);
|
displayChatMessageRaw("Starting to search for path from " + start + " to " + goal);
|
||||||
}
|
}
|
||||||
|
|
||||||
findPath(start).map(PathExecutor::new).ifPresent(path -> {
|
findPath(start).map(IPath::cutoffAtLoadedChunks).map(PathExecutor::new).ifPresent(path -> {
|
||||||
synchronized (pathPlanLock) {
|
synchronized (pathPlanLock) {
|
||||||
if (current == null) {
|
if (current == null) {
|
||||||
current = path;
|
current = path;
|
||||||
|
54
src/main/java/baritone/bot/pathing/path/CutoffPath.java
Normal file
54
src/main/java/baritone/bot/pathing/path/CutoffPath.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 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package baritone.bot.pathing.path;
|
||||||
|
|
||||||
|
import baritone.bot.pathing.movement.Movement;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CutoffPath implements IPath {
|
||||||
|
|
||||||
|
final List<BlockPos> path;
|
||||||
|
|
||||||
|
final List<Movement> movements;
|
||||||
|
|
||||||
|
private final int numNodes;
|
||||||
|
|
||||||
|
public CutoffPath(IPath prev, int lastPositionToInclude) {
|
||||||
|
path = prev.positions().subList(0, lastPositionToInclude + 1);
|
||||||
|
movements = prev.movements().subList(0, lastPositionToInclude + 1);
|
||||||
|
numNodes = prev.getNumNodesConsidered();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Movement> movements() {
|
||||||
|
return Collections.unmodifiableList(movements);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BlockPos> positions() {
|
||||||
|
return Collections.unmodifiableList(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getNumNodesConsidered() {
|
||||||
|
return numNodes;
|
||||||
|
}
|
||||||
|
}
|
@ -18,16 +18,19 @@
|
|||||||
package baritone.bot.pathing.path;
|
package baritone.bot.pathing.path;
|
||||||
|
|
||||||
import baritone.bot.pathing.movement.Movement;
|
import baritone.bot.pathing.movement.Movement;
|
||||||
|
import baritone.bot.utils.Helper;
|
||||||
import baritone.bot.utils.Utils;
|
import baritone.bot.utils.Utils;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.util.Tuple;
|
import net.minecraft.util.Tuple;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.chunk.EmptyChunk;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author leijurv
|
* @author leijurv
|
||||||
*/
|
*/
|
||||||
public interface IPath {
|
public interface IPath extends Helper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ordered list of movements to carry out.
|
* Ordered list of movements to carry out.
|
||||||
@ -117,4 +120,18 @@ public interface IPath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int getNumNodesConsidered();
|
int getNumNodesConsidered();
|
||||||
|
|
||||||
|
default IPath cutoffAtLoadedChunks() {
|
||||||
|
for (int i = 0; i < positions().size(); i++) {
|
||||||
|
BlockPos pos = positions().get(i);
|
||||||
|
if (Minecraft.getMinecraft().world.getChunk(pos) instanceof EmptyChunk) {
|
||||||
|
displayChatMessageRaw("Cutting off path at edge of loaded chunks");
|
||||||
|
displayChatMessageRaw("Length decreased by " + (positions().size() - i - 1));
|
||||||
|
return new CutoffPath(this, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
displayChatMessageRaw("Path ends within loaded chunks");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user