Get Cutoff implementation out of API we DON'T need you

This commit is contained in:
Brady 2018-10-09 00:10:50 -05:00
parent 0fb5f3233f
commit 771e892b31
No known key found for this signature in database
GPG Key ID: 73A788379A197567
12 changed files with 56 additions and 127 deletions

View File

@ -19,7 +19,7 @@ package baritone.api.behavior;
import baritone.api.pathing.calc.IPathFinder;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.path.IPath;
import baritone.api.pathing.calc.IPath;
import baritone.api.pathing.path.IPathExecutor;
import java.util.Optional;

View File

@ -15,16 +15,12 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.api.pathing.path;
package baritone.api.pathing.calc;
import baritone.api.BaritoneAPI;
import baritone.api.Settings;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.movement.IMovement;
import baritone.api.utils.BetterBlockPos;
import net.minecraft.client.Minecraft;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.chunk.EmptyChunk;
import java.util.List;
@ -116,37 +112,25 @@ public interface IPath {
}
/**
* Cuts off this path at the loaded chunk border, and returns the {@link CutoffResult}.
* Cuts off this path at the loaded chunk border, and returns the resulting path. Default
* implementation just returns this path, without the intended functionality.
*
* @return The result of this cut-off operation
*/
default CutoffResult cutoffAtLoadedChunks() {
for (int i = 0; i < positions().size(); i++) {
BlockPos pos = positions().get(i);
if (Minecraft.getMinecraft().world.getChunk(pos) instanceof EmptyChunk) {
return CutoffResult.cutoffPath(this, i);
}
}
return CutoffResult.preservePath(this);
default IPath cutoffAtLoadedChunks() {
return this;
}
/**
* Cuts off this path using the min length and cutoff factor settings, and returns the {@link CutoffResult}.
* Cuts off this path using the min length and cutoff factor settings, and returns the resulting path.
* Default implementation just returns this path, without the intended functionality.
*
* @see Settings#pathCutoffMinimumLength
* @see Settings#pathCutoffFactor
*
* @return The result of this cut-off operation
*/
default CutoffResult staticCutoff(Goal destination) {
if (length() < BaritoneAPI.getSettings().pathCutoffMinimumLength.get()) {
return CutoffResult.preservePath(this);
}
if (destination == null || destination.isInGoal(getDest())) {
return CutoffResult.preservePath(this);
}
double factor = BaritoneAPI.getSettings().pathCutoffFactor.get();
int newLength = (int) (length() * factor);
return CutoffResult.cutoffPath(this, newLength);
default IPath staticCutoff(Goal destination) {
return this;
}
}

View File

@ -18,7 +18,6 @@
package baritone.api.pathing.calc;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.path.IPath;
import java.util.Optional;

View File

@ -1,84 +0,0 @@
/*
* 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.api.pathing.path;
/**
* The result of a path cut-off operation.
*
* @author Brady
* @since 10/8/2018
*/
public final class CutoffResult {
/**
* The resulting path
*/
private final IPath path;
/**
* The amount of movements that were removed
*/
private final int removed;
private CutoffResult(IPath path, int removed) {
this.path = path;
this.removed = removed;
}
/**
* @return Whether or not the path was cut
*/
public final boolean wasCut() {
return this.removed > 0;
}
/**
* @return The amount of movements that were removed
*/
public final int getRemoved() {
return this.removed;
}
/**
* @return The resulting path
*/
public final IPath getPath() {
return this.path;
}
/**
* Creates a new result from a successful cut-off operation.
*
* @param path The input path
* @param index The index to cut the path at
* @return The result of the operation
*/
public static CutoffResult cutoffPath(IPath path, int index) {
return new CutoffResult(new CutoffPath(path, index), path.positions().size() - index - 1);
}
/**
* Creates a new result in which no cut-off occurred.
*
* @param path The input path
* @return The result of the operation
*/
public static CutoffResult preservePath(IPath path) {
return new CutoffResult(path, 0);
}
}

View File

@ -17,6 +17,8 @@
package baritone.api.pathing.path;
import baritone.api.pathing.calc.IPath;
/**
* @author Brady
* @since 10/8/2018

View File

@ -25,8 +25,8 @@ import baritone.api.event.events.RenderEvent;
import baritone.api.event.events.TickEvent;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.goals.GoalXZ;
import baritone.api.pathing.path.CutoffResult;
import baritone.api.pathing.path.IPath;
import baritone.pathing.calc.CutoffPath;
import baritone.api.pathing.calc.IPath;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.interfaces.IGoalRenderPos;
import baritone.pathing.calc.AStarPathFinder;
@ -285,27 +285,27 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
Optional<IPath> path = findPath(start, previous);
if (Baritone.settings().cutoffAtLoadBoundary.get()) {
path = path.map(p -> {
CutoffResult result = p.cutoffAtLoadedChunks();
IPath result = p.cutoffAtLoadedChunks();
if (result.wasCut()) {
if (result instanceof CutoffPath) {
logDebug("Cutting off path at edge of loaded chunks");
logDebug("Length decreased by " + result.getRemoved());
logDebug("Length decreased by " + (p.length() - result.length()));
} else {
logDebug("Path ends within loaded chunks");
}
return result.getPath();
return result;
});
}
Optional<PathExecutor> executor = path.map(p -> {
CutoffResult result = p.staticCutoff(goal);
IPath result = p.staticCutoff(goal);
if (result.wasCut()) {
logDebug("Static cutoff " + p.length() + " to " + result.getPath().length());
if (result instanceof CutoffPath) {
logDebug("Static cutoff " + p.length() + " to " + result.length());
}
return result.getPath();
return result;
}).map(PathExecutor::new);
synchronized (pathPlanLock) {

View File

@ -20,7 +20,7 @@ package baritone.pathing.calc;
import baritone.Baritone;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.movement.ActionCosts;
import baritone.api.pathing.path.IPath;
import baritone.api.pathing.calc.IPath;
import baritone.api.utils.BetterBlockPos;
import baritone.pathing.calc.openset.BinaryHeapOpenSet;
import baritone.pathing.movement.CalculationContext;

View File

@ -20,7 +20,7 @@ package baritone.pathing.calc;
import baritone.Baritone;
import baritone.api.pathing.calc.IPathFinder;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.path.IPath;
import baritone.api.pathing.calc.IPath;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import java.util.Optional;

View File

@ -15,10 +15,11 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.api.pathing.path;
package baritone.pathing.calc;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.movement.IMovement;
import baritone.api.pathing.calc.IPath;
import baritone.api.utils.BetterBlockPos;
import java.util.Collections;

View File

@ -17,13 +17,16 @@
package baritone.pathing.calc;
import baritone.api.BaritoneAPI;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.movement.IMovement;
import baritone.api.pathing.path.IPath;
import baritone.api.pathing.calc.IPath;
import baritone.api.utils.BetterBlockPos;
import baritone.pathing.movement.Movement;
import baritone.pathing.movement.Moves;
import net.minecraft.client.Minecraft;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.chunk.EmptyChunk;
import java.util.ArrayList;
import java.util.Collections;
@ -188,4 +191,28 @@ class Path implements IPath {
public BetterBlockPos getDest() {
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);
}
}

View File

@ -22,7 +22,7 @@ import baritone.api.event.events.TickEvent;
import baritone.api.pathing.movement.ActionCosts;
import baritone.api.pathing.movement.IMovement;
import baritone.api.pathing.movement.MovementStatus;
import baritone.api.pathing.path.IPath;
import baritone.api.pathing.calc.IPath;
import baritone.api.pathing.path.IPathExecutor;
import baritone.api.utils.BetterBlockPos;
import baritone.pathing.calc.AbstractNodeCostSearch;

View File

@ -23,7 +23,7 @@ import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.goals.GoalComposite;
import baritone.api.pathing.goals.GoalTwoBlocks;
import baritone.api.pathing.goals.GoalXZ;
import baritone.api.pathing.path.IPath;
import baritone.api.pathing.calc.IPath;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.interfaces.IGoalRenderPos;
import baritone.behavior.PathingBehavior;