forked from RepoMirrors/baritone
Merge pull request #894 from LoganDark/prefer-silk-touch
Setting to prefer silk touch, fixes #883
This commit is contained in:
commit
3e3df0b493
|
@ -597,6 +597,12 @@ public final class Settings {
|
||||||
public final Setting<Boolean> prefixControl = new Setting<>(true);
|
public final Setting<Boolean> prefixControl = new Setting<>(true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Always prefer silk touch tools over regular tools. This will not sacrifice speed, but it will always prefer silk
|
||||||
|
* touch tools over other tools of the same speed. This includes always choosing ANY silk touch tool over your hand.
|
||||||
|
*/
|
||||||
|
public final Setting<Boolean> preferSilkTouch = new Setting<>(false);
|
||||||
|
|
||||||
|
/*
|
||||||
* Censor coordinates in goals and block positions
|
* Censor coordinates in goals and block positions
|
||||||
*/
|
*/
|
||||||
public final Setting<Boolean> censorCoordinates = new Setting<>(false);
|
public final Setting<Boolean> censorCoordinates = new Setting<>(false);
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
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;
|
||||||
|
@ -408,7 +409,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||||
* @param b the blockstate to mine
|
* @param b the blockstate to mine
|
||||||
*/
|
*/
|
||||||
static void switchToBestToolFor(IPlayerContext ctx, IBlockState b) {
|
static void switchToBestToolFor(IPlayerContext ctx, IBlockState b) {
|
||||||
switchToBestToolFor(ctx, b, new ToolSet(ctx.player()));
|
switchToBestToolFor(ctx, b, new ToolSet(ctx.player()), BaritoneAPI.getSettings().preferSilkTouch.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -418,8 +419,8 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||||
* @param b the blockstate to mine
|
* @param b the blockstate to mine
|
||||||
* @param ts previously calculated ToolSet
|
* @param ts previously calculated ToolSet
|
||||||
*/
|
*/
|
||||||
static void switchToBestToolFor(IPlayerContext ctx, IBlockState b, ToolSet ts) {
|
static void switchToBestToolFor(IPlayerContext ctx, IBlockState b, ToolSet ts, boolean preferSilkTouch) {
|
||||||
ctx.player().inventory.currentItem = ts.getBestSlot(b.getBlock());
|
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) {
|
||||||
|
|
|
@ -90,30 +90,39 @@ public class ToolSet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasSilkTouch(ItemStack stack) {
|
||||||
|
return EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate which tool on the hotbar is best for mining
|
* Calculate which tool on the hotbar is best for mining
|
||||||
*
|
*
|
||||||
* @param b the blockstate to be mined
|
* @param b the blockstate to be mined
|
||||||
* @return A byte containing the index in the tools array that worked best
|
* @return A byte containing the index in the tools array that worked best
|
||||||
*/
|
*/
|
||||||
public byte getBestSlot(Block b) {
|
public byte getBestSlot(Block b, boolean preferSilkTouch) {
|
||||||
byte best = 0;
|
byte best = 0;
|
||||||
double value = Double.NEGATIVE_INFINITY;
|
double highestSpeed = Double.NEGATIVE_INFINITY;
|
||||||
int materialCost = Integer.MIN_VALUE;
|
int lowestCost = Integer.MIN_VALUE;
|
||||||
|
boolean bestSilkTouch = false;
|
||||||
IBlockState blockState = b.getDefaultState();
|
IBlockState blockState = b.getDefaultState();
|
||||||
for (byte i = 0; i < 9; i++) {
|
for (byte i = 0; i < 9; i++) {
|
||||||
ItemStack itemStack = player.inventory.getStackInSlot(i);
|
ItemStack itemStack = player.inventory.getStackInSlot(i);
|
||||||
double v = calculateSpeedVsBlock(itemStack, blockState);
|
double speed = calculateSpeedVsBlock(itemStack, blockState);
|
||||||
if (v > value) {
|
boolean silkTouch = hasSilkTouch(itemStack);
|
||||||
value = v;
|
if (speed > highestSpeed) {
|
||||||
|
highestSpeed = speed;
|
||||||
best = i;
|
best = i;
|
||||||
materialCost = getMaterialCost(itemStack);
|
lowestCost = getMaterialCost(itemStack);
|
||||||
} else if (v == value) {
|
bestSilkTouch = silkTouch;
|
||||||
int c = getMaterialCost(itemStack);
|
} else if (speed == highestSpeed) {
|
||||||
if (c < materialCost) {
|
int cost = getMaterialCost(itemStack);
|
||||||
value = v;
|
if ((cost < lowestCost && (silkTouch || !bestSilkTouch)) ||
|
||||||
|
(preferSilkTouch && !bestSilkTouch && silkTouch)) {
|
||||||
|
highestSpeed = speed;
|
||||||
best = i;
|
best = i;
|
||||||
materialCost = c;
|
lowestCost = cost;
|
||||||
|
bestSilkTouch = silkTouch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,7 +136,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));
|
ItemStack stack = player.inventory.getStackInSlot(getBestSlot(b, false));
|
||||||
return calculateSpeedVsBlock(stack, b.getDefaultState()) * avoidanceMultiplier(b);
|
return calculateSpeedVsBlock(stack, b.getDefaultState()) * avoidanceMultiplier(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue