almost works
This commit is contained in:
		@@ -45,7 +45,7 @@ public class PathingBehavior extends Behavior {
 | 
			
		||||
        if (current == null) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        // current.onTick();
 | 
			
		||||
        current.onTick(event);
 | 
			
		||||
        if (current.failed() || current.finished()) {
 | 
			
		||||
            current = null;
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,7 @@ import baritone.bot.pathing.goals.Goal;
 | 
			
		||||
import baritone.bot.pathing.movement.ActionCosts;
 | 
			
		||||
import baritone.bot.pathing.movement.Movement;
 | 
			
		||||
import baritone.bot.pathing.movement.movements.MovementAscend;
 | 
			
		||||
import baritone.bot.pathing.movement.movements.MovementTraverse;
 | 
			
		||||
import baritone.bot.pathing.path.IPath;
 | 
			
		||||
import baritone.bot.utils.ToolSet;
 | 
			
		||||
import net.minecraft.client.Minecraft;
 | 
			
		||||
@@ -139,10 +140,10 @@ public class AStarPathFinder extends AbstractNodeCostSearch {
 | 
			
		||||
        int y = pos.getY();
 | 
			
		||||
        int z = pos.getZ();
 | 
			
		||||
        Movement[] movements = new Movement[8];
 | 
			
		||||
        movements[0] = new MovementAscend(pos, new BlockPos(x + 1, y, z));
 | 
			
		||||
        movements[1] = new MovementAscend(pos, new BlockPos(x - 1, y, z));
 | 
			
		||||
        movements[2] = new MovementAscend(pos, new BlockPos(x, y, z + 1));
 | 
			
		||||
        movements[3] = new MovementAscend(pos, new BlockPos(x, y, z - 1));
 | 
			
		||||
        movements[0] = new MovementTraverse(pos, new BlockPos(x + 1, y, z));
 | 
			
		||||
        movements[1] = new MovementTraverse(pos, new BlockPos(x - 1, y, z));
 | 
			
		||||
        movements[2] = new MovementTraverse(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[5] = new MovementAscend(pos, new BlockPos(x - 1, y + 1, z));
 | 
			
		||||
        movements[6] = new MovementAscend(pos, new BlockPos(x, y + 1, z + 1));
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,11 @@ import baritone.bot.pathing.calc.PathNode;
 | 
			
		||||
 | 
			
		||||
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 {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -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.
 | 
			
		||||
 * 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 {
 | 
			
		||||
    private Node first = null;
 | 
			
		||||
 
 | 
			
		||||
@@ -114,11 +114,9 @@ public interface MovementHelper extends ActionCosts, Helper {
 | 
			
		||||
     * through? Includes water because we know that we automatically jump on
 | 
			
		||||
     * lava
 | 
			
		||||
     *
 | 
			
		||||
     * @param pos
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    static boolean canWalkOn(BlockPos pos) {
 | 
			
		||||
        IBlockState state = BlockStateInterface.get(pos);
 | 
			
		||||
    static boolean canWalkOn(BlockPos pos, IBlockState state) {
 | 
			
		||||
        Block block = state.getBlock();
 | 
			
		||||
        if (block instanceof BlockLadder || block instanceof BlockVine) {
 | 
			
		||||
            return true;
 | 
			
		||||
@@ -129,6 +127,7 @@ public interface MovementHelper extends ActionCosts, Helper {
 | 
			
		||||
        return state.isBlockNormalCube() && !isLava(block);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    static boolean canFall(BlockPos pos) {
 | 
			
		||||
        return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -41,7 +41,7 @@ public class MovementAscend extends Movement {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    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])) {
 | 
			
		||||
                return COST_INF;
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user