almost works

This commit is contained in:
Leijurv 2018-08-05 21:17:04 -04:00
parent fedbe724ef
commit 988124e444
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
7 changed files with 124 additions and 10 deletions

View File

@ -45,7 +45,7 @@ public class PathingBehavior extends Behavior {
if (current == null) { if (current == null) {
return; return;
} }
// current.onTick(); current.onTick(event);
if (current.failed() || current.finished()) { if (current.failed() || current.finished()) {
current = null; current = null;
} }

View File

@ -6,6 +6,7 @@ import baritone.bot.pathing.goals.Goal;
import baritone.bot.pathing.movement.ActionCosts; import baritone.bot.pathing.movement.ActionCosts;
import baritone.bot.pathing.movement.Movement; import baritone.bot.pathing.movement.Movement;
import baritone.bot.pathing.movement.movements.MovementAscend; import baritone.bot.pathing.movement.movements.MovementAscend;
import baritone.bot.pathing.movement.movements.MovementTraverse;
import baritone.bot.pathing.path.IPath; import baritone.bot.pathing.path.IPath;
import baritone.bot.utils.ToolSet; import baritone.bot.utils.ToolSet;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -139,10 +140,10 @@ public class AStarPathFinder extends AbstractNodeCostSearch {
int y = pos.getY(); int y = pos.getY();
int z = pos.getZ(); int z = pos.getZ();
Movement[] movements = new Movement[8]; Movement[] movements = new Movement[8];
movements[0] = new MovementAscend(pos, new BlockPos(x + 1, y, z)); movements[0] = new MovementTraverse(pos, new BlockPos(x + 1, y, z));
movements[1] = new MovementAscend(pos, new BlockPos(x - 1, y, z)); movements[1] = new MovementTraverse(pos, new BlockPos(x - 1, y, z));
movements[2] = new MovementAscend(pos, new BlockPos(x, y, z + 1)); movements[2] = new MovementTraverse(pos, new BlockPos(x, y, z + 1));
movements[3] = new MovementAscend(pos, new BlockPos(x, y, z - 1)); movements[3] = new MovementTraverse(pos, new BlockPos(x, y, z - 1));
movements[4] = new MovementAscend(pos, new BlockPos(x + 1, y + 1, z)); movements[4] = new MovementAscend(pos, new BlockPos(x + 1, y + 1, z));
movements[5] = new MovementAscend(pos, new BlockPos(x - 1, y + 1, z)); movements[5] = new MovementAscend(pos, new BlockPos(x - 1, y + 1, z));
movements[6] = new MovementAscend(pos, new BlockPos(x, y + 1, z + 1)); movements[6] = new MovementAscend(pos, new BlockPos(x, y + 1, z + 1));

View File

@ -4,6 +4,11 @@ import baritone.bot.pathing.calc.PathNode;
import java.util.Arrays; import java.util.Arrays;
/**
* A binary heap implementation of an open set. This is the one used in the AStarPathFinder.
*
* @author leijurv
*/
public class BinaryHeapOpenSet implements IOpenSet { public class BinaryHeapOpenSet implements IOpenSet {
/** /**

View File

@ -4,7 +4,9 @@ import baritone.bot.pathing.calc.PathNode;
/** /**
* A linked list implementation of an open set. This is the original implementation from MineBot. * A linked list implementation of an open set. This is the original implementation from MineBot.
* It has incredbly fast insert performance, at the cost of O(n) removeLowest. * It has incredibly fast insert performance, at the cost of O(n) removeLowest.
*
* @author leijurv
*/ */
public class LinkedListOpenSet implements IOpenSet { public class LinkedListOpenSet implements IOpenSet {
private Node first = null; private Node first = null;

View File

@ -114,11 +114,9 @@ public interface MovementHelper extends ActionCosts, Helper {
* through? Includes water because we know that we automatically jump on * through? Includes water because we know that we automatically jump on
* lava * lava
* *
* @param pos
* @return * @return
*/ */
static boolean canWalkOn(BlockPos pos) { static boolean canWalkOn(BlockPos pos, IBlockState state) {
IBlockState state = BlockStateInterface.get(pos);
Block block = state.getBlock(); Block block = state.getBlock();
if (block instanceof BlockLadder || block instanceof BlockVine) { if (block instanceof BlockLadder || block instanceof BlockVine) {
return true; return true;
@ -129,6 +127,7 @@ public interface MovementHelper extends ActionCosts, Helper {
return state.isBlockNormalCube() && !isLava(block); return state.isBlockNormalCube() && !isLava(block);
} }
static boolean canFall(BlockPos pos) { static boolean canFall(BlockPos pos) {
return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling; return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling;
} }

View File

@ -41,7 +41,7 @@ public class MovementAscend extends Movement {
@Override @Override
protected double calculateCost(ToolSet ts) { protected double calculateCost(ToolSet ts) {
if (!MovementHelper.canWalkOn(positionsToPlace[0])) { if (!MovementHelper.canWalkOn(positionsToPlace[0], BlockStateInterface.get(positionsToPlace[0]))) {
if (!MovementHelper.isAir(positionsToPlace[0]) && !MovementHelper.isWater(positionsToPlace[0])) { if (!MovementHelper.isAir(positionsToPlace[0]) && !MovementHelper.isWater(positionsToPlace[0])) {
return COST_INF; return COST_INF;
} }

View File

@ -0,0 +1,107 @@
package baritone.bot.pathing.movement.movements;
import baritone.bot.InputOverrideHandler;
import baritone.bot.pathing.movement.Movement;
import baritone.bot.pathing.movement.MovementHelper;
import baritone.bot.pathing.movement.MovementState;
import baritone.bot.utils.BlockStateInterface;
import baritone.bot.utils.ToolSet;
import baritone.bot.utils.Utils;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLadder;
import net.minecraft.block.BlockVine;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import java.util.Optional;
public class MovementTraverse extends Movement {
BlockPos[] against = new BlockPos[3];
public MovementTraverse(BlockPos from, BlockPos to) {
super(from, to, new BlockPos[]{to.up(), to}, new BlockPos[]{to.down()});
int i = 0;
if (!to.north().equals(from)) {
against[i] = to.north().down();
i++;
}
if (!to.south().equals(from)) {
against[i] = to.south().down();
i++;
}
if (!to.east().equals(from)) {
against[i] = to.east().down();
i++;
}
if (!to.west().equals(from)) {
against[i] = to.west().down();
i++;
}
//note: do NOT add ability to place against .down().down()
}
@Override
protected double calculateCost(ToolSet ts) {
IBlockState pb0 = BlockStateInterface.get(positionsToBreak[0]);
IBlockState pb1 = BlockStateInterface.get(positionsToBreak[1]);
double WC = MovementHelper.isWater(pb0.getBlock()) || MovementHelper.isWater(pb1.getBlock()) ? WALK_ONE_IN_WATER_COST : WALK_ONE_BLOCK_COST;
if (MovementHelper.canWalkOn(positionsToPlace[0], BlockStateInterface.get(positionsToPlace[0]))) {//this is a walk, not a bridge
if (MovementHelper.canWalkThrough(positionsToBreak[0], pb0) && MovementHelper.canWalkThrough(positionsToBreak[1], pb1)) {
return WC;
}
//double hardness1 = blocksToBreak[0].getBlockHardness(Minecraft.getMinecraft().world, positionsToBreak[0]);
//double hardness2 = blocksToBreak[1].getBlockHardness(Minecraft.getMinecraft().world, positionsToBreak[1]);
//Out.log("Can't walk through " + blocksToBreak[0] + " (hardness" + hardness1 + ") or " + blocksToBreak[1] + " (hardness " + hardness2 + ")");
return WC + getTotalHardnessOfBlocksToBreak(ts);
} else {//this is a bridge, so we need to place a block
if (true) {
System.out.println(src + " " + dest);
return COST_INF;//TODO
}
//return 1000000;
Block f = BlockStateInterface.get(src.down()).getBlock();
if (f instanceof BlockLadder || f instanceof BlockVine) {
return COST_INF;
}
IBlockState pp0 = BlockStateInterface.get(positionsToPlace[0]);
if (pp0.getBlock().equals(Blocks.AIR) || (!MovementHelper.isWater(pp0.getBlock()) && pp0.getBlock().isReplaceable(Minecraft.getMinecraft().world, positionsToPlace[0]))) {
for (BlockPos against1 : against) {
if (BlockStateInterface.get(against1).isBlockNormalCube()) {
return WC + PLACE_ONE_BLOCK_COST + getTotalHardnessOfBlocksToBreak(ts);
}
}
WC = WC * SNEAK_ONE_BLOCK_COST / WALK_ONE_BLOCK_COST;//since we are placing, we are sneaking
return WC + PLACE_ONE_BLOCK_COST + getTotalHardnessOfBlocksToBreak(ts);
}
return COST_INF;
//Out.log("Can't walk on " + Baritone.get(positionsToPlace[0]).getBlock());
}
}
@Override
public void onFinish() {
}
@Override
public MovementState updateState(MovementState state) {
super.updateState(state);
switch (state.getStatus()) {
case PREPPING:
case UNREACHABLE:
case FAILED:
return state;
case WAITING:
case RUNNING:
state.setTarget(new MovementState.MovementTarget(Optional.empty(), Optional.of(Utils.calcRotationFromCoords(playerFeet(), positionsToBreak[0]))));
MovementState latestState = state.setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
if (playerFeet().equals(dest))
latestState.setStatus(MovementState.MovementStatus.SUCCESS);
default:
return state;
}
}
}