favored lookup performance
This commit is contained in:
		@@ -37,12 +37,15 @@ import baritone.pathing.path.CutoffPath;
 | 
			
		||||
import baritone.pathing.path.PathExecutor;
 | 
			
		||||
import baritone.utils.Helper;
 | 
			
		||||
import baritone.utils.PathRenderer;
 | 
			
		||||
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
 | 
			
		||||
import net.minecraft.util.math.BlockPos;
 | 
			
		||||
import net.minecraft.world.chunk.EmptyChunk;
 | 
			
		||||
 | 
			
		||||
import java.util.*;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Comparator;
 | 
			
		||||
import java.util.Objects;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
import java.util.concurrent.LinkedBlockingQueue;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
public final class PathingBehavior extends Behavior implements IPathingBehavior, Helper {
 | 
			
		||||
 | 
			
		||||
@@ -492,9 +495,11 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
 | 
			
		||||
                transformed = new GoalXZ(pos.getX(), pos.getZ());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        HashSet<Long> favoredPositions = null;
 | 
			
		||||
        LongOpenHashSet favoredPositions = null;
 | 
			
		||||
        if (Baritone.settings().backtrackCostFavoringCoefficient.get() != 1D && previous != null) {
 | 
			
		||||
            favoredPositions = previous.positions().stream().map(BetterBlockPos::longHash).collect(Collectors.toCollection(HashSet::new));
 | 
			
		||||
            LongOpenHashSet tmp = new LongOpenHashSet();
 | 
			
		||||
            previous.positions().forEach(pos -> tmp.add(BetterBlockPos.longHash(pos)));
 | 
			
		||||
            favoredPositions = tmp;
 | 
			
		||||
        }
 | 
			
		||||
        return new AStarPathFinder(start.getX(), start.getY(), start.getZ(), transformed, favoredPositions, context);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -28,6 +28,7 @@ import baritone.pathing.movement.Moves;
 | 
			
		||||
import baritone.utils.Helper;
 | 
			
		||||
import baritone.utils.pathing.BetterWorldBorder;
 | 
			
		||||
import baritone.utils.pathing.MutableMoveResult;
 | 
			
		||||
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
 | 
			
		||||
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
@@ -39,10 +40,10 @@ import java.util.Optional;
 | 
			
		||||
 */
 | 
			
		||||
public final class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
 | 
			
		||||
 | 
			
		||||
    private final HashSet<Long> favoredPositions;
 | 
			
		||||
    private final LongOpenHashSet favoredPositions;
 | 
			
		||||
    private final CalculationContext calcContext;
 | 
			
		||||
 | 
			
		||||
    public AStarPathFinder(int startX, int startY, int startZ, Goal goal, HashSet<Long> favoredPositions, CalculationContext context) {
 | 
			
		||||
    public AStarPathFinder(int startX, int startY, int startZ, Goal goal, LongOpenHashSet favoredPositions, CalculationContext context) {
 | 
			
		||||
        super(startX, startY, startZ, goal, context);
 | 
			
		||||
        this.favoredPositions = favoredPositions;
 | 
			
		||||
        this.calcContext = context;
 | 
			
		||||
@@ -63,7 +64,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
 | 
			
		||||
            bestSoFar[i] = startNode;
 | 
			
		||||
        }
 | 
			
		||||
        MutableMoveResult res = new MutableMoveResult();
 | 
			
		||||
        HashSet<Long> favored = favoredPositions;
 | 
			
		||||
        LongOpenHashSet favored = favoredPositions;
 | 
			
		||||
        BetterWorldBorder worldBorder = new BetterWorldBorder(calcContext.world().getWorldBorder());
 | 
			
		||||
        long startTime = System.nanoTime() / 1000000L;
 | 
			
		||||
        boolean slowPath = Baritone.settings().slowPath.get();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user