This commit is contained in:
Brady 2018-09-23 15:26:57 -05:00
parent 943794726a
commit 6770985b3a
No known key found for this signature in database
GPG Key ID: 73A788379A197567
7 changed files with 152 additions and 44 deletions

View File

@ -20,9 +20,10 @@ package baritone.pathing.calc;
import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.Movement; 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.ParkourResult;
import baritone.utils.pathing.BetterBlockPos; import baritone.utils.pathing.BetterBlockPos;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.Tuple;
public enum Moves { public enum Moves {
DOWNWARD(0, 0) { DOWNWARD(0, 0) {
@ -158,8 +159,8 @@ public enum Moves {
@Override @Override
public MoveResult apply(CalculationContext context, int x, int y, int z) { public MoveResult apply(CalculationContext context, int x, int y, int z) {
Tuple<Integer, Double> res = MovementDescend.cost(context, x, y, z, x + 1, z); DescendResult res = MovementDescend.cost(context, x, y, z, x + 1, z);
return new MoveResult(x + 1, res.getFirst(), z, res.getSecond()); return new MoveResult(x + 1, res.y, z, res.cost);
} }
}, },
@ -176,8 +177,8 @@ public enum Moves {
@Override @Override
public MoveResult apply(CalculationContext context, int x, int y, int z) { public MoveResult apply(CalculationContext context, int x, int y, int z) {
Tuple<Integer, Double> res = MovementDescend.cost(context, x, y, z, x - 1, z); DescendResult res = MovementDescend.cost(context, x, y, z, x - 1, z);
return new MoveResult(x - 1, res.getFirst(), z, res.getSecond()); return new MoveResult(x - 1, res.y, z, res.cost);
} }
}, },
@ -194,8 +195,8 @@ public enum Moves {
@Override @Override
public MoveResult apply(CalculationContext context, int x, int y, int z) { public MoveResult apply(CalculationContext context, int x, int y, int z) {
Tuple<Integer, Double> res = MovementDescend.cost(context, x, y, z, x, z - 1); DescendResult res = MovementDescend.cost(context, x, y, z, x, z - 1);
return new MoveResult(x, res.getFirst(), z - 1, res.getSecond()); return new MoveResult(x, res.y, z - 1, res.cost);
} }
}, },
@ -212,8 +213,8 @@ public enum Moves {
@Override @Override
public MoveResult apply(CalculationContext context, int x, int y, int z) { public MoveResult apply(CalculationContext context, int x, int y, int z) {
Tuple<Integer, Double> res = MovementDescend.cost(context, x, y, z, x, z + 1); DescendResult res = MovementDescend.cost(context, x, y, z, x, z + 1);
return new MoveResult(x, res.getFirst(), z + 1, res.getSecond()); return new MoveResult(x, res.y, z + 1, res.cost);
} }
}, },
@ -273,8 +274,8 @@ public enum Moves {
@Override @Override
public MoveResult apply(CalculationContext context, int x, int y, int z) { public MoveResult apply(CalculationContext context, int x, int y, int z) {
Tuple<Tuple<Integer, Integer>, Double> res = MovementParkour.cost(context, x, y, z, EnumFacing.NORTH); ParkourResult res = MovementParkour.cost(context, x, y, z, EnumFacing.NORTH);
return new MoveResult(res.getFirst().getFirst(), y, res.getFirst().getSecond(), res.getSecond()); return new MoveResult(res.x, y, res.z, res.cost);
} }
}, },
@ -286,8 +287,8 @@ public enum Moves {
@Override @Override
public MoveResult apply(CalculationContext context, int x, int y, int z) { public MoveResult apply(CalculationContext context, int x, int y, int z) {
Tuple<Tuple<Integer, Integer>, Double> res = MovementParkour.cost(context, x, y, z, EnumFacing.SOUTH); ParkourResult res = MovementParkour.cost(context, x, y, z, EnumFacing.SOUTH);
return new MoveResult(res.getFirst().getFirst(), y, res.getFirst().getSecond(), res.getSecond()); return new MoveResult(res.x, y, res.z, res.cost);
} }
}, },
@ -299,8 +300,8 @@ public enum Moves {
@Override @Override
public MoveResult apply(CalculationContext context, int x, int y, int z) { public MoveResult apply(CalculationContext context, int x, int y, int z) {
Tuple<Tuple<Integer, Integer>, Double> res = MovementParkour.cost(context, x, y, z, EnumFacing.EAST); ParkourResult res = MovementParkour.cost(context, x, y, z, EnumFacing.EAST);
return new MoveResult(res.getFirst().getFirst(), y, res.getFirst().getSecond(), res.getSecond()); return new MoveResult(res.x, y, res.z, res.cost);
} }
}, },
@ -312,14 +313,13 @@ public enum Moves {
@Override @Override
public MoveResult apply(CalculationContext context, int x, int y, int z) { public MoveResult apply(CalculationContext context, int x, int y, int z) {
Tuple<Tuple<Integer, Integer>, Double> res = MovementParkour.cost(context, x, y, z, EnumFacing.WEST); ParkourResult res = MovementParkour.cost(context, x, y, z, EnumFacing.WEST);
return new MoveResult(res.getFirst().getFirst(), y, res.getFirst().getSecond(), res.getSecond()); return new MoveResult(res.x, y, res.z, res.cost);
} }
}; };
protected abstract Movement apply0(BetterBlockPos src); protected abstract Movement apply0(BetterBlockPos src);
public abstract MoveResult apply(CalculationContext context, int x, int y, int z); public abstract MoveResult apply(CalculationContext context, int x, int y, int z);
public final boolean dynamicXZ; public final boolean dynamicXZ;

