Merge branch 'slabs-stairs'

This commit is contained in:
Leijurv 2018-09-04 10:07:08 -07:00
commit b8ee7f5b96
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
16 changed files with 116 additions and 57 deletions

View File

@ -5,7 +5,8 @@
- **Block placing** Baritone considers placing blocks as part of its path. This includes sneak-back-placing, pillaring, etc. It has a configurable penalty of placing a block (set to 1 second by default), to conserve its resources. The list of acceptable throwaway blocks is also configurable, and is cobble, dirt, or netherrack by default. <a href="https://www.youtube.com/watch?v=F6FbI1L9UmU">Example</a>
- **Falling** Baritone will fall up to 3 blocks onto solid ground (configurable, if you have Feather Falling and/or don't mind taking a little damage). If you have a water bucket on your hotbar, it will fall up to 23 blocks and place the bucket beneath it. It will fall an unlimited distance into existing still water.
- **Vines and ladders** Baritone understands how to climb and descend vines and ladders. There is experimental support for more advanced maneuvers, like strafing to a different ladder / vine column in midair (off by default, setting named `allowVines`).
- **Fence gates and doors**
- **Opening fence gates and doors**
- **Slabs and stairs**
- **Falling blocks** Baritone understands the costs of breaking blocks with falling blocks on top, and includes all of their break costs. Additionally, since it avoids breaking any blocks touching a liquid, it won't break the bottom of a gravel stack below a lava lake (anymore).
- **Avoiding dangerous blocks** Obviously, it knows not to walk through fire or on magma, not to corner over lava (that deals some damage), not to break any blocks touching a liquid (it might drown), etc.
@ -35,9 +36,7 @@ And finally `GoalComposite`. `GoalComposite` is a list of other goals, any one o
# Future features
Things it doesn't have yet
- Trapdoors
- Slabs (double, top, and bottom)
- Sprint jumping in a 1x2 corridor
- Stairs
See <a href="https://github.com/cabaletta/baritone/issues">issues</a> for more.

View File

@ -77,6 +77,12 @@ public class Settings {
*/
public Setting<Boolean> allowVines = new Setting<>(false);
/**
* Slab behavior is complicated, disable this for higher path reliability. Leave enabled if you have bottom slabs
* everywhere in your base.
*/
public Setting<Boolean> allowWalkOnBottomSlab = new Setting<>(true);
/**
* This is the big A* setting.
* As long as your cost heuristic is an *underestimate*, it's guaranteed to find you the best path.

View File

@ -50,10 +50,11 @@ public final class ChunkPacker implements Helper {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
int index = CachedChunk.getPositionIndex(x, y, z);
Block block = chunk.getBlockState(x, y, z).getBlock();
boolean[] bits = getPathingBlockType(block).getBits();
IBlockState state = chunk.getBlockState(x, y, z);
boolean[] bits = getPathingBlockType(state).getBits();
bitSet.set(index, bits[0]);
bitSet.set(index + 1, bits[1]);
Block block = state.getBlock();
if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(block)) {
String name = blockToString(block);
specialBlocks.computeIfAbsent(name, b -> new ArrayList<>()).add(new BlockPos(x, y, z));
@ -103,13 +104,14 @@ public final class ChunkPacker implements Helper {
return Block.getBlockFromName(name);
}
private static PathingBlockType getPathingBlockType(Block block) {
private static PathingBlockType getPathingBlockType(IBlockState state) {
Block block = state.getBlock();
if (block.equals(Blocks.WATER)) {
// only water source blocks are plausibly usable, flowing water should be avoid
return PathingBlockType.WATER;
}
if (MovementHelper.avoidWalkingInto(block) || block.equals(Blocks.FLOWING_WATER)) {
if (MovementHelper.avoidWalkingInto(block) || block.equals(Blocks.FLOWING_WATER) || MovementHelper.isBottomSlab(state)) {
return PathingBlockType.AVOID;
}
// We used to do an AABB check here

View File

@ -200,7 +200,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
return Optional.of(new Path(startNode, bestSoFar[i], numNodes));
}
}
displayChatMessageRaw("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + bestDist + " blocks");
displayChatMessageRaw("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + Math.sqrt(bestDist) + " blocks");
displayChatMessageRaw("No path found =(");
currentlyRunning = null;
return Optional.empty();

View File

@ -21,13 +21,7 @@ import baritone.Baritone;
import baritone.behavior.impl.LookBehavior;
import baritone.behavior.impl.LookBehaviorUtils;
import baritone.pathing.movement.MovementState.MovementStatus;
import baritone.pathing.movement.movements.MovementDownward;
import baritone.pathing.movement.movements.MovementPillar;
import baritone.pathing.movement.movements.MovementTraverse;
import baritone.utils.*;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLadder;
import net.minecraft.block.BlockVine;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
@ -78,21 +72,11 @@ public abstract class Movement implements Helper, MovementHelper {
if (cost == null) {
if (context == null)
context = new CalculationContext();
cost = calculateCost0(context);
cost = calculateCost(context);
}
return cost;
}
private double calculateCost0(CalculationContext context) {
if (!(this instanceof MovementPillar) && !(this instanceof MovementTraverse) && !(this instanceof MovementDownward)) {
Block fromDown = BlockStateInterface.get(src.down()).getBlock();
if (fromDown instanceof BlockLadder || fromDown instanceof BlockVine) {
return COST_INF;
}
}
return calculateCost(context);
}
protected abstract double calculateCost(CalculationContext context);
public double recalculateCost() {
@ -101,7 +85,7 @@ public abstract class Movement implements Helper, MovementHelper {
}
public double calculateCostWithoutCaching() {
return calculateCost0(new CalculationContext());
return calculateCost(new CalculationContext());
}
/**

View File

@ -186,6 +186,9 @@ public interface MovementHelper extends ActionCosts, Helper {
*/
static boolean canWalkOn(BlockPos pos, IBlockState state) {
Block block = state.getBlock();
if (block == Blocks.AIR) {
return false;
}
if (block instanceof BlockLadder || (Baritone.settings().allowVines.get() && block instanceof BlockVine)) { // TODO reconsider this
return true;
}
@ -198,8 +201,17 @@ public interface MovementHelper extends ActionCosts, Helper {
if (Blocks.ENDER_CHEST.equals(block) || Blocks.CHEST.equals(block)) {
return true;
}
if (block instanceof BlockAir) {
return false;
if (block instanceof BlockSlab) {
if (!Baritone.settings().allowWalkOnBottomSlab.get()) {
if (((BlockSlab) block).isDouble()) {
return true;
}
return state.getValue(BlockSlab.HALF) != BlockSlab.EnumBlockHalf.BOTTOM;
}
return true;
}
if (block instanceof BlockStairs) {
return true;
}
if (BlockStateInterface.isWater(block)) {
if (BlockStateInterface.isFlowing(state)) {
@ -261,6 +273,16 @@ public interface MovementHelper extends ActionCosts, Helper {
return 0; // we won't actually mine it, so don't check fallings above
}
static boolean isBottomSlab(IBlockState state) {
return state.getBlock() instanceof BlockSlab
&& !((BlockSlab) state.getBlock()).isDouble()
&& state.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM;
}
static boolean isBottomSlab(BlockPos pos) {
return isBottomSlab(BlockStateInterface.get(pos));
}
/**
* The entity the player is currently looking at
*

View File

@ -53,7 +53,18 @@ public class MovementAscend extends Movement {
@Override
protected double calculateCost(CalculationContext context) {
IBlockState srcDown = BlockStateInterface.get(src.down());
if (srcDown.getBlock() == Blocks.LADDER || srcDown.getBlock() == Blocks.VINE) {
return COST_INF;
}
// we can jump from soul sand, but not from a bottom slab
boolean jumpingFromBottomSlab = MovementHelper.isBottomSlab(srcDown);
IBlockState toPlace = BlockStateInterface.get(positionToPlace);
boolean jumpingToBottomSlab = MovementHelper.isBottomSlab(toPlace);
if (jumpingFromBottomSlab && !jumpingToBottomSlab) {
return COST_INF;// the only thing we can ascend onto from a bottom slab is another bottom slab
}
if (!MovementHelper.canWalkOn(positionToPlace, toPlace)) {
if (!context.hasThrowaway()) {
return COST_INF;
@ -96,9 +107,11 @@ public class MovementAscend extends Movement {
// it's possible srcUp is AIR from the start, and srcUp2 is falling
// and in that scenario, when we arrive and break srcUp2, that lets srcUp3 fall on us and suffocate us
}
// TODO maybe change behavior if src.down() is soul sand?
double walk = WALK_ONE_BLOCK_COST;
if (toPlace.getBlock().equals(Blocks.SOUL_SAND)) {
if (jumpingToBottomSlab && !jumpingFromBottomSlab) {
return walk + getTotalHardnessOfBlocksToBreak(context); // we don't hit space we just walk into the slab
}
if (!jumpingToBottomSlab && toPlace.getBlock().equals(Blocks.SOUL_SAND)) {
walk *= WALK_ONE_OVER_SOUL_SAND_COST / WALK_ONE_BLOCK_COST;
}
// we hit space immediately on entering this action
@ -123,7 +136,8 @@ public class MovementAscend extends Movement {
return state.setStatus(MovementStatus.SUCCESS);
}
if (!MovementHelper.canWalkOn(positionToPlace)) {
IBlockState jumpingOnto = BlockStateInterface.get(positionToPlace);
if (!MovementHelper.canWalkOn(positionToPlace, jumpingOnto)) {
for (int i = 0; i < 4; i++) {
BlockPos anAgainst = positionToPlace.offset(HORIZONTALS[i]);
if (anAgainst.equals(src)) {
@ -161,6 +175,11 @@ public class MovementAscend extends Movement {
return state.setStatus(MovementStatus.UNREACHABLE);
}
MovementHelper.moveTowards(state, dest);
if (MovementHelper.isBottomSlab(jumpingOnto)) {
if (!MovementHelper.isBottomSlab(src.down())) {
return state; // don't jump while walking from a non double slab into a bottom slab
}
}
if (headBonkClear()) {
return state.setInput(InputOverrideHandler.Input.JUMP, true);

View File

@ -25,8 +25,6 @@ import baritone.pathing.movement.MovementState.MovementStatus;
import baritone.utils.BlockStateInterface;
import baritone.utils.InputOverrideHandler;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLadder;
import net.minecraft.block.BlockVine;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
@ -44,18 +42,22 @@ public class MovementDescend extends Movement {
@Override
protected double calculateCost(CalculationContext context) {
Block fromDown = BlockStateInterface.get(src.down()).getBlock();
if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) {
return COST_INF;
}
if (!MovementHelper.canWalkOn(positionToPlace)) {
return COST_INF;
}
Block tmp1 = BlockStateInterface.get(dest).getBlock();
if (tmp1 instanceof BlockLadder || tmp1 instanceof BlockVine) {
if (tmp1 == Blocks.LADDER || tmp1 == Blocks.VINE) {
return COST_INF;
}
// we walk half the block plus 0.3 to get to the edge, then we walk the other 0.2 while simultaneously falling (math.max because of how it's in parallel)
double walk = WALK_OFF_BLOCK_COST;
if (BlockStateInterface.get(src.down()).getBlock().equals(Blocks.SOUL_SAND)) {
if (fromDown == Blocks.SOUL_SAND) {
// use this ratio to apply the soul sand speed penalty to our 0.8 block distance
walk *= WALK_ONE_OVER_SOUL_SAND_COST / WALK_ONE_BLOCK_COST;
walk = WALK_ONE_OVER_SOUL_SAND_COST;
}
return walk + Math.max(FALL_N_BLOCKS_COST[1], CENTER_AFTER_FALL_COST) + getTotalHardnessOfBlocksToBreak(context);
}

View File

@ -75,6 +75,10 @@ public class MovementDiagonal extends Movement {
@Override
protected double calculateCost(CalculationContext context) {
Block fromDown = BlockStateInterface.get(src.down()).getBlock();
if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) {
return COST_INF;
}
if (!MovementHelper.canWalkThrough(positionsToBreak[4]) || !MovementHelper.canWalkThrough(positionsToBreak[5])) {
return COST_INF;
}
@ -88,7 +92,7 @@ public class MovementDiagonal extends Movement {
if (destWalkOn.getBlock().equals(Blocks.SOUL_SAND)) {
multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2;
}
if (BlockStateInterface.get(src.down()).getBlock().equals(Blocks.SOUL_SAND)) {
if (fromDown == Blocks.SOUL_SAND) {
multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2;
}
Block cuttingOver1 = BlockStateInterface.get(positionsToBreak[2].down()).getBlock();

View File

@ -23,9 +23,8 @@ import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLadder;
import net.minecraft.block.BlockVine;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
public class MovementDownward extends Movement {
@ -49,7 +48,7 @@ public class MovementDownward extends Movement {
}
IBlockState d = BlockStateInterface.get(dest);
Block td = d.getBlock();
boolean ladder = td instanceof BlockLadder || td instanceof BlockVine;
boolean ladder = td == Blocks.LADDER || td == Blocks.VINE;
if (ladder) {
return LADDER_DOWN_ONE_COST;
} else {

View File

@ -25,8 +25,11 @@ import baritone.pathing.movement.MovementState;
import baritone.pathing.movement.MovementState.MovementStatus;
import baritone.pathing.movement.MovementState.MovementTarget;
import baritone.utils.*;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFalling;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
@ -44,9 +47,17 @@ public class MovementFall extends Movement {
@Override
protected double calculateCost(CalculationContext context) {
if (!MovementHelper.canWalkOn(dest.down())) {
Block fromDown = BlockStateInterface.get(src.down()).getBlock();
if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) {
return COST_INF;
}
IBlockState fallOnto = BlockStateInterface.get(dest.down());
if (!MovementHelper.canWalkOn(dest.down(), fallOnto)) {
return COST_INF;
}
if (MovementHelper.isBottomSlab(fallOnto)) {
return COST_INF; // falling onto a half slab is really glitchy, and can cause more fall damage than we'd expect
}
double placeBucketCost = 0.0;
if (!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > context.maxFallHeightNoWater()) {
if (!context.hasWaterBucket()) {

View File

@ -47,11 +47,16 @@ public class MovementPillar extends Movement {
protected double calculateCost(CalculationContext context) {
Block fromDown = BlockStateInterface.get(src).getBlock();
boolean ladder = fromDown instanceof BlockLadder || fromDown instanceof BlockVine;
Block fromDownDown = BlockStateInterface.get(src.down()).getBlock();
IBlockState fromDownDown = BlockStateInterface.get(src.down());
if (!ladder) {
if (fromDownDown instanceof BlockLadder || fromDownDown instanceof BlockVine) {
if (fromDownDown.getBlock() instanceof BlockLadder || fromDownDown.getBlock() instanceof BlockVine) {
return COST_INF;
}
if (fromDownDown.getBlock() instanceof BlockSlab) {
if (!((BlockSlab) fromDownDown.getBlock()).isDouble() && fromDownDown.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) {
return COST_INF; // can't pillar up from a bottom slab onto a non ladder
}
}
}
if (!context.hasThrowaway() && !ladder) {
return COST_INF;
@ -87,7 +92,7 @@ public class MovementPillar extends Movement {
//}
}
}
if (fromDown instanceof BlockLiquid || fromDownDown instanceof BlockLiquid) {//can't pillar on water or in water
if (fromDown instanceof BlockLiquid || fromDownDown.getBlock() instanceof BlockLiquid) {//can't pillar on water or in water
return COST_INF;
}
if (ladder) {
@ -142,9 +147,12 @@ public class MovementPillar extends Movement {
return state.setStatus(MovementState.MovementStatus.UNREACHABLE);
}
if (playerFeet().equals(against.up()) || playerFeet().equals(dest))
if (playerFeet().equals(against.up()) || playerFeet().equals(dest)) {
return state.setStatus(MovementState.MovementStatus.SUCCESS);
}
if (MovementHelper.isBottomSlab(src.down())) {
state.setInput(InputOverrideHandler.Input.JUMP, true);
}
/*
if (thePlayer.getPosition0().getX() != from.getX() || thePlayer.getPosition0().getZ() != from.getZ()) {
Baritone.moveTowardsBlock(from);

View File

@ -85,7 +85,7 @@ public class MovementTraverse extends Movement {
return WC + hardness1 + hardness2;
} else {//this is a bridge, so we need to place a block
Block srcDown = BlockStateInterface.get(src.down()).getBlock();
if (srcDown instanceof BlockLadder || srcDown instanceof BlockVine) {
if (srcDown == Blocks.LADDER || srcDown == Blocks.VINE) {
return COST_INF;
}
if (destOn.getBlock().equals(Blocks.AIR) || MovementHelper.isReplacable(positionToPlace, destOn)) {
@ -107,8 +107,8 @@ public class MovementTraverse extends Movement {
return WC + context.placeBlockCost() + getTotalHardnessOfBlocksToBreak(context);
}
}
if (Blocks.SOUL_SAND.equals(srcDown)) {
return COST_INF; // can't sneak and backplace against soul sand =/
if (srcDown == Blocks.SOUL_SAND || (srcDown instanceof BlockSlab && !((BlockSlab) srcDown).isDouble())) {
return COST_INF; // can't sneak and backplace against soul sand or half slabs =/
}
WC = WC * SNEAK_ONE_BLOCK_COST / WALK_ONE_BLOCK_COST;//since we are placing, we are sneaking
return WC + context.placeBlockCost() + getTotalHardnessOfBlocksToBreak(context);
@ -206,7 +206,8 @@ public class MovementTraverse extends Movement {
return state.setStatus(MovementState.MovementStatus.UNREACHABLE);
}
state.setInput(InputOverrideHandler.Input.SNEAK, true);
if (BlockStateInterface.get(playerFeet().down()).getBlock().equals(Blocks.SOUL_SAND)) { // see issue #118
Block standingOn = BlockStateInterface.get(playerFeet().down()).getBlock();
if (standingOn.equals(Blocks.SOUL_SAND) || standingOn instanceof BlockSlab) { // see issue #118
double dist = Math.max(Math.abs(dest.getX() + 0.5 - player().posX), Math.abs(dest.getZ() + 0.5 - player().posZ));
if (dist < 0.85) { // 0.5 + 0.3 + epsilon
MovementHelper.moveTowards(state, dest);

View File

@ -18,6 +18,7 @@
package baritone.utils;
import baritone.Baritone;
import net.minecraft.block.BlockSlab;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.multiplayer.WorldClient;
@ -53,10 +54,11 @@ public interface Helper {
default BlockPos playerFeet() {
// TODO find a better way to deal with soul sand!!!!!
return new BlockPos(player().posX, player().posY + 0.1251, player().posZ);
/*if (BlockStateInterface.get(feet).getBlock().equals(Blocks.SOUL_SAND) && player().posY > feet.getY() + 0.874999) {
BlockPos feet = new BlockPos(player().posX, player().posY + 0.1251, player().posZ);
if (BlockStateInterface.get(feet).getBlock() instanceof BlockSlab) {
return feet.up();
}*/
}
return feet;
}
default Vec3d playerFeetAsVec() {

View File

@ -67,10 +67,10 @@ public class ToolSet implements Helper {
private Map<Block, Byte> slotCache = new HashMap<>();
/**
* A cache mapping a {@link IBlockState} to how long it will take to break
* A cache mapping a {@link Block} to how long it will take to break
* with this toolset, given the optimum tool is used.
*/
private Map<IBlockState, Double> breakStrengthCache = new HashMap<>();
private Map<Block, Double> breakStrengthCache = new HashMap<>();
/**
* Create a toolset from the current player's inventory (but don't calculate any hardness values just yet)
@ -141,7 +141,7 @@ public class ToolSet implements Helper {
* @return how long it would take in ticks
*/
public double getStrVsBlock(IBlockState state, BlockPos pos) {
return this.breakStrengthCache.computeIfAbsent(state, s -> calculateStrVsBlock(s, pos));
return this.breakStrengthCache.computeIfAbsent(state.getBlock(), b -> calculateStrVsBlock(state, pos));
}
/**

View File

@ -26,7 +26,7 @@ import net.minecraft.util.math.Vec3i;
*
* @author leijurv
*/
public class BetterBlockPos extends BlockPos {
public final class BetterBlockPos extends BlockPos {
public final int x;
public final int y;
public final int z;