baritone
baritone copied to clipboard
farm: Fortune support
I'm trying to add Fortune support to .b farm.
Since breaking 0-hardness crops (i.e. Wheat, Carrots, Potatoes, and Nether Wart) does not use a tool's durability, should I selectively ignore the cost ca. the else if statement here in order to prefer (e.g.) a Golden Hoe with Fortune 3 over a Netherite Pickaxe which would otherwise have been preferred due to its having Silk Touch, for mining those blocks in particular?
Or should this logic be injected directly into FarmProcess.java#PathingCommand, instead?
Fortune does not affect Cocoa, and is arguably inferior to Silk Touch for most farming workflows involving Melons; both of these blocks have a nonzero hardness, however, so would not be affected by this patch.
I think that the way that enchantments are chosen probably needs to be redone to allow the user to pick a prefered enchantment, this would mean fortune could be preferred when, for example, you mine diamonds.
I got this working, its not perfect: Baritone will always prefer fortune enchanted tools whenever it needs to break something
public int getBestSlot(Block b, boolean preferSilkTouch, boolean pathingCalculation) {
if (!Baritone.settings().autoTool.value && pathingCalculation) {
return player.inventory.currentItem;
}
int best = 0;
double highestSpeed = Double.NEGATIVE_INFINITY;
int lowestCost = Integer.MAX_VALUE;
boolean bestSilkTouch = false;
int bestFortune = Integer.MIN_VALUE;
int bestUnbreaking = Integer.MIN_VALUE;
IBlockState blockState = b.getDefaultState();
for (int i = 0; i < 9; i++) {
ItemStack itemStack = player.inventory.getStackInSlot(i);
if (!Baritone.settings().useSwordToMine.value && itemStack.getItem() instanceof ItemSword) {
continue;
}
if (Baritone.settings().itemSaver.value && (itemStack.getItemDamage() + Baritone.settings().itemSaverThreshold.value) >= itemStack.getMaxDamage() && itemStack.getMaxDamage() > 1) {
continue;
}
double speed = calculateSpeedVsBlock(itemStack, blockState);
boolean silkTouch = hasSilkTouch(itemStack);
int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, itemStack); //See: https://nekoyue.github.io/ForgeJavaDocs-NG/javadoc/1.12.2/
int unbreaking = EnchantmentHelper.getEnchantmentLevel(Enchantments.UNBREAKING, itemStack);
if (speed > highestSpeed) {
highestSpeed = speed;
best = i;
lowestCost = getMaterialCost(itemStack);
bestSilkTouch = silkTouch;
bestFortune = fortune;
} else if (speed == highestSpeed) {
int cost = getMaterialCost(itemStack);
if (preferSilkTouch && !bestSilkTouch && silkTouch) {
best = i;
lowestCost = cost;
bestSilkTouch = silkTouch;
bestFortune = fortune;
} else if (silkTouch == bestSilkTouch) {
if (cost < lowestCost) {
best = i;
lowestCost = cost;
bestFortune = fortune;
} else if (cost == lowestCost && fortune > bestFortune) {
best = i;
bestFortune = fortune;
}
}
}
}
return best;
}