forked from RepoMirrors/baritone
original blockpos for comparison
This commit is contained in:
parent
d8ca6cad4e
commit
125c8a6742
|
@ -30,7 +30,6 @@ import baritone.pathing.movement.movements.*;
|
|||
import baritone.pathing.path.IPath;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.Helper;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ChunkProviderClient;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
@ -48,9 +47,9 @@ import java.util.Random;
|
|||
*/
|
||||
public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
||||
|
||||
private final Optional<HashSet<BetterBlockPos>> favoredPositions;
|
||||
private final Optional<HashSet<BlockPos>> favoredPositions;
|
||||
|
||||
public AStarPathFinder(BlockPos start, Goal goal, Optional<Collection<BetterBlockPos>> favoredPositions) {
|
||||
public AStarPathFinder(BlockPos start, Goal goal, Optional<Collection<BlockPos>> favoredPositions) {
|
||||
super(start, goal);
|
||||
this.favoredPositions = favoredPositions.map(HashSet::new); // <-- okay this is epic
|
||||
}
|
||||
|
@ -69,7 +68,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
|||
bestHeuristicSoFar[i] = Double.MAX_VALUE;
|
||||
}
|
||||
CalculationContext calcContext = new CalculationContext();
|
||||
HashSet<BetterBlockPos> favored = favoredPositions.orElse(null);
|
||||
HashSet<BlockPos> favored = favoredPositions.orElse(null);
|
||||
currentlyRunning = this;
|
||||
CachedWorld cachedWorld = Optional.ofNullable(WorldProvider.INSTANCE.getCurrentWorld()).map(w -> w.cache).orElse(null);
|
||||
ChunkProviderClient chunkProvider = Minecraft.getMinecraft().world.getChunkProvider();
|
||||
|
@ -98,7 +97,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
|||
PathNode currentNode = openSet.removeLowest();
|
||||
currentNode.isOpen = false;
|
||||
mostRecentConsidered = currentNode;
|
||||
BetterBlockPos currentNodePos = currentNode.pos;
|
||||
BlockPos currentNodePos = currentNode.pos;
|
||||
numNodes++;
|
||||
if (goal.isInGoal(currentNodePos)) {
|
||||
currentlyRunning = null;
|
||||
|
@ -111,10 +110,10 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
|||
if (movementToGetToNeighbor == null) {
|
||||
continue;
|
||||
}
|
||||
BetterBlockPos dest = movementToGetToNeighbor.getDest();
|
||||
int chunkX = currentNodePos.x >> 4;
|
||||
int chunkZ = currentNodePos.z >> 4;
|
||||
if (dest.x >> 4 != chunkX || dest.z >> 4 != chunkZ) {
|
||||
BlockPos dest = movementToGetToNeighbor.getDest();
|
||||
int chunkX = currentNodePos.getX() >> 4;
|
||||
int chunkZ = currentNodePos.getZ() >> 4;
|
||||
if (dest.getX() >> 4 != chunkX || dest.getZ() >> 4 != chunkZ) {
|
||||
// only need to check if the destination is a loaded chunk if it's in a different chunk than the start of the movement
|
||||
if (chunkProvider.getLoadedChunk(chunkX, chunkZ) == null) {
|
||||
// see issue #106
|
||||
|
@ -209,33 +208,33 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
|||
}
|
||||
|
||||
|
||||
public static Movement[] getConnectedPositions(BetterBlockPos pos, CalculationContext calcContext) {
|
||||
public static Movement[] getConnectedPositions(BlockPos pos, CalculationContext calcContext) {
|
||||
int x = pos.getX();
|
||||
int y = pos.getY();
|
||||
int z = pos.getZ();
|
||||
BetterBlockPos east = new BetterBlockPos(x + 1, y, z);
|
||||
BetterBlockPos west = new BetterBlockPos(x - 1, y, z);
|
||||
BetterBlockPos south = new BetterBlockPos(x, y, z + 1);
|
||||
BetterBlockPos north = new BetterBlockPos(x, y, z - 1);
|
||||
BlockPos east = new BlockPos(x + 1, y, z);
|
||||
BlockPos west = new BlockPos(x - 1, y, z);
|
||||
BlockPos south = new BlockPos(x, y, z + 1);
|
||||
BlockPos north = new BlockPos(x, y, z - 1);
|
||||
return new Movement[]{
|
||||
new MovementTraverse(pos, east),
|
||||
new MovementTraverse(pos, west),
|
||||
new MovementTraverse(pos, north),
|
||||
new MovementTraverse(pos, south),
|
||||
new MovementAscend(pos, new BetterBlockPos(x + 1, y + 1, z)),
|
||||
new MovementAscend(pos, new BetterBlockPos(x - 1, y + 1, z)),
|
||||
new MovementAscend(pos, new BetterBlockPos(x, y + 1, z + 1)),
|
||||
new MovementAscend(pos, new BetterBlockPos(x, y + 1, z - 1)),
|
||||
new MovementAscend(pos, new BlockPos(x + 1, y + 1, z)),
|
||||
new MovementAscend(pos, new BlockPos(x - 1, y + 1, z)),
|
||||
new MovementAscend(pos, new BlockPos(x, y + 1, z + 1)),
|
||||
new MovementAscend(pos, new BlockPos(x, y + 1, z - 1)),
|
||||
MovementHelper.generateMovementFallOrDescend(pos, east, calcContext),
|
||||
MovementHelper.generateMovementFallOrDescend(pos, west, calcContext),
|
||||
MovementHelper.generateMovementFallOrDescend(pos, north, calcContext),
|
||||
MovementHelper.generateMovementFallOrDescend(pos, south, calcContext),
|
||||
new MovementDownward(pos, new BetterBlockPos(x, y - 1, z)),
|
||||
new MovementDownward(pos, new BlockPos(x, y - 1, z)),
|
||||
new MovementDiagonal(pos, EnumFacing.NORTH, EnumFacing.WEST),
|
||||
new MovementDiagonal(pos, EnumFacing.NORTH, EnumFacing.EAST),
|
||||
new MovementDiagonal(pos, EnumFacing.SOUTH, EnumFacing.WEST),
|
||||
new MovementDiagonal(pos, EnumFacing.SOUTH, EnumFacing.EAST),
|
||||
new MovementPillar(pos, new BetterBlockPos(x, y + 1, z)),
|
||||
new MovementPillar(pos, new BlockPos(x, y + 1, z)),
|
||||
MovementParkour.calculate(pos, EnumFacing.NORTH),
|
||||
MovementParkour.calculate(pos, EnumFacing.SOUTH),
|
||||
MovementParkour.calculate(pos, EnumFacing.EAST),
|
||||
|
|
|
@ -20,10 +20,9 @@ package baritone.pathing.calc;
|
|||
import baritone.behavior.impl.PathingBehavior;
|
||||
import baritone.pathing.goals.Goal;
|
||||
import baritone.pathing.path.IPath;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
|
@ -38,11 +37,11 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
|||
*/
|
||||
protected static AbstractNodeCostSearch currentlyRunning = null;
|
||||
|
||||
protected final BetterBlockPos start;
|
||||
protected final BlockPos start;
|
||||
|
||||
protected final Goal goal;
|
||||
|
||||
private final Long2ObjectOpenHashMap<PathNode> map; // see issue #107
|
||||
private final HashMap<BlockPos, PathNode> map; // see issue #107
|
||||
|
||||
protected PathNode startNode;
|
||||
|
||||
|
@ -67,9 +66,9 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
|||
protected final static double MIN_DIST_PATH = 5;
|
||||
|
||||
AbstractNodeCostSearch(BlockPos start, Goal goal) {
|
||||
this.start = new BetterBlockPos(start.getX(), start.getY(), start.getZ());
|
||||
this.start = new BlockPos(start.getX(), start.getY(), start.getZ());
|
||||
this.goal = goal;
|
||||
this.map = new Long2ObjectOpenHashMap<>();
|
||||
this.map = new HashMap<>();
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
|
@ -121,13 +120,12 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
|||
* @param pos The pos to lookup
|
||||
* @return The associated node
|
||||
*/
|
||||
protected PathNode getNodeAtPosition(BetterBlockPos pos) {
|
||||
protected PathNode getNodeAtPosition(BlockPos pos) {
|
||||
// see issue #107
|
||||
long hashCode = pos.hashCode;
|
||||
PathNode node = map.get(hashCode);
|
||||
PathNode node = map.get(pos);
|
||||
if (node == null) {
|
||||
node = new PathNode(pos, goal);
|
||||
map.put(hashCode, node);
|
||||
map.put(pos, node);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ package baritone.pathing.calc;
|
|||
|
||||
import baritone.pathing.movement.Movement;
|
||||
import baritone.pathing.path.IPath;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -37,18 +37,18 @@ class Path implements IPath {
|
|||
/**
|
||||
* The start position of this path
|
||||
*/
|
||||
final BetterBlockPos start;
|
||||
final BlockPos start;
|
||||
|
||||
/**
|
||||
* The end position of this path
|
||||
*/
|
||||
final BetterBlockPos end;
|
||||
final BlockPos end;
|
||||
|
||||
/**
|
||||
* The blocks on the path. Guaranteed that path.get(0) equals start and
|
||||
* path.get(path.size()-1) equals end
|
||||
*/
|
||||
final List<BetterBlockPos> path;
|
||||
final List<BlockPos> path;
|
||||
|
||||
final List<Movement> movements;
|
||||
|
||||
|
@ -75,7 +75,7 @@ class Path implements IPath {
|
|||
throw new IllegalStateException();
|
||||
}
|
||||
PathNode current = end;
|
||||
LinkedList<BetterBlockPos> tempPath = new LinkedList<>(); // Repeatedly inserting to the beginning of an arraylist is O(n^2)
|
||||
LinkedList<BlockPos> tempPath = new LinkedList<>(); // Repeatedly inserting to the beginning of an arraylist is O(n^2)
|
||||
LinkedList<Movement> tempMovements = new LinkedList<>(); // Instead, do it into a linked list, then convert at the end
|
||||
while (!current.equals(start)) {
|
||||
tempPath.addFirst(current.pos);
|
||||
|
@ -122,7 +122,7 @@ class Path implements IPath {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<BetterBlockPos> positions() {
|
||||
public List<BlockPos> positions() {
|
||||
return Collections.unmodifiableList(path);
|
||||
}
|
||||
|
||||
|
@ -132,12 +132,12 @@ class Path implements IPath {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BetterBlockPos getSrc() {
|
||||
public BlockPos getSrc() {
|
||||
return start;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BetterBlockPos getDest() {
|
||||
public BlockPos getDest() {
|
||||
return end;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ package baritone.pathing.calc;
|
|||
|
||||
import baritone.pathing.goals.Goal;
|
||||
import baritone.pathing.movement.Movement;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/**
|
||||
* A node in the path, containing the cost and steps to get to it.
|
||||
|
@ -31,7 +31,7 @@ public final class PathNode {
|
|||
/**
|
||||
* The position of this node
|
||||
*/
|
||||
final BetterBlockPos pos;
|
||||
final BlockPos pos;
|
||||
|
||||
/**
|
||||
* The goal it's going towards
|
||||
|
@ -78,7 +78,7 @@ public final class PathNode {
|
|||
*/
|
||||
public int heapPosition;
|
||||
|
||||
public PathNode(BetterBlockPos pos, Goal goal) {
|
||||
public PathNode(BlockPos pos, Goal goal) {
|
||||
this.pos = pos;
|
||||
this.previous = null;
|
||||
this.cost = Short.MAX_VALUE;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
package baritone.pathing.goals;
|
||||
|
||||
import baritone.utils.interfaces.IGoalRenderPos;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
|
||||
|
@ -40,7 +40,7 @@ public class GoalGetToBlock implements Goal, IGoalRenderPos {
|
|||
}
|
||||
|
||||
public BlockPos getGoalPos() {
|
||||
return new BetterBlockPos(x, y, z);
|
||||
return new BlockPos(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -22,7 +22,7 @@ import baritone.behavior.impl.LookBehavior;
|
|||
import baritone.behavior.impl.LookBehaviorUtils;
|
||||
import baritone.pathing.movement.MovementState.MovementStatus;
|
||||
import baritone.utils.*;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
|
@ -40,9 +40,9 @@ public abstract class Movement implements Helper, MovementHelper {
|
|||
|
||||
private MovementState currentState = new MovementState().setStatus(MovementStatus.PREPPING);
|
||||
|
||||
protected final BetterBlockPos src;
|
||||
protected final BlockPos src;
|
||||
|
||||
protected final BetterBlockPos dest;
|
||||
protected final BlockPos dest;
|
||||
|
||||
/**
|
||||
* The positions that need to be broken before this movement can ensue
|
||||
|
@ -58,14 +58,14 @@ public abstract class Movement implements Helper, MovementHelper {
|
|||
|
||||
private Double cost;
|
||||
|
||||
protected Movement(BetterBlockPos src, BetterBlockPos dest, BlockPos[] toBreak, BlockPos toPlace) {
|
||||
protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak, BlockPos toPlace) {
|
||||
this.src = src;
|
||||
this.dest = dest;
|
||||
this.positionsToBreak = toBreak;
|
||||
this.positionToPlace = toPlace;
|
||||
}
|
||||
|
||||
protected Movement(BetterBlockPos src, BetterBlockPos dest, BlockPos[] toBreak) {
|
||||
protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak) {
|
||||
this(src, dest, toBreak, null);
|
||||
}
|
||||
|
||||
|
@ -186,11 +186,11 @@ public abstract class Movement implements Helper, MovementHelper {
|
|||
&& currentState.getStatus() != MovementStatus.WAITING);
|
||||
}
|
||||
|
||||
public BetterBlockPos getSrc() {
|
||||
public BlockPos getSrc() {
|
||||
return src;
|
||||
}
|
||||
|
||||
public BetterBlockPos getDest() {
|
||||
public BlockPos getDest() {
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ import baritone.pathing.movement.MovementState.MovementTarget;
|
|||
import baritone.pathing.movement.movements.MovementDescend;
|
||||
import baritone.pathing.movement.movements.MovementFall;
|
||||
import baritone.utils.*;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.properties.PropertyBool;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
@ -401,7 +401,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||
)).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
|
||||
}
|
||||
|
||||
static Movement generateMovementFallOrDescend(BetterBlockPos pos, BetterBlockPos dest, CalculationContext calcContext) {
|
||||
static Movement generateMovementFallOrDescend(BlockPos pos, BlockPos dest, CalculationContext calcContext) {
|
||||
// A
|
||||
//SA
|
||||
// A
|
||||
|
@ -424,7 +424,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||
// we're clear for a fall 2
|
||||
// let's see how far we can fall
|
||||
for (int fallHeight = 3; true; fallHeight++) {
|
||||
BetterBlockPos onto = dest.down(fallHeight);
|
||||
BlockPos onto = dest.down(fallHeight);
|
||||
if (onto.getY() < 0) {
|
||||
// when pathing in the end, where you could plausibly fall into the void
|
||||
// this check prevents it from getting the block at y=-1 and crashing
|
||||
|
|
|
@ -26,7 +26,7 @@ import baritone.pathing.movement.MovementState.MovementStatus;
|
|||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.InputOverrideHandler;
|
||||
import baritone.utils.Utils;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFalling;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
@ -42,7 +42,7 @@ public class MovementAscend extends Movement {
|
|||
|
||||
private int ticksWithoutPlacement = 0;
|
||||
|
||||
public MovementAscend(BetterBlockPos src, BetterBlockPos dest) {
|
||||
public MovementAscend(BlockPos src, BlockPos dest) {
|
||||
super(src, dest, new BlockPos[]{dest, src.up(2), dest.up()}, dest.down());
|
||||
}
|
||||
|
||||
|
|
|
@ -24,14 +24,14 @@ import baritone.pathing.movement.MovementState;
|
|||
import baritone.pathing.movement.MovementState.MovementStatus;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.InputOverrideHandler;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class MovementDescend extends Movement {
|
||||
|
||||
public MovementDescend(BetterBlockPos start, BetterBlockPos end) {
|
||||
public MovementDescend(BlockPos start, BlockPos end) {
|
||||
super(start, end, new BlockPos[]{end.up(2), end.up(), end}, end.down());
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ import baritone.pathing.movement.MovementHelper;
|
|||
import baritone.pathing.movement.MovementState;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.InputOverrideHandler;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockMagma;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
@ -38,16 +38,16 @@ public class MovementDiagonal extends Movement {
|
|||
|
||||
private static final double SQRT_2 = Math.sqrt(2);
|
||||
|
||||
public MovementDiagonal(BetterBlockPos start, EnumFacing dir1, EnumFacing dir2) {
|
||||
public MovementDiagonal(BlockPos start, EnumFacing dir1, EnumFacing dir2) {
|
||||
this(start, start.offset(dir1), start.offset(dir2), dir2);
|
||||
// super(start, start.offset(dir1).offset(dir2), new BlockPos[]{start.offset(dir1), start.offset(dir1).up(), start.offset(dir2), start.offset(dir2).up(), start.offset(dir1).offset(dir2), start.offset(dir1).offset(dir2).up()}, new BlockPos[]{start.offset(dir1).offset(dir2).down()});
|
||||
}
|
||||
|
||||
private MovementDiagonal(BetterBlockPos start, BetterBlockPos dir1, BetterBlockPos dir2, EnumFacing drr2) {
|
||||
private MovementDiagonal(BlockPos start, BlockPos dir1, BlockPos dir2, EnumFacing drr2) {
|
||||
this(start, dir1.offset(drr2), dir1, dir2);
|
||||
}
|
||||
|
||||
private MovementDiagonal(BetterBlockPos start, BetterBlockPos end, BetterBlockPos dir1, BetterBlockPos dir2) {
|
||||
private MovementDiagonal(BlockPos start, BlockPos end, BlockPos dir1, BlockPos dir2) {
|
||||
super(start, end, new BlockPos[]{dir1, dir1.up(), dir2, dir2.up(), end, end.up()});
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import baritone.pathing.movement.Movement;
|
|||
import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.pathing.movement.MovementState;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
|
@ -32,7 +32,7 @@ public class MovementDownward extends Movement {
|
|||
|
||||
private int numTicks = 0;
|
||||
|
||||
public MovementDownward(BetterBlockPos start, BetterBlockPos end) {
|
||||
public MovementDownward(BlockPos start, BlockPos end) {
|
||||
super(start, end, new BlockPos[]{end});
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ import baritone.pathing.movement.MovementState;
|
|||
import baritone.pathing.movement.MovementState.MovementStatus;
|
||||
import baritone.pathing.movement.MovementState.MovementTarget;
|
||||
import baritone.utils.*;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFalling;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
@ -42,7 +42,7 @@ public class MovementFall extends Movement {
|
|||
private static final ItemStack STACK_BUCKET_WATER = new ItemStack(Items.WATER_BUCKET);
|
||||
private static final ItemStack STACK_BUCKET_EMPTY = new ItemStack(Items.BUCKET);
|
||||
|
||||
public MovementFall(BetterBlockPos src, BetterBlockPos dest) {
|
||||
public MovementFall(BlockPos src, BlockPos dest) {
|
||||
super(src, dest, MovementFall.buildPositionsToBreak(src, dest));
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ import baritone.pathing.movement.MovementHelper;
|
|||
import baritone.pathing.movement.MovementState;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.InputOverrideHandler;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
@ -35,14 +35,14 @@ public class MovementParkour extends Movement {
|
|||
final EnumFacing direction;
|
||||
final int dist;
|
||||
|
||||
private MovementParkour(BetterBlockPos src, int dist, EnumFacing dir) {
|
||||
private MovementParkour(BlockPos src, int dist, EnumFacing dir) {
|
||||
super(src, src.offset(dir, dist), new BlockPos[]{});
|
||||
this.direction = dir;
|
||||
this.dist = dist;
|
||||
super.override(costFromJumpDistance(dist));
|
||||
}
|
||||
|
||||
public static MovementParkour calculate(BetterBlockPos src, EnumFacing dir) {
|
||||
public static MovementParkour calculate(BlockPos src, EnumFacing dir) {
|
||||
if (!Baritone.settings().allowParkour.get()) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import baritone.utils.BlockStateInterface;
|
|||
import baritone.utils.InputOverrideHandler;
|
||||
import baritone.utils.Rotation;
|
||||
import baritone.utils.Utils;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -34,7 +34,7 @@ import net.minecraft.util.math.BlockPos;
|
|||
public class MovementPillar extends Movement {
|
||||
private int numTicks = 0;
|
||||
|
||||
public MovementPillar(BetterBlockPos start, BetterBlockPos end) {
|
||||
public MovementPillar(BlockPos start, BlockPos end) {
|
||||
super(start, end, new BlockPos[]{start.up(2)}, start);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ import baritone.pathing.movement.MovementState;
|
|||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.InputOverrideHandler;
|
||||
import baritone.utils.Utils;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -43,7 +43,7 @@ public class MovementTraverse extends Movement {
|
|||
*/
|
||||
private boolean wasTheBridgeBlockAlwaysThere = true;
|
||||
|
||||
public MovementTraverse(BetterBlockPos from, BetterBlockPos to) {
|
||||
public MovementTraverse(BlockPos from, BlockPos to) {
|
||||
super(from, to, new BlockPos[]{to.up(), to}, to.down());
|
||||
}
|
||||
|
||||
|
|
|
@ -18,14 +18,14 @@
|
|||
package baritone.pathing.path;
|
||||
|
||||
import baritone.pathing.movement.Movement;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CutoffPath implements IPath {
|
||||
|
||||
final List<BetterBlockPos> path;
|
||||
final List<BlockPos> path;
|
||||
|
||||
final List<Movement> movements;
|
||||
|
||||
|
@ -43,7 +43,7 @@ public class CutoffPath implements IPath {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<BetterBlockPos> positions() {
|
||||
public List<BlockPos> positions() {
|
||||
return Collections.unmodifiableList(path);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import baritone.pathing.goals.Goal;
|
|||
import baritone.pathing.movement.Movement;
|
||||
import baritone.utils.Helper;
|
||||
import baritone.utils.Utils;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.Tuple;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -47,7 +47,7 @@ public interface IPath extends Helper {
|
|||
* All positions along the way.
|
||||
* Should begin with the same as getSrc and end with the same as getDest
|
||||
*/
|
||||
List<BetterBlockPos> positions();
|
||||
List<BlockPos> positions();
|
||||
|
||||
/**
|
||||
* Number of positions in this path
|
||||
|
@ -65,7 +65,7 @@ public interface IPath extends Helper {
|
|||
* @return
|
||||
*/
|
||||
default Movement subsequentMovement(BlockPos currentPosition) {
|
||||
List<BetterBlockPos> pos = positions();
|
||||
List<BlockPos> pos = positions();
|
||||
List<Movement> movements = movements();
|
||||
for (int i = 0; i < pos.size(); i++) {
|
||||
if (currentPosition.equals(pos.get(i))) {
|
||||
|
@ -101,15 +101,15 @@ public interface IPath extends Helper {
|
|||
/**
|
||||
* Where does this path start
|
||||
*/
|
||||
default BetterBlockPos getSrc() {
|
||||
default BlockPos getSrc() {
|
||||
return positions().get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Where does this path end
|
||||
*/
|
||||
default BetterBlockPos getDest() {
|
||||
List<BetterBlockPos> pos = positions();
|
||||
default BlockPos getDest() {
|
||||
List<BlockPos> pos = positions();
|
||||
return pos.get(pos.size() - 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ import baritone.pathing.movement.ActionCosts;
|
|||
import baritone.pathing.movement.CalculationContext;
|
||||
import baritone.pathing.movement.Movement;
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -312,7 +312,7 @@ public class ExampleBaritoneControl extends Behavior {
|
|||
return;
|
||||
}
|
||||
if (msg.toLowerCase().equals("costs")) {
|
||||
Movement[] movements = AStarPathFinder.getConnectedPositions(new BetterBlockPos(playerFeet()), new CalculationContext());
|
||||
Movement[] movements = AStarPathFinder.getConnectedPositions(new BlockPos(playerFeet()), new CalculationContext());
|
||||
List<Movement> moves = new ArrayList<>(Arrays.asList(movements));
|
||||
while (moves.contains(null)) {
|
||||
moves.remove(null);
|
||||
|
|
|
@ -24,7 +24,7 @@ import baritone.pathing.goals.GoalTwoBlocks;
|
|||
import baritone.pathing.goals.GoalXZ;
|
||||
import baritone.pathing.path.IPath;
|
||||
import baritone.utils.interfaces.IGoalRenderPos;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
|
@ -63,7 +63,7 @@ public final class PathRenderer implements Helper {
|
|||
GlStateManager.glLineWidth(Baritone.settings().pathRenderLineWidthPixels.get());
|
||||
GlStateManager.disableTexture2D();
|
||||
GlStateManager.depthMask(false);
|
||||
List<BetterBlockPos> positions = path.positions();
|
||||
List<BlockPos> positions = path.positions();
|
||||
int next;
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
fadeStart += startIndex;
|
||||
|
|
|
@ -1,128 +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 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.utils.pathing;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
|
||||
/**
|
||||
* A better BlockPos that has fewer hash collisions (and slightly more performant offsets)
|
||||
*
|
||||
* @author leijurv
|
||||
*/
|
||||
public final class BetterBlockPos extends BlockPos {
|
||||
public final int x;
|
||||
public final int y;
|
||||
public final int z;
|
||||
public final long hashCode;
|
||||
|
||||
public BetterBlockPos(int x, int y, int z) {
|
||||
super(x, y, z);
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
/*
|
||||
* This is the hashcode implementation of Vec3i, the superclass of BlockPos
|
||||
*
|
||||
* public int hashCode() {
|
||||
* return (this.getY() + this.getZ() * 31) * 31 + this.getX();
|
||||
* }
|
||||
*
|
||||
* That is terrible and has tons of collisions and makes the HashMap terribly inefficient.
|
||||
*
|
||||
* That's why we grab out the X, Y, Z and calculate our own hashcode
|
||||
*/
|
||||
long hash = 3241;
|
||||
hash = 3457689L * hash + x;
|
||||
hash = 8734625L * hash + y;
|
||||
hash = 2873465L * hash + z;
|
||||
this.hashCode = hash;
|
||||
}
|
||||
|
||||
public BetterBlockPos(BlockPos pos) {
|
||||
this(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (int) hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null) {
|
||||
return false;
|
||||
}
|
||||
if (o instanceof BetterBlockPos) {
|
||||
BetterBlockPos oth = (BetterBlockPos) o;
|
||||
if (oth.hashCode != hashCode) {
|
||||
return false;
|
||||
}
|
||||
return oth.x == x && oth.y == y && oth.z == z;
|
||||
}
|
||||
// during path execution, like "if (whereShouldIBe.equals(whereAmI)) {"
|
||||
// sometimes we compare a BlockPos to a BetterBlockPos
|
||||
BlockPos oth = (BlockPos) o;
|
||||
return oth.getX() == x && oth.getY() == y && oth.getZ() == z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BetterBlockPos up() {
|
||||
// this is unimaginably faster than blockpos.up
|
||||
// that literally calls
|
||||
// this.up(1)
|
||||
// which calls this.offset(EnumFacing.UP, 1)
|
||||
// which does return n == 0 ? this : new BlockPos(this.getX() + facing.getXOffset() * n, this.getY() + facing.getYOffset() * n, this.getZ() + facing.getZOffset() * n);
|
||||
|
||||
// how many function calls is that? up(), up(int), offset(EnumFacing, int), new BlockPos, getX, getXOffset, getY, getYOffset, getZ, getZOffset
|
||||
// that's ten.
|
||||
// this is one function call.
|
||||
return new BetterBlockPos(x, y + 1, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BetterBlockPos up(int amt) {
|
||||
// see comment in up()
|
||||
return amt == 0 ? this : new BetterBlockPos(x, y + amt, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BetterBlockPos down() {
|
||||
// see comment in up()
|
||||
return new BetterBlockPos(x, y - 1, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BetterBlockPos down(int amt) {
|
||||
// see comment in up()
|
||||
return new BetterBlockPos(x, y - amt, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BetterBlockPos offset(EnumFacing dir) {
|
||||
Vec3i vec = dir.getDirectionVec();
|
||||
return new BetterBlockPos(x + vec.getX(), y + vec.getY(), z + vec.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BetterBlockPos offset(EnumFacing dir, int dist) {
|
||||
Vec3i vec = dir.getDirectionVec();
|
||||
return new BetterBlockPos(x + vec.getX() * dist, y + vec.getY() * dist, z + vec.getZ() * dist);
|
||||
}
|
||||
}
|
|
@ -19,7 +19,7 @@ package baritone.pathing.calc.openset;
|
|||
|
||||
import baritone.pathing.calc.PathNode;
|
||||
import baritone.pathing.goals.Goal;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class OpenSetsTest {
|
|||
// can't use an existing goal
|
||||
// because they use Baritone.settings()
|
||||
// and we can't do that because Minecraft itself isn't initted
|
||||
PathNode pn = new PathNode(new BetterBlockPos(0, 0, 0), new Goal() {
|
||||
PathNode pn = new PathNode(new BlockPos(0, 0, 0), new Goal() {
|
||||
@Override
|
||||
public boolean isInGoal(BlockPos pos) {
|
||||
return false;
|
||||
|
|
|
@ -20,7 +20,7 @@ package baritone.utils.pathing;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
import org.junit.Test;
|
||||
|
||||
public class BetterBlockPosTest {
|
||||
public class BlockPosTest {
|
||||
|
||||
@Test
|
||||
public void benchMulti() {
|
||||
|
@ -38,7 +38,7 @@ public class BetterBlockPosTest {
|
|||
|
||||
public void benchOne() {
|
||||
BlockPos pos = new BlockPos(1, 2, 3);
|
||||
BetterBlockPos pos2 = new BetterBlockPos(1, 2, 3);
|
||||
BlockPos pos2 = new BlockPos(1, 2, 3);
|
||||
try {
|
||||
Thread.sleep(1000); // give GC some time
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -64,7 +64,7 @@ public class BetterBlockPosTest {
|
|||
|
||||
public void benchN() {
|
||||
BlockPos pos = new BlockPos(1, 2, 3);
|
||||
BetterBlockPos pos2 = new BetterBlockPos(1, 2, 3);
|
||||
BlockPos pos2 = new BlockPos(1, 2, 3);
|
||||
try {
|
||||
Thread.sleep(1000); // give GC some time
|
||||
} catch (InterruptedException e) {
|
||||
|
|
Loading…
Reference in New Issue