Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gotta go fast, fixes #179, fixes #168 #180

Merged
merged 6 commits into from
Sep 23, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
MovementPillar
  • Loading branch information
leijurv committed Sep 23, 2018
commit e33564f1eb5db7ea4d2cdc185e00f8382f88ce05
24 changes: 14 additions & 10 deletions src/main/java/baritone/pathing/movement/MovementHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@
*/
public interface MovementHelper extends ActionCosts, Helper {

static boolean avoidBreaking(BlockPos pos, IBlockState state) {
static boolean avoidBreaking(BetterBlockPos pos, IBlockState state) {
return avoidBreaking(pos.x, pos.y, pos.z, state);
}

static boolean avoidBreaking(int x, int y, int z, IBlockState state) {
Block b = state.getBlock();
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
return b == Blocks.ICE // ice becomes water, and water can mess up the path
|| b instanceof BlockSilverfish // obvious reasons
// call BlockStateInterface.get directly with x,y,z. no need to make 5 new BlockPos for no reason
Expand Down Expand Up @@ -322,16 +323,20 @@ static boolean canPlaceAgainst(BlockPos pos) {

static double getMiningDurationTicks(CalculationContext context, BetterBlockPos position, boolean includeFalling) {
IBlockState state = BlockStateInterface.get(position);
return getMiningDurationTicks(context, position, state, includeFalling);
return getMiningDurationTicks(context, position.x, position.y, position.z, state, includeFalling);
}

static double getMiningDurationTicks(CalculationContext context, BetterBlockPos position, IBlockState state, boolean includeFalling) {
return getMiningDurationTicks(context, position.x, position.y, position.z, state, includeFalling);
}

static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, IBlockState state, boolean includeFalling) {
Block block = state.getBlock();
if (!canWalkThrough(position, state)) {
if (!canWalkThrough(x, y, z, state)) {
if (!context.allowBreak()) {
return COST_INF;
}
if (avoidBreaking(position, state)) {
if (avoidBreaking(x, y, z, state)) {
return COST_INF;
}
double m = Blocks.CRAFTING_TABLE.equals(block) ? 10 : 1; // TODO see if this is still necessary. it's from MineBot when we wanted to penalize breaking its crafting table
Expand All @@ -342,10 +347,9 @@ static double getMiningDurationTicks(CalculationContext context, BetterBlockPos

double result = m / strVsBlock;
if (includeFalling) {
BetterBlockPos up = position.up();
IBlockState above = BlockStateInterface.get(up);
IBlockState above = BlockStateInterface.get(x, y + 1, z);
if (above.getBlock() instanceof BlockFalling) {
result += getMiningDurationTicks(context, up, above, true);
result += getMiningDurationTicks(context, x, y + 1, z, above, true);
}
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ public void reset() {

@Override
protected double calculateCost(CalculationContext context) {
Block fromDown = BlockStateInterface.get(src).getBlock();
return cost(context, src.x, src.y, src.z);
}

public static double cost(CalculationContext context, int x, int y, int z) {
Block fromDown = BlockStateInterface.get(x, y, z).getBlock();
boolean ladder = fromDown instanceof BlockLadder || fromDown instanceof BlockVine;
IBlockState fromDownDown = BlockStateInterface.get(src.down());
IBlockState fromDownDown = BlockStateInterface.get(x, y - 1, z);
if (!ladder) {
if (fromDownDown.getBlock() instanceof BlockLadder || fromDownDown.getBlock() instanceof BlockVine) {
return COST_INF;
Expand All @@ -65,37 +69,35 @@ protected double calculateCost(CalculationContext context) {
return COST_INF;
}
if (fromDown instanceof BlockVine) {
if (getAgainst(src) == null) {
if (!hasAgainst(x, y, z)) {
return COST_INF;
}
}
BetterBlockPos toBreakPos = src.up(2);
IBlockState toBreak = BlockStateInterface.get(toBreakPos);
IBlockState toBreak = BlockStateInterface.get(x, y + 2, z);
Block toBreakBlock = toBreak.getBlock();
if (toBreakBlock instanceof BlockFenceGate) {
return COST_INF;
}
Block srcUp = null;
if (BlockStateInterface.isWater(toBreakBlock) && BlockStateInterface.isWater(fromDown)) {
srcUp = BlockStateInterface.get(dest).getBlock();
srcUp = BlockStateInterface.get(x, y + 1, z).getBlock();
if (BlockStateInterface.isWater(srcUp)) {
return LADDER_UP_ONE_COST;
}
}
double hardness = MovementHelper.getMiningDurationTicks(context, toBreakPos, toBreak, true);
double hardness = MovementHelper.getMiningDurationTicks(context, x, y + 2, z, toBreak, true);
if (hardness >= COST_INF) {
return COST_INF;
}
if (hardness != 0) {
if (toBreakBlock instanceof BlockLadder || toBreakBlock instanceof BlockVine) {
hardness = 0; // we won't actually need to break the ladder / vine because we're going to use it
} else {
BlockPos chkPos = src.up(3);
IBlockState check = BlockStateInterface.get(chkPos);
IBlockState check = BlockStateInterface.get(x, y + 3, z);
if (check.getBlock() instanceof BlockFalling) {
// see MovementAscend's identical check for breaking a falling block above our head
if (srcUp == null) {
srcUp = BlockStateInterface.get(dest).getBlock();
srcUp = BlockStateInterface.get(x, y + 1, z).getBlock();
}
if (!(toBreakBlock instanceof BlockFalling) || !(srcUp instanceof BlockFalling)) {
return COST_INF;
Expand All @@ -120,6 +122,13 @@ protected double calculateCost(CalculationContext context) {
}
}

public static boolean hasAgainst(int x, int y, int z) {
return BlockStateInterface.get(x + 1, y, z).isBlockNormalCube() ||
BlockStateInterface.get(x - 1, y, z).isBlockNormalCube() ||
BlockStateInterface.get(x, y, z + 1).isBlockNormalCube() ||
BlockStateInterface.get(x, y, z - 1).isBlockNormalCube();
}

public static BlockPos getAgainst(BlockPos vine) {
if (BlockStateInterface.get(vine.north()).isBlockNormalCube()) {
return vine.north();
Expand Down