Relocate MovementHelper and Movement utility methods
This commit is contained in:
parent
1a33d9462d
commit
5e665554ea
@ -55,45 +55,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() {
|
||||||
|
@ -82,11 +82,46 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
return state.isBlockNormalCube() && !BlockStateInterface.isLava(block);
|
return state.isBlockNormalCube() && !BlockStateInterface.isLava(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static double getTotalHardnessOfBlocksToBreak(ToolSet ts, BlockPos[] positionsToBreak) {
|
||||||
static boolean canFall(BlockPos pos) {
|
/*
|
||||||
return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling;
|
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)) {
|
||||||
|
@ -27,7 +27,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
|
||||||
|
@ -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;
|
||||||
@ -71,4 +72,9 @@ public class BlockStateInterface {
|
|||||||
return BlockStateInterface.getBlock(pos).equals(Blocks.AIR);
|
return BlockStateInterface.getBlock(pos).equals(Blocks.AIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static boolean canFall(BlockPos pos) {
|
||||||
|
return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user