Merge pull request #1947 from RealIndrit/master

Add auto tool setting
This commit is contained in:
Leijurv 2020-08-17 15:57:37 -07:00 committed by GitHub
commit f0d2bae3d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 3 deletions

View File

@ -61,6 +61,21 @@ public final class Settings {
*/ */
public final Setting<Boolean> allowInventory = new Setting<>(false); public final Setting<Boolean> allowInventory = new Setting<>(false);
/**
* Allow player to decide if to use auto tool or not
*/
public final Setting<Boolean> autoTool = new Setting<>(true);
/**
* Should movement cost calculation ignore the cost of breaking blocks with current slot, and assume best possible
* item in the hotbar?
*
* Only use this if actually necessary, make sure to put this back to original state (false), or it
* might mess up pathing in some combinations with auto tool setting. (just fall back to original settings if any
* problems occurs)
*/
public final Setting<Boolean> ignoreAutoToolMovementCost = new Setting<>(false);
/** /**
* It doesn't actually take twenty ticks to place a block, this cost is so high * It doesn't actually take twenty ticks to place a block, this cost is so high
* because we want to generally conserve blocks which might be limited. * because we want to generally conserve blocks which might be limited.

View File

@ -432,7 +432,9 @@ public interface MovementHelper extends ActionCosts, Helper {
* @param ts previously calculated ToolSet * @param ts previously calculated ToolSet
*/ */
static void switchToBestToolFor(IPlayerContext ctx, IBlockState b, ToolSet ts, boolean preferSilkTouch) { static void switchToBestToolFor(IPlayerContext ctx, IBlockState b, ToolSet ts, boolean preferSilkTouch) {
ctx.player().inventory.currentItem = ts.getBestSlot(b.getBlock(), preferSilkTouch); if (Baritone.settings().autoTool.value) {
ctx.player().inventory.currentItem = ts.getBestSlot(b.getBlock(), preferSilkTouch);
}
} }
static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) { static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) {

View File

@ -96,12 +96,27 @@ public class ToolSet {
} }
/** /**
* Calculate which tool on the hotbar is best for mining * Calculate which tool on the hotbar is best for mining, depending on an override setting,
* related to auto tool movement cost, it will either return current selected slot, or the best slot.
* *
* @param b the blockstate to be mined * @param b the blockstate to be mined
* @return An int containing the index in the tools array that worked best * @return An int containing the index in the tools array that worked best
*/ */
public int getBestSlot(Block b, boolean preferSilkTouch) { public int getBestSlot(Block b, boolean preferSilkTouch) {
return getBestSlot(b, preferSilkTouch, false);
}
public int getBestSlot(Block b, boolean preferSilkTouch, boolean pathingCalculation) {
/*
If we actually want know what efficiency our held item has instead of the best one
possible, this lets us make pathing depending on the actual tool used (if auto tool is disabled)
*/
if (!Baritone.settings().ignoreAutoToolMovementCost.value && pathingCalculation) {
return player.inventory.currentItem;
}
int best = 0; int best = 0;
double highestSpeed = Double.NEGATIVE_INFINITY; double highestSpeed = Double.NEGATIVE_INFINITY;
int lowestCost = Integer.MIN_VALUE; int lowestCost = Integer.MIN_VALUE;
@ -137,7 +152,7 @@ public class ToolSet {
* @return A double containing the destruction ticks with the best tool * @return A double containing the destruction ticks with the best tool
*/ */
private double getBestDestructionTime(Block b) { private double getBestDestructionTime(Block b) {
ItemStack stack = player.inventory.getStackInSlot(getBestSlot(b, false)); ItemStack stack = player.inventory.getStackInSlot(getBestSlot(b, false, true));
return calculateSpeedVsBlock(stack, b.getDefaultState()) * avoidanceMultiplier(b); return calculateSpeedVsBlock(stack, b.getDefaultState()) * avoidanceMultiplier(b);
} }