View File

@ -23,6 +23,7 @@ import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState; import baritone.pathing.movement.MovementState;
import baritone.pathing.movement.MovementState.MovementStatus; import baritone.pathing.movement.MovementState.MovementStatus;
import baritone.pathing.movement.movements.result.DescendResult;
import baritone.utils.BlockStateInterface; import baritone.utils.BlockStateInterface;
import baritone.utils.InputOverrideHandler; import baritone.utils.InputOverrideHandler;
import baritone.utils.pathing.BetterBlockPos; import baritone.utils.pathing.BetterBlockPos;
@ -30,12 +31,11 @@ import net.minecraft.block.Block;
import net.minecraft.block.BlockFalling; import net.minecraft.block.BlockFalling;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
public class MovementDescend extends Movement { import static baritone.pathing.movement.movements.result.DescendResult.IMPOSSIBLE;
private static final Tuple<Integer, Double> IMPOSSIBLE = new Tuple<>(0, COST_INF); public class MovementDescend extends Movement {
private int numTicks = 0; private int numTicks = 0;
@ -51,14 +51,14 @@ public class MovementDescend extends Movement {
@Override @Override
protected double calculateCost(CalculationContext context) { protected double calculateCost(CalculationContext context) {
Tuple<Integer, Double> result = cost(context, src.x, src.y, src.z, dest.x, dest.z); DescendResult result = cost(context, src.x, src.y, src.z, dest.x, dest.z);
if (result.getFirst() != dest.y) { if (result.y != dest.y) {
return COST_INF; // doesn't apply to us, this position is a fall not a descend return COST_INF; // doesn't apply to us, this position is a fall not a descend
} }
return result.getSecond(); return result.cost;
} }
public static Tuple<Integer, Double> cost(CalculationContext context, int x, int y, int z, int destX, int destZ) { public static DescendResult cost(CalculationContext context, int x, int y, int z, int destX, int destZ) {
Block fromDown = BlockStateInterface.get(x, y - 1, z).getBlock(); Block fromDown = BlockStateInterface.get(x, y - 1, z).getBlock();
if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) { if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) {
return IMPOSSIBLE; return IMPOSSIBLE;
@ -105,10 +105,10 @@ public class MovementDescend extends Movement {
walk = WALK_ONE_OVER_SOUL_SAND_COST; walk = WALK_ONE_OVER_SOUL_SAND_COST;
} }
totalCost += walk + Math.max(FALL_N_BLOCKS_COST[1], CENTER_AFTER_FALL_COST); totalCost += walk + Math.max(FALL_N_BLOCKS_COST[1], CENTER_AFTER_FALL_COST);
return new Tuple<>(y - 1, totalCost); return new DescendResult(y - 1, totalCost);
} }
public static Tuple<Integer, Double> dynamicFallCost(CalculationContext context, int x, int y, int z, int destX, int destZ, double frontBreak, IBlockState below) { public static DescendResult dynamicFallCost(CalculationContext context, int x, int y, int z, int destX, int destZ, double frontBreak, IBlockState below) {
if (frontBreak != 0 && BlockStateInterface.get(destX, y + 2, destZ).getBlock() instanceof BlockFalling) { if (frontBreak != 0 && BlockStateInterface.get(destX, y + 2, destZ).getBlock() instanceof BlockFalling) {
// if frontBreak is 0 we can actually get through this without updating the falling block and making it actually fall // if frontBreak is 0 we can actually get through this without updating the falling block and making it actually fall
// but if frontBreak is nonzero, we're breaking blocks in front, so don't let anything fall through this column, // but if frontBreak is nonzero, we're breaking blocks in front, so don't let anything fall through this column,
@ -132,7 +132,7 @@ public class MovementDescend extends Movement {
return IMPOSSIBLE; // TODO fix return IMPOSSIBLE; // TODO fix
} }
// found a fall into water // found a fall into water
return new Tuple<>(newY, tentativeCost); // TODO incorporate water swim up cost? return new DescendResult(newY, tentativeCost); // TODO incorporate water swim up cost?
} }
if (ontoBlock.getBlock() == Blocks.FLOWING_WATER) { if (ontoBlock.getBlock() == Blocks.FLOWING_WATER) {
return IMPOSSIBLE; return IMPOSSIBLE;
@ -147,11 +147,11 @@ public class MovementDescend extends Movement {
return IMPOSSIBLE; // falling onto a half slab is really glitchy, and can cause more fall damage than we'd expect return IMPOSSIBLE; // falling onto a half slab is really glitchy, and can cause more fall damage than we'd expect
} }
if (context.hasWaterBucket() && fallHeight <= context.maxFallHeightBucket() + 1) { if (context.hasWaterBucket() && fallHeight <= context.maxFallHeightBucket() + 1) {
return new Tuple<>(newY + 1, tentativeCost + context.placeBlockCost()); // this is the block we're falling onto, so dest is +1 return new DescendResult(newY + 1, tentativeCost + context.placeBlockCost()); // this is the block we're falling onto, so dest is +1
} }
if (fallHeight <= context.maxFallHeightNoWater() + 1) { if (fallHeight <= context.maxFallHeightNoWater() + 1) {
// fallHeight = 4 means onto.up() is 3 blocks down, which is the max // fallHeight = 4 means onto.up() is 3 blocks down, which is the max
return new Tuple<>(newY + 1, tentativeCost); return new DescendResult(newY + 1, tentativeCost);
} else { } else {
return IMPOSSIBLE; return IMPOSSIBLE;
} }

View File

@ -24,12 +24,12 @@ import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState; import baritone.pathing.movement.MovementState;
import baritone.pathing.movement.MovementState.MovementStatus; import baritone.pathing.movement.MovementState.MovementStatus;
import baritone.pathing.movement.MovementState.MovementTarget; import baritone.pathing.movement.MovementState.MovementTarget;
import baritone.pathing.movement.movements.result.DescendResult;
import baritone.utils.*; import baritone.utils.*;
import baritone.utils.pathing.BetterBlockPos; import baritone.utils.pathing.BetterBlockPos;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Items; import net.minecraft.init.Items;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@ -45,11 +45,11 @@ public class MovementFall extends Movement {
@Override @Override
protected double calculateCost(CalculationContext context) { protected double calculateCost(CalculationContext context) {
Tuple<Integer, Double> result = MovementDescend.cost(context, src.x, src.y, src.z, dest.x, dest.z); DescendResult result = MovementDescend.cost(context, src.x, src.y, src.z, dest.x, dest.z);
if (result.getFirst() != dest.y) { if (result.y != dest.y) {
return COST_INF; // doesn't apply to us, this position is a descend not a fall return COST_INF; // doesn't apply to us, this position is a descend not a fall
} }
return result.getSecond(); return result.cost;
} }
@Override @Override

View File

@ -23,6 +23,7 @@ import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.Movement; import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState; import baritone.pathing.movement.MovementState;
import baritone.pathing.movement.movements.result.ParkourResult;
import baritone.utils.BlockStateInterface; import baritone.utils.BlockStateInterface;
import baritone.utils.InputOverrideHandler; import baritone.utils.InputOverrideHandler;
import baritone.utils.Utils; import baritone.utils.Utils;
@ -31,16 +32,17 @@ import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import java.util.Objects; import java.util.Objects;
import static baritone.pathing.movement.movements.result.ParkourResult.IMPOSSIBLE;
public class MovementParkour extends Movement { public class MovementParkour extends Movement {
private static final EnumFacing[] HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP = {EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.WEST, EnumFacing.DOWN}; private static final EnumFacing[] HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP = {EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.WEST, EnumFacing.DOWN};
private static final BetterBlockPos[] EMPTY = new BetterBlockPos[]{}; private static final BetterBlockPos[] EMPTY = new BetterBlockPos[]{};
private static final Tuple<Tuple<Integer, Integer>, Double> IMPOSSIBLE = new Tuple<>(new Tuple<>(0, 0), COST_INF);
private final EnumFacing direction; private final EnumFacing direction;
private final int dist; private final int dist;
@ -52,12 +54,12 @@ public class MovementParkour extends Movement {
} }
public static MovementParkour cost(CalculationContext context, BetterBlockPos src, EnumFacing direction) { public static MovementParkour cost(CalculationContext context, BetterBlockPos src, EnumFacing direction) {
Tuple<Tuple<Integer, Integer>, Double> res = cost(context, src.x, src.y, src.z, direction); ParkourResult res = cost(context, src.x, src.y, src.z, direction);
int dist = Math.abs(res.getFirst().getFirst() - src.x) + Math.abs(res.getFirst().getSecond() - src.z); int dist = Math.abs(res.x - src.x) + Math.abs(res.z - src.z);
return new MovementParkour(src, dist, direction); return new MovementParkour(src, dist, direction);
} }
public static Tuple<Tuple<Integer, Integer>, Double> cost(CalculationContext context, int x, int y, int z, EnumFacing dir) { public static ParkourResult cost(CalculationContext context, int x, int y, int z, EnumFacing dir) {
if (!Baritone.settings().allowParkour.get()) { if (!Baritone.settings().allowParkour.get()) {
return IMPOSSIBLE; return IMPOSSIBLE;
} }
@ -95,7 +97,7 @@ public class MovementParkour extends Movement {
} }
} }
if (MovementHelper.canWalkOn(x + xDiff * i, y - 1, z + zDiff * i)) { if (MovementHelper.canWalkOn(x + xDiff * i, y - 1, z + zDiff * i)) {
return new Tuple<>(new Tuple<>(x + xDiff * i, z + zDiff * i), costFromJumpDistance(i)); return new ParkourResult(x + xDiff * i, z + zDiff * i, costFromJumpDistance(i));
} }
} }
if (!context.canSprint()) { if (!context.canSprint()) {
@ -120,7 +122,7 @@ public class MovementParkour extends Movement {
continue; continue;
} }
if (MovementHelper.canPlaceAgainst(againstX, y - 1, againstZ)) { if (MovementHelper.canPlaceAgainst(againstX, y - 1, againstZ)) {
return new Tuple<>(new Tuple<>(destX, destZ), costFromJumpDistance(i) + context.placeBlockCost()); return new ParkourResult(destX, destZ, costFromJumpDistance(i) + context.placeBlockCost());
} }
} }
return IMPOSSIBLE; return IMPOSSIBLE;
@ -142,11 +144,11 @@ public class MovementParkour extends Movement {
@Override @Override
protected double calculateCost(CalculationContext context) { protected double calculateCost(CalculationContext context) {
Tuple<Tuple<Integer, Integer>, Double> res = cost(context, src.x, src.y, src.z, direction); ParkourResult res = cost(context, src.x, src.y, src.z, direction);
if (res.getFirst().getFirst() != dest.x || res.getFirst().getSecond() != dest.z) { if (res.x != dest.x || res.z != dest.z) {
return COST_INF; return COST_INF;
} }
return res.getSecond(); return res.cost;
} }
@Override @Override

View File

@ -0,0 +1,36 @@
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.pathing.movement.movements.result;
import static baritone.pathing.movement.ActionCosts.COST_INF;
/**
* @author Brady
* @since 9/23/2018
*/
public final class DescendResult extends Result {
public static final DescendResult IMPOSSIBLE = new DescendResult(0, COST_INF);
public final int y;
public DescendResult(int y, double cost) {
super(cost);
this.y = y;
}
}

View File

@ -0,0 +1,37 @@
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.pathing.movement.movements.result;
import static baritone.pathing.movement.ActionCosts.COST_INF;
/**
* @author Brady
* @since 9/23/2018
*/
public final class ParkourResult extends Result {
public static final ParkourResult IMPOSSIBLE = new ParkourResult(0, 0, COST_INF);
public final int x, z;
public ParkourResult(int x, int z, double cost) {
super(cost);
this.x = x;
this.z = z;
}
}

View File

@ -0,0 +1,33 @@
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.pathing.movement.movements.result;
/**
* Generic class for special movement results. Only contains a single "cost" field.
*
* @author Brady
* @since 9/23/2018
*/
public class Result {
public final double cost;
public Result(double cost) {
this.cost = cost;
}
}