From 1dca02517e412565071ef95d0a1a5fe19dd99bbd Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 9 Jan 2019 15:42:49 -0800 Subject: [PATCH] disable backtrack cost favoring while building --- src/main/java/baritone/behavior/PathingBehavior.java | 2 +- .../baritone/pathing/movement/CalculationContext.java | 2 ++ src/main/java/baritone/process/BuilderProcess.java | 1 + src/main/java/baritone/utils/pathing/Favoring.java | 10 +++++----- .../baritone/utils/pathing/SegmentedCalculator.java | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 06020598..b789b096 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -517,7 +517,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, transformed = new GoalXZ(pos.getX(), pos.getZ()); } } - Favoring favoring = new Favoring(context.getBaritone().getPlayerContext(), previous); + Favoring favoring = new Favoring(context.getBaritone().getPlayerContext(), previous, context); return new AStarPathFinder(start.getX(), start.getY(), start.getZ(), transformed, favoring, context); } diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index 95887efd..03fa6ddb 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -65,6 +65,7 @@ public class CalculationContext { public final int maxFallHeightBucket; public final double waterWalkSpeed; public final double breakBlockAdditionalCost; + public double backtrackCostFavoringCoefficient; public double jumpPenalty; public final double walkOnWaterOnePenalty; public final BetterWorldBorder worldBorder; @@ -100,6 +101,7 @@ public class CalculationContext { float mult = depth / 3.0F; this.waterWalkSpeed = ActionCosts.WALK_ONE_IN_WATER_COST * (1 - mult) + ActionCosts.WALK_ONE_BLOCK_COST * mult; this.breakBlockAdditionalCost = Baritone.settings().blockBreakAdditionalPenalty.get(); + this.backtrackCostFavoringCoefficient = Baritone.settings().backtrackCostFavoringCoefficient.get(); this.jumpPenalty = Baritone.settings().jumpPenalty.get(); this.walkOnWaterOnePenalty = Baritone.settings().walkOnWaterOnePenalty.get(); // why cache these things here, why not let the movements just get directly from settings? diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index e64a6627..a679c028 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -330,6 +330,7 @@ public class BuilderProcess extends BaritoneProcessHelper { this.originZ = schematicOrigin.getZ(); this.jumpPenalty += 10; + this.backtrackCostFavoringCoefficient = 1; } private IBlockState getSchematic(int x, int y, int z) { diff --git a/src/main/java/baritone/utils/pathing/Favoring.java b/src/main/java/baritone/utils/pathing/Favoring.java index 7ffe49ff..8a601758 100644 --- a/src/main/java/baritone/utils/pathing/Favoring.java +++ b/src/main/java/baritone/utils/pathing/Favoring.java @@ -17,27 +17,27 @@ package baritone.utils.pathing; -import baritone.Baritone; import baritone.api.pathing.calc.IPath; import baritone.api.utils.BetterBlockPos; import baritone.api.utils.IPlayerContext; +import baritone.pathing.movement.CalculationContext; import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap; public final class Favoring { private final Long2DoubleOpenHashMap favorings; - public Favoring(IPlayerContext ctx, IPath previous) { - this(previous); + public Favoring(IPlayerContext ctx, IPath previous, CalculationContext context) { + this(previous, context); for (Avoidance avoid : Avoidance.create(ctx)) { avoid.applySpherical(favorings); } System.out.println("Favoring size: " + favorings.size()); } - public Favoring(IPath previous) { // create one just from previous path, no mob avoidances + public Favoring(IPath previous, CalculationContext context) { // create one just from previous path, no mob avoidances favorings = new Long2DoubleOpenHashMap(); favorings.defaultReturnValue(1.0D); - double coeff = Baritone.settings().backtrackCostFavoringCoefficient.get(); + double coeff = context.backtrackCostFavoringCoefficient; if (coeff != 1D && previous != null) { previous.positions().forEach(pos -> favorings.put(BetterBlockPos.longHash(pos), coeff)); } diff --git a/src/main/java/baritone/utils/pathing/SegmentedCalculator.java b/src/main/java/baritone/utils/pathing/SegmentedCalculator.java index e1d6dd10..523825ab 100644 --- a/src/main/java/baritone/utils/pathing/SegmentedCalculator.java +++ b/src/main/java/baritone/utils/pathing/SegmentedCalculator.java @@ -87,7 +87,7 @@ public class SegmentedCalculator { private PathCalculationResult segment(Optional previous) { BetterBlockPos segmentStart = previous.map(IPath::getDest).orElse(start); // <-- e p i c - AbstractNodeCostSearch search = new AStarPathFinder(segmentStart.x, segmentStart.y, segmentStart.z, goal, new Favoring(previous.orElse(null)), context); // this is on another thread, so cannot include mob avoidances. + AbstractNodeCostSearch search = new AStarPathFinder(segmentStart.x, segmentStart.y, segmentStart.z, goal, new Favoring(previous.orElse(null), context), context); // this is on another thread, so cannot include mob avoidances. return search.calculate(Baritone.settings().primaryTimeoutMS.get(), Baritone.settings().failureTimeoutMS.get()); // use normal time settings, not the plan ahead settings, so as to not overwhelm the computer }