diagonal descend

This commit is contained in:
Leijurv 2018-12-11 22:26:55 -08:00
parent a2534a8227
commit 44963fa4c7
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
2 changed files with 67 additions and 39 deletions

View File

@ -220,51 +220,59 @@ public enum Moves {
}
},
DIAGONAL_NORTHEAST(+1, 0, -1) {
DIAGONAL_NORTHEAST(+1, 0, -1, false, true) {
@Override
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return new MovementDiagonal(context.getBaritone(), src, EnumFacing.NORTH, EnumFacing.EAST);
MutableMoveResult res = new MutableMoveResult();
apply(context, src.x, src.y, src.z, res);
return new MovementDiagonal(context.getBaritone(), src, EnumFacing.NORTH, EnumFacing.EAST, res.y - src.y);
}
@Override
public double cost(CalculationContext context, int x, int y, int z) {
return MovementDiagonal.cost(context, x, y, z, x + 1, z - 1);
public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) {
MovementDiagonal.cost(context, x, y, z, x + 1, z - 1, result);
}
},
DIAGONAL_NORTHWEST(-1, 0, -1) {
DIAGONAL_NORTHWEST(-1, 0, -1, false, true) {
@Override
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return new MovementDiagonal(context.getBaritone(), src, EnumFacing.NORTH, EnumFacing.WEST);
MutableMoveResult res = new MutableMoveResult();
apply(context, src.x, src.y, src.z, res);
return new MovementDiagonal(context.getBaritone(), src, EnumFacing.NORTH, EnumFacing.WEST, res.y - src.y);
}
@Override
public double cost(CalculationContext context, int x, int y, int z) {
return MovementDiagonal.cost(context, x, y, z, x - 1, z - 1);
public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) {
MovementDiagonal.cost(context, x, y, z, x - 1, z - 1, result);
}
},
DIAGONAL_SOUTHEAST(+1, 0, +1) {
DIAGONAL_SOUTHEAST(+1, 0, +1, false, true) {
@Override
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return new MovementDiagonal(context.getBaritone(), src, EnumFacing.SOUTH, EnumFacing.EAST);
MutableMoveResult res = new MutableMoveResult();
apply(context, src.x, src.y, src.z, res);
return new MovementDiagonal(context.getBaritone(), src, EnumFacing.SOUTH, EnumFacing.EAST, res.y - src.y);
}
@Override
public double cost(CalculationContext context, int x, int y, int z) {
return MovementDiagonal.cost(context, x, y, z, x + 1, z + 1);
public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) {
MovementDiagonal.cost(context, x, y, z, x + 1, z + 1, result);
}
},
DIAGONAL_SOUTHWEST(-1, 0, +1) {
DIAGONAL_SOUTHWEST(-1, 0, +1, false, true) {
@Override
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return new MovementDiagonal(context.getBaritone(), src, EnumFacing.SOUTH, EnumFacing.WEST);
MutableMoveResult res = new MutableMoveResult();
apply(context, src.x, src.y, src.z, res);
return new MovementDiagonal(context.getBaritone(), src, EnumFacing.SOUTH, EnumFacing.WEST, res.y - src.y);
}
@Override
public double cost(CalculationContext context, int x, int y, int z) {
return MovementDiagonal.cost(context, x, y, z, x - 1, z + 1);
public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) {
MovementDiagonal.cost(context, x, y, z, x - 1, z + 1, result);
}
},

View File

