From 4aa52d2f2ef02875c73f1ff258ddc39b9651ebf7 Mon Sep 17 00:00:00 2001 From: scorbett123 Date: Sat, 24 Oct 2020 18:03:29 +0100 Subject: [PATCH] add itemSaver setting. Signed-off-by: scorbett123 --- src/api/java/baritone/api/Settings.java | 5 +++++ src/main/java/baritone/utils/ToolSet.java | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 9cabe083..129c418d 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -684,6 +684,11 @@ public final class Settings { */ public final Setting censorRanCommands = new Setting<>(false); + /** + * Stop using tools just before they are going to break. + */ + public final Setting itemSaver = new Setting<>(false); + /** * 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. diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index aa8819ce..798420f9 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -18,6 +18,7 @@ package baritone.utils; import baritone.Baritone; +import baritone.api.utils.Helper; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.entity.EntityPlayerSP; @@ -124,6 +125,9 @@ public class ToolSet { IBlockState blockState = b.getDefaultState(); for (int i = 0; i < 9; i++) { ItemStack itemStack = player.inventory.getStackInSlot(i); + if (itemStack.getItemDamage() >= itemStack.getMaxDamage() - 1 && Baritone.settings().itemSaver.value) { + continue; + } double speed = calculateSpeedVsBlock(itemStack, blockState); boolean silkTouch = hasSilkTouch(itemStack); if (speed > highestSpeed) {