Fix location of method
This commit is contained in:
parent
5b3eb5a375
commit
24cbb5e149
@ -131,6 +131,47 @@ public abstract class Movement implements Helper, MovementHelper {
|
||||
currentState.setStatus(MovementStatus.CANCELED);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate latest movement state.
|
||||
* Gets called once a tick.
|
||||
@ -154,9 +195,9 @@ public abstract class Movement implements Helper, MovementHelper {
|
||||
return toBreakCached;
|
||||
}
|
||||
ArrayList<BlockPos> result = new ArrayList<>();
|
||||
for (BlockPos positionsToBreak1 : positionsToBreak) {
|
||||
if (!MovementHelper.canWalkThrough(positionsToBreak1, BlockStateInterface.get(positionsToBreak1))) {
|
||||
result.add(positionsToBreak1);
|
||||
for (BlockPos positionToBreak : positionsToBreak) {
|
||||
if (!MovementHelper.canWalkThrough(positionToBreak, BlockStateInterface.get(positionToBreak))) {
|
||||
result.add(positionToBreak);
|
||||
}
|
||||
}
|
||||
toBreakCached = result;
|
||||
@ -168,9 +209,9 @@ public abstract class Movement implements Helper, MovementHelper {
|
||||
return toPlaceCached;
|
||||
}
|
||||
ArrayList<BlockPos> result = new ArrayList<>();
|
||||
for (BlockPos positionsToPlace1 : positionsToPlace) {
|
||||
if (!MovementHelper.canWalkOn(positionsToPlace1)) {
|
||||
result.add(positionsToPlace1);
|
||||
for (BlockPos positionToBreak : positionsToPlace) {
|
||||
if (!MovementHelper.canWalkOn(positionToBreak)) {
|
||||
result.add(positionToBreak);
|
||||
}
|
||||
}
|
||||
toPlaceCached = result;
|
||||
@ -178,6 +219,7 @@ public abstract class Movement implements Helper, MovementHelper {
|
||||
}
|
||||
|
||||
protected void moveTowards(BlockPos pos) {
|
||||
currentState.setTarget(new MovementState.MovementTarget(new Rotation(Utils.calcRotationFromVec3d(playerHead(), Utils.calcCenterFromCoords(pos, world()), playerRotations()).getFirst(), player().rotationPitch))).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
|
||||
currentState.setTarget(new MovementState.MovementTarget(new Rotation(Utils.calcRotationFromVec3d(playerHead(), Utils.calcCenterFromCoords(pos, world()), playerRotations()).getFirst(), player().rotationPitch)))
|
||||
.setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
|
||||
}
|
||||
}
|
||||
|
@ -98,46 +98,6 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
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) {
|
||||
if (!block.equals(Blocks.AIR) && !canWalkThrough(position, block)) {
|
||||
if (avoidBreaking(position)) {
|
||||
|
@ -50,7 +50,7 @@ public class MovementAscend extends Movement {
|
||||
}
|
||||
for (BlockPos against1 : against) {
|
||||
if (BlockStateInterface.get(against1).isBlockNormalCube()) {
|
||||
return JUMP_ONE_BLOCK_COST + WALK_ONE_BLOCK_COST + PLACE_ONE_BLOCK_COST + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak);
|
||||
return JUMP_ONE_BLOCK_COST + WALK_ONE_BLOCK_COST + PLACE_ONE_BLOCK_COST + getTotalHardnessOfBlocksToBreak(ts );
|
||||
}
|
||||
}
|
||||
return COST_INF;
|
||||
@ -58,7 +58,7 @@ public class MovementAscend extends Movement {
|
||||
if (BlockStateInterface.get(src.up(3)).getBlock() instanceof BlockFalling) {//it would fall on us and possibly suffocate us
|
||||
return COST_INF;
|
||||
}
|
||||
return WALK_ONE_BLOCK_COST / 2 + Math.max(JUMP_ONE_BLOCK_COST, WALK_ONE_BLOCK_COST / 2) + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak);//we walk half the block to get to the edge, then we walk the other half while simultaneously jumping (math.max because of how it's in parallel)
|
||||
return WALK_ONE_BLOCK_COST / 2 + Math.max(JUMP_ONE_BLOCK_COST, WALK_ONE_BLOCK_COST / 2) + getTotalHardnessOfBlocksToBreak(ts);//we walk half the block to get to the edge, then we walk the other half while simultaneously jumping (math.max because of how it's in parallel)
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,13 +25,12 @@ public class MovementDescend extends Movement {
|
||||
if (tmp1 instanceof BlockLadder || tmp1 instanceof BlockVine) {
|
||||
return COST_INF;
|
||||
}
|
||||
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)
|
||||
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)
|
||||
}
|
||||
|
||||
@Override
|
||||
public MovementState updateState(MovementState state) {
|
||||
super.updateState(state);
|
||||
System.out.println("Ticking with state " + state.getStatus());
|
||||
switch (state.getStatus()) {
|
||||
case PREPPING:
|
||||
case UNREACHABLE:
|
||||
|
@ -52,7 +52,7 @@ public class MovementDownward extends Movement {
|
||||
if (ladder) {
|
||||
return LADDER_DOWN_ONE_COST;
|
||||
} else {
|
||||
return FALL_N_BLOCKS_COST[1] + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak);
|
||||
return FALL_N_BLOCKS_COST[1] + getTotalHardnessOfBlocksToBreak(ts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,9 @@ import baritone.bot.utils.BlockStateInterface;
|
||||
import baritone.bot.utils.Rotation;
|
||||
import baritone.bot.utils.ToolSet;
|
||||
import baritone.bot.utils.Utils;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemBucket;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
@ -43,7 +46,7 @@ public class MovementFall extends Movement {
|
||||
if(!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > 3) {
|
||||
placeBucketCost = ActionCosts.PLACE_ONE_BLOCK_COST;
|
||||
}
|
||||
return WALK_OFF_BLOCK_COST + FALL_N_BLOCKS_COST[positionsToBreak.length - 1] + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak) + placeBucketCost;
|
||||
return WALK_OFF_BLOCK_COST + FALL_N_BLOCKS_COST[positionsToBreak.length - 1] + getTotalHardnessOfBlocksToBreak(ts) + placeBucketCost;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -58,6 +61,9 @@ public class MovementFall extends Movement {
|
||||
state.setStatus(MovementStatus.RUNNING);
|
||||
case RUNNING:
|
||||
BlockPos playerFeet = playerFeet();
|
||||
if(src.getY() - dest.getY() > 3 && !BlockStateInterface.isWater(dest) && !player().inventory.hasItemStack(new ItemStack(new ItemBucket(Blocks.WATER)))) {
|
||||
return state.setStatus(MovementStatus.UNREACHABLE);
|
||||
}
|
||||
if(playerFeet.equals(dest) && (player().posY - playerFeet.getY() < 0.01 || BlockStateInterface.isWater(dest)))
|
||||
return state.setStatus(MovementStatus.SUCCESS);
|
||||
Vec3d destCenter = Utils.calcCenterFromCoords(dest, world());
|
||||
|
@ -58,7 +58,7 @@ public class MovementTraverse extends Movement {
|
||||
//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 + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak);
|
||||
return WC + getTotalHardnessOfBlocksToBreak(ts);
|
||||
} else {//this is a bridge, so we need to place a block
|
||||
//return 1000000;
|
||||
Block f = BlockStateInterface.get(src.down()).getBlock();
|
||||
@ -69,11 +69,11 @@ public class MovementTraverse extends Movement {
|
||||
if (pp0.getBlock().equals(Blocks.AIR) || (!BlockStateInterface.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 + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak);
|
||||
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 + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak);
|
||||
return WC + PLACE_ONE_BLOCK_COST + getTotalHardnessOfBlocksToBreak(ts);
|
||||
}
|
||||
return COST_INF;
|
||||
//Out.log("Can't walk on " + Baritone.get(positionsToPlace[0]).getBlock());
|
||||
|
Loading…
Reference in New Issue
Block a user