refactor
This commit is contained in:
parent
6770985b3a
commit
182c1e6ff5
@ -22,6 +22,8 @@ import baritone.pathing.calc.openset.BinaryHeapOpenSet;
|
|||||||
import baritone.pathing.goals.Goal;
|
import baritone.pathing.goals.Goal;
|
||||||
import baritone.pathing.movement.ActionCosts;
|
import baritone.pathing.movement.ActionCosts;
|
||||||
import baritone.pathing.movement.CalculationContext;
|
import baritone.pathing.movement.CalculationContext;
|
||||||
|
import baritone.pathing.movement.Moves;
|
||||||
|
import baritone.pathing.movement.movements.result.MoveResult;
|
||||||
import baritone.pathing.path.IPath;
|
import baritone.pathing.path.IPath;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import baritone.utils.Helper;
|
import baritone.utils.Helper;
|
||||||
@ -97,7 +99,9 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
|||||||
if (newX >> 4 != currentNode.x >> 4 || newZ >> 4 != currentNode.z >> 4) {
|
if (newX >> 4 != currentNode.x >> 4 || newZ >> 4 != currentNode.z >> 4) {
|
||||||
// only need to check if the destination is a loaded chunk if it's in a different chunk than the start of the movement
|
// 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 (!BlockStateInterface.isLoaded(newX, newZ)) {
|
if (!BlockStateInterface.isLoaded(newX, newZ)) {
|
||||||
|
if (!moves.dynamicXZ) { // only increment the counter if the movement would have gone out of bounds guaranteed
|
||||||
numEmptyChunk++;
|
numEmptyChunk++;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ package baritone.pathing.calc;
|
|||||||
|
|
||||||
import baritone.pathing.goals.Goal;
|
import baritone.pathing.goals.Goal;
|
||||||
import baritone.pathing.movement.Movement;
|
import baritone.pathing.movement.Movement;
|
||||||
|
import baritone.pathing.movement.Moves;
|
||||||
import baritone.pathing.path.IPath;
|
import baritone.pathing.path.IPath;
|
||||||
import baritone.utils.pathing.BetterBlockPos;
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
@ -15,20 +15,24 @@
|
|||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package baritone.pathing.calc;
|
package baritone.pathing.movement;
|
||||||
|
|
||||||
import baritone.pathing.movement.CalculationContext;
|
|
||||||
import baritone.pathing.movement.Movement;
|
|
||||||
import baritone.pathing.movement.movements.*;
|
import baritone.pathing.movement.movements.*;
|
||||||
import baritone.pathing.movement.movements.result.DescendResult;
|
import baritone.pathing.movement.movements.result.DescendResult;
|
||||||
|
import baritone.pathing.movement.movements.result.MoveResult;
|
||||||
import baritone.pathing.movement.movements.result.ParkourResult;
|
import baritone.pathing.movement.movements.result.ParkourResult;
|
||||||
import baritone.utils.pathing.BetterBlockPos;
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An enum of all possible movements attached to all possible directions they could be taken in
|
||||||
|
*
|
||||||
|
* @author leijurv
|
||||||
|
*/
|
||||||
public enum Moves {
|
public enum Moves {
|
||||||
DOWNWARD(0, 0) {
|
DOWNWARD(0, 0) {
|
||||||
@Override
|
@Override
|
||||||
protected Movement apply0(BetterBlockPos src) { // TODO specific return types
|
public Movement apply0(BetterBlockPos src) {
|
||||||
return new MovementDownward(src, src.down());
|
return new MovementDownward(src, src.down());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +44,7 @@ public enum Moves {
|
|||||||
|
|
||||||
PILLAR(0, 0) {
|
PILLAR(0, 0) {
|
||||||
@Override
|
@Override
|
||||||
protected Movement apply0(BetterBlockPos src) {
|
public Movement apply0(BetterBlockPos src) {
|
||||||
return new MovementPillar(src, src.up());
|
return new MovementPillar(src, src.up());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +56,7 @@ public enum Moves {
|
|||||||
|
|
||||||
TRAVERSE_NORTH(0, -1) {
|
TRAVERSE_NORTH(0, -1) {
|
||||||
@Override
|
@Override
|
||||||
protected Movement apply0(BetterBlockPos src) {
|
public Movement apply0(BetterBlockPos src) {
|
||||||
return new MovementTraverse(src, src.north());
|
return new MovementTraverse(src, src.north());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +68,7 @@ public enum Moves {
|
|||||||
|
|
||||||
TRAVERSE_SOUTH(0, +1) {
|
TRAVERSE_SOUTH(0, +1) {
|
||||||
@Override
|
@Override
|
||||||
protected Movement apply0(BetterBlockPos src) {
|
public Movement apply0(BetterBlockPos src) {
|
||||||
return new MovementTraverse(src, src.south());
|
return new MovementTraverse(src, src.south());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +80,7 @@ public enum Moves {
|
|||||||
|
|
||||||
TRAVERSE_EAST(+1, 0) {
|
TRAVERSE_EAST(+1, 0) {
|
||||||
@Override
|
@Override
|
||||||
protected Movement apply0(BetterBlockPos src) {
|
public Movement apply0(BetterBlockPos src) {
|
||||||
return new MovementTraverse(src, src.east());
|
return new MovementTraverse(src, src.east());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +92,7 @@ public enum Moves {
|
|||||||
|
|
||||||
TRAVERSE_WEST(-1, 0) {
|
TRAVERSE_WEST(-1, 0) {
|
||||||
@Override
|
@Override
|
||||||
protected Movement apply0(BetterBlockPos src) {
|
public Movement apply0(BetterBlockPos src) {
|
||||||
return new MovementTraverse(src, src.west());
|
return new MovementTraverse(src, src.west());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +104,7 @@ public enum Moves {
|
|||||||
|
|
||||||
ASCEND_NORTH(0, -1) {
|
ASCEND_NORTH(0, -1) {
|
||||||
@Override
|
@Override
|
||||||
protected Movement apply0(BetterBlockPos src) {
|
public Movement apply0(BetterBlockPos src) {
|
||||||
return new MovementAscend(src, new BetterBlockPos(src.x, src.y + 1, src.z - 1));
|
return new MovementAscend(src, new BetterBlockPos(src.x, src.y + 1, src.z - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +116,7 @@ public enum Moves {
|
|||||||
|
|
||||||
ASCEND_SOUTH(0, +1) {
|
ASCEND_SOUTH(0, +1) {
|
||||||
@Override
|
@Override
|
||||||
protected Movement apply0(BetterBlockPos src) {
|
public Movement apply0(BetterBlockPos src) {
|
||||||
return new MovementAscend(src, new BetterBlockPos(src.x, src.y + 1, src.z + 1));
|
return new MovementAscend(src, new BetterBlockPos(src.x, src.y + 1, src.z + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +128,7 @@ public enum Moves {
|
|||||||
|
|
||||||
ASCEND_EAST(+1, 0) {
|
ASCEND_EAST(+1, 0) {
|
||||||
@Override
|
@Override
|
||||||
protected Movement apply0(BetterBlockPos src) {
|
public Movement apply0(BetterBlockPos src) {
|
||||||
return new MovementAscend(src, new BetterBlockPos(src.x + 1, src.y + 1, src.z));
|
return new MovementAscend(src, new BetterBlockPos(src.x + 1, src.y + 1, src.z));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +140,7 @@ public enum Moves {
|
|||||||
|
|
||||||
ASCEND_WEST(-1, 0) {
|
ASCEND_WEST(-1, 0) {
|
||||||
@Override
|
@Override
|
||||||
protected Movement apply0(BetterBlockPos src) {
|
public Movement apply0(BetterBlockPos src) {
|
||||||
return new MovementAscend(src, new BetterBlockPos(src.x - 1, src.y + 1, src.z));
|
return new MovementAscend(src, new BetterBlockPos(src.x - 1, src.y + 1, src.z));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +152,7 @@ public enum Moves {
|
|||||||
|
|
||||||
DESCEND_EAST(+1, 0) {
|
DESCEND_EAST(+1, 0) {
|
||||||
@Override
|
@Override
|
||||||
protected Movement apply0(BetterBlockPos src) {
|
public Movement apply0(BetterBlockPos src) {
|
||||||
MoveResult res = apply(new CalculationContext(), src.x, src.y, src.z);
|
MoveResult res = apply(new CalculationContext(), src.x, src.y, src.z);
|
||||||
if (res.destY == src.y - 1) {
|
if (res.destY == src.y - 1) {
|
||||||
return new MovementDescend(src, new BetterBlockPos(res.destX, res.destY, res.destZ));
|
return new MovementDescend(src, new BetterBlockPos(res.destX, res.destY, res.destZ));
|
||||||
@ -166,7 +170,7 @@ public enum Moves {
|
|||||||
|
|
||||||
DESCEND_WEST(-1, 0) {
|
DESCEND_WEST(-1, 0) {
|
||||||
@Override
|
@Override
|
||||||
protected Movement apply0(BetterBlockPos src) {
|
public Movement apply0(BetterBlockPos src) {
|
||||||
MoveResult res = apply(new CalculationContext(), src.x, src.y, src.z);
|
MoveResult res = apply(new CalculationContext(), src.x, src.y, src.z);
|
||||||
if (res.destY == src.y - 1) {
|
if (res.destY == src.y - 1) {
|
||||||
return new MovementDescend(src, new BetterBlockPos(res.destX, res.destY, res.destZ));
|
return new MovementDescend(src, new BetterBlockPos(res.destX, res.destY, res.destZ));
|
||||||
@ -184,7 +188,7 @@ public enum Moves {
|
|||||||
|
|
||||||
DESCEND_NORTH(0, -1) {
|
DESCEND_NORTH(0, -1) {
|
||||||
@Override
|
@Override
|
||||||
protected Movement apply0(BetterBlockPos src) {
|
public Movement apply0(BetterBlockPos src) {
|
||||||
MoveResult res = apply(new CalculationContext(), src.x, src.y, src.z);
|
MoveResult res = apply(new CalculationContext(), src.x, src.y, src.z);
|
||||||
if (res.destY == src.y - 1) {
|
if (res.destY == src.y - 1) {
|
||||||
return new MovementDescend(src, new BetterBlockPos(res.destX, res.destY, res.destZ));
|
return new MovementDescend(src, new BetterBlockPos(res.destX, res.destY, res.destZ));
|
||||||
@ -202,7 +206,7 @@ public enum Moves {
|
|||||||
|
|
||||||
DESCEND_SOUTH(0, +1) {
|
DESCEND_SOUTH(0, +1) {
|
||||||
@Override
|
@Override
|
||||||
protected Movement apply0(BetterBlockPos src) {
|
public Movement apply0(BetterBlockPos src) {
|
||||||
MoveResult res = apply(new CalculationContext(), src.x, src.y, src.z);
|
MoveResult res = apply(new CalculationContext(), src.x, src.y, src.z);
|
||||||
if (res.destY == src.y - 1) {
|
if (res.destY == src.y - 1) {
|
||||||
return new MovementDescend(src, new BetterBlockPos(res.destX, res.destY, res.destZ));
|
return new MovementDescend(src, new BetterBlockPos(res.destX, res.destY, res.destZ));
|
||||||
@ -220,7 +224,7 @@ public enum Moves {
|
|||||||
|
|
||||||
DIAGONAL_NORTHEAST(+1, -1) {
|
DIAGONAL_NORTHEAST(+1, -1) {
|
||||||
@Override
|
@Override
|
||||||
protected Movement apply0(BetterBlockPos src) {
|
public Movement apply0(BetterBlockPos src) {
|
||||||
return new MovementDiagonal(src, EnumFacing.NORTH, EnumFacing.EAST);
|
return new MovementDiagonal(src, EnumFacing.NORTH, EnumFacing.EAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +236,7 @@ public enum Moves {
|
|||||||
|
|
||||||
DIAGONAL_NORTHWEST(-1, -1) {
|
DIAGONAL_NORTHWEST(-1, -1) {
|
||||||
@Override
|
@Override
|
||||||
protected Movement apply0(BetterBlockPos src) {
|
public Movement apply0(BetterBlockPos src) {
|
||||||
return new MovementDiagonal(src, EnumFacing.NORTH, EnumFacing.WEST);
|
return new MovementDiagonal(src, EnumFacing.NORTH, EnumFacing.WEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,7 +248,7 @@ public enum Moves {
|
|||||||
|
|
||||||
DIAGONAL_SOUTHEAST(+1, +1) {
|
DIAGONAL_SOUTHEAST(+1, +1) {
|
||||||
@Override
|
@Override
|
||||||
protected Movement apply0(BetterBlockPos src) {
|
public Movement apply0(BetterBlockPos src) {
|
||||||
return new MovementDiagonal(src, EnumFacing.SOUTH, EnumFacing.EAST);
|
return new MovementDiagonal(src, EnumFacing.SOUTH, EnumFacing.EAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,7 +260,7 @@ public enum Moves {
|
|||||||
|
|
||||||
DIAGONAL_SOUTHWEST(-1, +1) {
|
DIAGONAL_SOUTHWEST(-1, +1) {
|
||||||
@Override
|
@Override
|
||||||
protected Movement apply0(BetterBlockPos src) {
|
public Movement apply0(BetterBlockPos src) {
|
||||||
return new MovementDiagonal(src, EnumFacing.SOUTH, EnumFacing.WEST);
|
return new MovementDiagonal(src, EnumFacing.SOUTH, EnumFacing.WEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,7 +272,7 @@ public enum Moves {
|
|||||||
|
|
||||||
PARKOUR_NORTH(0, -4, true) {
|
PARKOUR_NORTH(0, -4, true) {
|
||||||
@Override
|
@Override
|
||||||
protected Movement apply0(BetterBlockPos src) {
|
public Movement apply0(BetterBlockPos src) {
|
||||||
return MovementParkour.cost(new CalculationContext(), src, EnumFacing.NORTH);
|
return MovementParkour.cost(new CalculationContext(), src, EnumFacing.NORTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,7 +285,7 @@ public enum Moves {
|
|||||||
|
|
||||||
PARKOUR_SOUTH(0, +4, true) {
|
PARKOUR_SOUTH(0, +4, true) {
|
||||||
@Override
|
@Override
|
||||||
protected Movement apply0(BetterBlockPos src) {
|
public Movement apply0(BetterBlockPos src) {
|
||||||
return MovementParkour.cost(new CalculationContext(), src, EnumFacing.SOUTH);
|
return MovementParkour.cost(new CalculationContext(), src, EnumFacing.SOUTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,7 +298,7 @@ public enum Moves {
|
|||||||
|
|
||||||
PARKOUR_EAST(+4, 0, true) {
|
PARKOUR_EAST(+4, 0, true) {
|
||||||
@Override
|
@Override
|
||||||
protected Movement apply0(BetterBlockPos src) {
|
public Movement apply0(BetterBlockPos src) {
|
||||||
return MovementParkour.cost(new CalculationContext(), src, EnumFacing.EAST);
|
return MovementParkour.cost(new CalculationContext(), src, EnumFacing.EAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,7 +311,7 @@ public enum Moves {
|
|||||||
|
|
||||||
PARKOUR_WEST(-4, 0, true) {
|
PARKOUR_WEST(-4, 0, true) {
|
||||||
@Override
|
@Override
|
||||||
protected Movement apply0(BetterBlockPos src) {
|
public Movement apply0(BetterBlockPos src) {
|
||||||
return MovementParkour.cost(new CalculationContext(), src, EnumFacing.WEST);
|
return MovementParkour.cost(new CalculationContext(), src, EnumFacing.WEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,10 +322,6 @@ public enum Moves {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
protected abstract Movement apply0(BetterBlockPos src);
|
|
||||||
|
|
||||||
public abstract MoveResult apply(CalculationContext context, int x, int y, int z);
|
|
||||||
|
|
||||||
public final boolean dynamicXZ;
|
public final boolean dynamicXZ;
|
||||||
|
|
||||||
public final int xOffset;
|
public final int xOffset;
|
||||||
@ -336,4 +336,8 @@ public enum Moves {
|
|||||||
Moves(int x, int z) {
|
Moves(int x, int z) {
|
||||||
this(x, z, false);
|
this(x, z, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract Movement apply0(BetterBlockPos src);
|
||||||
|
|
||||||
|
public abstract MoveResult apply(CalculationContext context, int x, int y, int z);
|
||||||
}
|
}
|
@ -15,7 +15,7 @@
|
|||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package baritone.pathing.calc;
|
package baritone.pathing.movement.movements.result;
|
||||||
|
|
||||||
public final class MoveResult {
|
public final class MoveResult {
|
||||||
public final int destX;
|
public final int destX;
|
Loading…
Reference in New Issue
Block a user