@ -26,6 +26,7 @@ import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface;
import baritone.utils.pathing.MutableMoveResult;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
@ -39,13 +40,13 @@ public class MovementDiagonal extends Movement {
private static final double SQRT_2 = Math.sqrt(2);
public MovementDiagonal(IBaritone baritone, BetterBlockPos start, EnumFacing dir1, EnumFacing dir2) {
this(baritone, start, start.offset(dir1), start.offset(dir2), dir2);
public MovementDiagonal(IBaritone baritone, BetterBlockPos start, EnumFacing dir1, EnumFacing dir2, int dy) {
this(baritone, start, start.offset(dir1), start.offset(dir2), dir2, dy);
// 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(IBaritone baritone, BetterBlockPos start, BetterBlockPos dir1, BetterBlockPos dir2, EnumFacing drr2) {
this(baritone, start, dir1.offset(drr2), dir1, dir2);
private MovementDiagonal(IBaritone baritone, BetterBlockPos start, BetterBlockPos dir1, BetterBlockPos dir2, EnumFacing drr2, int dy) {
this(baritone, start, dir1.offset(drr2).up(dy), dir1, dir2);
}
private MovementDiagonal(IBaritone baritone, BetterBlockPos start, BetterBlockPos end, BetterBlockPos dir1, BetterBlockPos dir2) {
@ -54,17 +55,26 @@ public class MovementDiagonal extends Movement {
@Override
protected double calculateCost(CalculationContext context) {
return cost(context, src.x, src.y, src.z, dest.x, dest.z);
MutableMoveResult result = new MutableMoveResult();
cost(context, src.x, src.y, src.z, dest.x, dest.z, result);
if (result.y != dest.y) {
return COST_INF; // doesn't apply to us, this position is incorrect
}
return result.cost;
}
public static double cost(CalculationContext context, int x, int y, int z, int destX, int destZ) {
public static void cost(CalculationContext context, int x, int y, int z, int destX, int destZ, MutableMoveResult res) {
IBlockState destInto = context.get(destX, y, destZ);
if (!MovementHelper.canWalkThrough(context.bsi(), destX, y, destZ, destInto) || !MovementHelper.canWalkThrough(context.bsi(), destX, y + 1, destZ)) {
return COST_INF;
return;
}
IBlockState destWalkOn = context.get(destX, y - 1, destZ);
boolean descend = false;
if (!MovementHelper.canWalkOn(context.bsi(), destX, y - 1, destZ, destWalkOn)) {
return COST_INF;
descend = true;
if (!MovementHelper.canWalkOn(context.bsi(), destX, y - 2, destZ) || !MovementHelper.canWalkThrough(context.bsi(), destX, y - 1, destZ, destWalkOn)) {
return;
}
}
double multiplier = WALK_ONE_BLOCK_COST;
// For either possible soul sand, that affects half of our walking
@ -73,18 +83,18 @@ public class MovementDiagonal extends Movement {
}
Block fromDown = context.get(x, y - 1, z).getBlock();
if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) {
return COST_INF;
return;
}
if (fromDown == Blocks.SOUL_SAND) {
multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2;
}
Block cuttingOver1 = context.get(x, y - 1, destZ).getBlock();
if (cuttingOver1 == Blocks.MAGMA || MovementHelper.isLava(cuttingOver1)) {
return COST_INF;
return;
}
Block cuttingOver2 = context.get(destX, y - 1, z).getBlock();
if (cuttingOver2 == Blocks.MAGMA || MovementHelper.isLava(cuttingOver2)) {
return COST_INF;
return;
}
IBlockState pb0 = context.get(x, y, destZ);
IBlockState pb2 = context.get(destX, y, z);
@ -93,27 +103,27 @@ public class MovementDiagonal extends Movement {
if (optionA != 0 && optionB != 0) {
// check these one at a time -- if pb0 and pb2 were nonzero, we already know that (optionA != 0 && optionB != 0)
// so no need to check pb1 as well, might as well return early here
return COST_INF;
return;
}
IBlockState pb1 = context.get(x, y + 1, destZ);
optionA += MovementHelper.getMiningDurationTicks(context, x, y + 1, destZ, pb1, true);
if (optionA != 0 && optionB != 0) {
// same deal, if pb1 makes optionA nonzero and option B already was nonzero, pb3 can't affect the result
return COST_INF;
return;
}
IBlockState pb3 = context.get(destX, y + 1, z);
if (optionA == 0 && ((MovementHelper.avoidWalkingInto(pb2.getBlock()) && pb2.getBlock() != Blocks.WATER) || (MovementHelper.avoidWalkingInto(pb3.getBlock()) && pb3.getBlock() != Blocks.WATER))) {
// at this point we're done calculating optionA, so we can check if it's actually possible to edge around in that direction
return COST_INF;
return;
}
optionB += MovementHelper.getMiningDurationTicks(context, destX, y + 1, z, pb3, true);
if (optionA != 0 && optionB != 0) {
// and finally, if the cost is nonzero for both ways to approach this diagonal, it's not possible
return COST_INF;
return;
}
if (optionB == 0 && ((MovementHelper.avoidWalkingInto(pb0.getBlock()) && pb0.getBlock() != Blocks.WATER) || (MovementHelper.avoidWalkingInto(pb1.getBlock()) && pb1.getBlock() != Blocks.WATER))) {
// and now that option B is fully calculated, see if we can edge around that way
return COST_INF;
return;
}
boolean water = false;
Block startIn = context.getBlock(x, y, z);
@ -128,16 +138,26 @@ public class MovementDiagonal extends Movement {
multiplier *= SQRT_2 - 0.001; // TODO tune
if (startIn == Blocks.LADDER || startIn == Blocks.VINE) {
// edging around doesn't work if doing so would climb a ladder or vine instead of moving sideways
return COST_INF;
}
return;
}
} else {
// only can sprint if not edging around
if (context.canSprint() && !water) {
// If we aren't edging around anything, and we aren't in water
// We can sprint =D
// Don't check for soul sand, since we can sprint on that too
multiplier *= SPRINT_MULTIPLIER;
}
return multiplier * SQRT_2;
}
res.cost = multiplier * SQRT_2;
if (descend) {
res.cost += Math.max(FALL_N_BLOCKS_COST[1], CENTER_AFTER_FALL_COST);
res.y = y - 1;
} else {
res.y = y;
}
res.x = destX;
res.z = destZ;
}
@Override