merge
This commit is contained in:
@@ -56,45 +56,6 @@ public abstract class Movement implements Helper, MovementHelper {
|
|||||||
return cost;
|
return cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getTotalHardnessOfBlocksToBreak(ToolSet ts) {
|
|
||||||
/*
|
|
||||||
double sum = 0;
|
|
||||||
HashSet<BlockPos> toBreak = new HashSet();
|
|
||||||
for (BlockPos positionsToBreak1 : positionsToBreak) {
|
|
||||||
toBreak.add(positionsToBreak1);
|
|
||||||
if (this instanceof ActionFall) {//if we are digging straight down, assume we have already broken the sand above us
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
BlockPos tmp = positionsToBreak1.up();
|
|
||||||
while (canFall(tmp)) {
|
|
||||||
toBreak.add(tmp);
|
|
||||||
tmp = tmp.up();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (BlockPos pos : toBreak) {
|
|
||||||
sum += getHardness(ts, Baritone.get(pos), pos);
|
|
||||||
if (sum >= COST_INF) {
|
|
||||||
return COST_INF;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!Baritone.allowBreakOrPlace || !Baritone.hasThrowaway) {
|
|
||||||
for (int i = 0; i < blocksToPlace.length; i++) {
|
|
||||||
if (!canWalkOn(positionsToPlace[i])) {
|
|
||||||
return COST_INF;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
//^ the above implementation properly deals with falling blocks, TODO integrate
|
|
||||||
double sum = 0;
|
|
||||||
for (BlockPos pos : positionsToBreak) {
|
|
||||||
sum += MovementHelper.getMiningDurationTicks(ts, BlockStateInterface.get(pos), pos);
|
|
||||||
if (sum >= COST_INF) {
|
|
||||||
return COST_INF;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract double calculateCost(ToolSet ts); // TODO pass in information like whether it's allowed to place throwaway blocks
|
protected abstract double calculateCost(ToolSet ts); // TODO pass in information like whether it's allowed to place throwaway blocks
|
||||||
|
|
||||||
public double recalculateCost() {
|
public double recalculateCost() {
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
return state.isBlockNormalCube() && !BlockStateInterface.isLava(block);
|
return state.isBlockNormalCube() && !BlockStateInterface.isLava(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static boolean canWalkOn(BlockPos pos) {
|
static boolean canWalkOn(BlockPos pos) {
|
||||||
return canWalkOn(pos, BlockStateInterface.get(pos));
|
return canWalkOn(pos, BlockStateInterface.get(pos));
|
||||||
}
|
}
|
||||||
@@ -97,6 +98,46 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling;
|
return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static double getTotalHardnessOfBlocksToBreak(ToolSet ts, BlockPos[] positionsToBreak) {
|
||||||
|
/*
|
||||||
|
double sum = 0;
|
||||||
|
HashSet<BlockPos> toBreak = new HashSet();
|
||||||
|
for (BlockPos positionsToBreak1 : positionsToBreak) {
|
||||||
|
toBreak.add(positionsToBreak1);
|
||||||
|
if (this instanceof ActionFall) {//if we are digging straight down, assume we have already broken the sand above us
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BlockPos tmp = positionsToBreak1.up();
|
||||||
|
while (canFall(tmp)) {
|
||||||
|
toBreak.add(tmp);
|
||||||
|
tmp = tmp.up();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (BlockPos pos : toBreak) {
|
||||||
|
sum += getHardness(ts, Baritone.get(pos), pos);
|
||||||
|
if (sum >= COST_INF) {
|
||||||
|
return COST_INF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!Baritone.allowBreakOrPlace || !Baritone.hasThrowaway) {
|
||||||
|
for (int i = 0; i < blocksToPlace.length; i++) {
|
||||||
|
if (!canWalkOn(positionsToPlace[i])) {
|
||||||
|
return COST_INF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
//^ the above implementation properly deals with falling blocks, TODO integrate
|
||||||
|
double sum = 0;
|
||||||
|
for (BlockPos pos : positionsToBreak) {
|
||||||
|
sum += getMiningDurationTicks(ts, BlockStateInterface.get(pos), pos);
|
||||||
|
if (sum >= COST_INF) {
|
||||||
|
return COST_INF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static double getMiningDurationTicks(ToolSet ts, IBlockState block, BlockPos position) {
|
static double getMiningDurationTicks(ToolSet ts, IBlockState block, BlockPos position) {
|
||||||
if (!block.equals(Blocks.AIR) && !canWalkThrough(position, block)) {
|
if (!block.equals(Blocks.AIR) && !canWalkThrough(position, block)) {
|
||||||
if (avoidBreaking(position)) {
|
if (avoidBreaking(position)) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import baritone.bot.InputOverrideHandler;
|
|||||||
import baritone.bot.pathing.movement.Movement;
|
import baritone.bot.pathing.movement.Movement;
|
||||||
import baritone.bot.pathing.movement.MovementHelper;
|
import baritone.bot.pathing.movement.MovementHelper;
|
||||||
import baritone.bot.pathing.movement.MovementState;
|
import baritone.bot.pathing.movement.MovementState;
|
||||||
|
import baritone.bot.pathing.movement.MovementState.MovementStatus;
|
||||||
import baritone.bot.utils.BlockStateInterface;
|
import baritone.bot.utils.BlockStateInterface;
|
||||||
import baritone.bot.utils.Rotation;
|
import baritone.bot.utils.Rotation;
|
||||||
import baritone.bot.utils.ToolSet;
|
import baritone.bot.utils.ToolSet;
|
||||||
@@ -27,7 +28,7 @@ public class MovementDescend extends Movement {
|
|||||||
if (tmp1 instanceof BlockLadder || tmp1 instanceof BlockVine) {
|
if (tmp1 instanceof BlockLadder || tmp1 instanceof BlockVine) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
return WALK_ONE_BLOCK_COST * 0.8 + Math.max(FALL_N_BLOCKS_COST[1], WALK_ONE_BLOCK_COST * 0.2) + getTotalHardnessOfBlocksToBreak(ts);//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)
|
return WALK_ONE_BLOCK_COST * 0.8 + Math.max(FALL_N_BLOCKS_COST[1], WALK_ONE_BLOCK_COST * 0.2) + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak);//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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -40,12 +41,13 @@ public class MovementDescend extends Movement {
|
|||||||
case FAILED:
|
case FAILED:
|
||||||
return state;
|
return state;
|
||||||
case WAITING:
|
case WAITING:
|
||||||
|
state.setStatus(MovementStatus.RUNNING);
|
||||||
case RUNNING:
|
case RUNNING:
|
||||||
BlockPos playerFeet = playerFeet();
|
BlockPos playerFeet = playerFeet();
|
||||||
|
|
||||||
if (playerFeet.equals(dest) && player().posY - playerFeet.getY() < 0.01) {
|
if (playerFeet.equals(dest) && player().posY - playerFeet.getY() < 0.01) {
|
||||||
// Wait until we're actually on the ground before saying we're done because sometimes we continue to fall if the next action starts immediately
|
// Wait until we're actually on the ground before saying we're done because sometimes we continue to fall if the next action starts immediately
|
||||||
state.setStatus(MovementState.MovementStatus.SUCCESS);
|
state.setStatus(MovementStatus.SUCCESS);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
Rotation rotationToBlock = Utils.calcRotationFromVec3d(playerHead(), Utils.calcCenterFromCoords(positionsToBreak[1], world()));
|
Rotation rotationToBlock = Utils.calcRotationFromVec3d(playerHead(), Utils.calcCenterFromCoords(positionsToBreak[1], world()));
|
||||||
|
|||||||
@@ -1,61 +1,41 @@
|
|||||||
package baritone.bot.pathing.movement.movements;
|
package baritone.bot.pathing.movement.movements;
|
||||||
|
|
||||||
import baritone.bot.InputOverrideHandler;
|
import baritone.bot.pathing.movement.ActionCosts;
|
||||||
import baritone.bot.pathing.movement.Movement;
|
import baritone.bot.pathing.movement.Movement;
|
||||||
import baritone.bot.pathing.movement.MovementHelper;
|
import baritone.bot.pathing.movement.MovementHelper;
|
||||||
import baritone.bot.pathing.movement.MovementState;
|
|
||||||
import baritone.bot.utils.BlockStateInterface;
|
import baritone.bot.utils.BlockStateInterface;
|
||||||
import baritone.bot.utils.Rotation;
|
|
||||||
import baritone.bot.utils.ToolSet;
|
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.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
public class MovementFall extends Movement {
|
public class MovementFall extends Movement {
|
||||||
public MovementFall(BlockPos start) {
|
|
||||||
super(start, start.down(), new BlockPos[]{start.down()}, new BlockPos[0]);
|
private static BlockPos[] buildPositionsToBreak(BlockPos src, BlockPos dest) {
|
||||||
|
BlockPos[] toBreak;
|
||||||
|
int diffX = dest.getX() - src.getX();
|
||||||
|
int diffZ = dest.getZ() - src.getZ();
|
||||||
|
int diffY = dest.getY() - src.getY();
|
||||||
|
toBreak = new BlockPos[diffY + 1];
|
||||||
|
for(int i = 0; i < toBreak.length; i++ ) {
|
||||||
|
toBreak[i] = new BlockPos(dest.getX() - diffX, dest.getY() + (toBreak.length - 1) - i, dest.getZ() - diffZ);
|
||||||
|
}
|
||||||
|
return toBreak;
|
||||||
}
|
}
|
||||||
|
|
||||||
int numTicks = 0;
|
|
||||||
|
|
||||||
@Override
|
protected MovementFall(BlockPos src, BlockPos dest) {
|
||||||
public MovementState updateState(MovementState state) {
|
super(src, dest, MovementFall.buildPositionsToBreak(src, dest), new BlockPos[]{dest.down()});
|
||||||
super.updateState(state);
|
|
||||||
System.out.println("Ticking with state " + state.getStatus());
|
|
||||||
switch (state.getStatus()) {
|
|
||||||
case PREPPING:
|
|
||||||
case UNREACHABLE:
|
|
||||||
case FAILED:
|
|
||||||
return state;
|
|
||||||
case WAITING:
|
|
||||||
case RUNNING:
|
|
||||||
if (playerFeet().equals(dest)) {
|
|
||||||
state.setStatus(MovementState.MovementStatus.SUCCESS);
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
if (numTicks++ < 10) {
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
Rotation rotationToBlock = Utils.calcRotationFromVec3d(playerHead(), Utils.calcCenterFromCoords(positionsToBreak[0], world()));
|
|
||||||
return state.setTarget(new MovementState.MovementTarget(rotationToBlock)).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calculateCost(ToolSet ts) {
|
protected double calculateCost(ToolSet ts) {
|
||||||
if (!MovementHelper.canWalkOn(dest.down(), BlockStateInterface.get(dest.down()))) {
|
if(!MovementHelper.canWalkOn(positionsToPlace[0], BlockStateInterface.get(positionsToPlace[0]))) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
Block td = BlockStateInterface.get(dest).getBlock();
|
double placeBucketCost = 0.0;
|
||||||
boolean ladder = td instanceof BlockLadder || td instanceof BlockVine;
|
if(!BlockStateInterface.isWater(dest)) {
|
||||||
if (ladder) {
|
placeBucketCost = ActionCosts.PLACE_ONE_BLOCK_COST;
|
||||||
return LADDER_DOWN_ONE_COST;
|
|
||||||
} else {
|
|
||||||
return FALL_N_BLOCKS_COST[1] + getTotalHardnessOfBlocksToBreak(ts);
|
|
||||||
}
|
}
|
||||||
|
return WALK_OFF_BLOCK_COST + FALL_N_BLOCKS_COST[positionsToBreak.length - 1] + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak) + placeBucketCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package baritone.bot.utils;
|
package baritone.bot.utils;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.BlockFalling;
|
||||||
import net.minecraft.block.BlockLiquid;
|
import net.minecraft.block.BlockLiquid;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
@@ -40,7 +41,7 @@ public class BlockStateInterface {
|
|||||||
* @return Whether or not the block is water
|
* @return Whether or not the block is water
|
||||||
*/
|
*/
|
||||||
public static boolean isWater(BlockPos bp) {
|
public static boolean isWater(BlockPos bp) {
|
||||||
return isWater(BlockStateInterface.get(bp).getBlock());
|
return isWater(BlockStateInterface.getBlock(bp));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isLava(Block b) {
|
public static boolean isLava(Block b) {
|
||||||
@@ -58,7 +59,7 @@ public class BlockStateInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isLiquid(BlockPos p) {
|
public static boolean isLiquid(BlockPos p) {
|
||||||
return isLiquid(BlockStateInterface.get(p).getBlock());
|
return isLiquid(BlockStateInterface.getBlock(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isFlowing(IBlockState state) {
|
public static boolean isFlowing(IBlockState state) {
|
||||||
@@ -68,7 +69,12 @@ public class BlockStateInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAir(BlockPos pos) {
|
public static boolean isAir(BlockPos pos) {
|
||||||
return BlockStateInterface.get(pos).getBlock().equals(Blocks.AIR);
|
return BlockStateInterface.getBlock(pos).equals(Blocks.AIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static boolean canFall(BlockPos pos) {
|
||||||
|
return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user