move this behind the toolset cache for performance

This commit is contained in:
Leijurv 2019-05-01 10:48:17 -07:00
parent e9e26c981a
commit d60a0bee9e
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
2 changed files with 11 additions and 10 deletions

View File

@ -18,7 +18,6 @@
package baritone.pathing.movement; package baritone.pathing.movement;
import baritone.Baritone; import baritone.Baritone;
import baritone.api.BaritoneAPI;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.pathing.movement.ActionCosts; import baritone.api.pathing.movement.ActionCosts;
import baritone.api.pathing.movement.MovementStatus; import baritone.api.pathing.movement.MovementStatus;
@ -353,6 +352,9 @@ public interface MovementHelper extends ActionCosts, Helper {
static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, IBlockState state, boolean includeFalling) { static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, IBlockState state, boolean includeFalling) {
Block block = state.getBlock(); Block block = state.getBlock();
if (!canWalkThrough(context.bsi, x, y, z, state)) { if (!canWalkThrough(context.bsi, x, y, z, state)) {
if (block instanceof BlockLiquid) {
return COST_INF;
}
double mult = context.breakCostMultiplierAt(x, y, z); double mult = context.breakCostMultiplierAt(x, y, z);
if (mult >= COST_INF) { if (mult >= COST_INF) {
return COST_INF; return COST_INF;
@ -360,16 +362,11 @@ public interface MovementHelper extends ActionCosts, Helper {
if (avoidBreaking(context.bsi, x, y, z, state)) { if (avoidBreaking(context.bsi, x, y, z, state)) {
return COST_INF; return COST_INF;
} }
if (block instanceof BlockLiquid) {
return COST_INF;
}
double m = Baritone.settings().blocksToAvoidBreaking.value.contains(block) ? 10 : 1;
double strVsBlock = context.toolSet.getStrVsBlock(state); double strVsBlock = context.toolSet.getStrVsBlock(state);
if (strVsBlock <= 0) { if (strVsBlock <= 0) {
return COST_INF; return COST_INF;
} }
double result = 1 / strVsBlock;
double result = m / strVsBlock;
result += context.breakBlockAdditionalCost; result += context.breakBlockAdditionalCost;
result *= mult; result *= mult;
if (includeFalling) { if (includeFalling) {

View File

@ -65,10 +65,10 @@ public class ToolSet {
} }
/** /**
* Using the best tool on the hotbar, how long would it take to mine this block * Using the best tool on the hotbar, how fast we can mine this block
* *
* @param state the blockstate to be mined * @param state the blockstate to be mined
* @return how long it would take in ticks * @return the speed of how fast we'll mine it. 1/(time in ticks)
*/ */
public double getStrVsBlock(IBlockState state) { public double getStrVsBlock(IBlockState state) {
return breakStrengthCache.computeIfAbsent(state.getBlock(), backendCalculation); return breakStrengthCache.computeIfAbsent(state.getBlock(), backendCalculation);
@ -128,7 +128,11 @@ public class ToolSet {
*/ */
private double getBestDestructionTime(Block b) { private double getBestDestructionTime(Block b) {
ItemStack stack = player.inventory.getStackInSlot(getBestSlot(b)); ItemStack stack = player.inventory.getStackInSlot(getBestSlot(b));
return calculateSpeedVsBlock(stack, b.getDefaultState()); return calculateSpeedVsBlock(stack, b.getDefaultState()) * avoidanceMultiplier(b);
}
private double avoidanceMultiplier(Block b) {
return Baritone.settings().blocksToAvoidBreaking.value.contains(b) ? 0.1 : 1;
} }
/** /**