diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/Excavator.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/Excavator.java index 34f48d4b1e..fe121020e7 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/Excavator.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/Excavator.java @@ -11,14 +11,17 @@ import meteordevelopment.meteorclient.events.meteor.KeyEvent; import meteordevelopment.meteorclient.events.meteor.MouseButtonEvent; import meteordevelopment.meteorclient.events.render.Render3DEvent; +import meteordevelopment.meteorclient.events.world.TickEvent; import meteordevelopment.meteorclient.renderer.ShapeMode; import meteordevelopment.meteorclient.settings.*; import meteordevelopment.meteorclient.systems.modules.Categories; import meteordevelopment.meteorclient.systems.modules.Module; +import meteordevelopment.meteorclient.systems.modules.Modules; import meteordevelopment.meteorclient.utils.misc.Keybind; import meteordevelopment.meteorclient.utils.misc.input.KeyAction; import meteordevelopment.meteorclient.utils.render.color.SettingColor; import meteordevelopment.orbit.EventHandler; +import net.minecraft.item.ItemStack; import net.minecraft.util.hit.BlockHitResult; import org.lwjgl.glfw.GLFW; @@ -50,6 +53,13 @@ public class Excavator extends Module { .build() ); + private final Setting disableLowDura = sgGeneral.add(new BoolSetting.Builder() + .name("disable-low-dura") + .description("Disable the module when your main hand tool has < 100 durability to prevent it from breaking.") + .defaultValue(false) + .build() + ); + // Rendering private final Setting shapeMode = sgRendering.add(new EnumSetting.Builder() .name("shape-mode") @@ -75,6 +85,7 @@ public class Excavator extends Module { private enum Status { SEL_START, SEL_END, + READY_TO_WORK, // New state WORKING } @@ -92,6 +103,30 @@ public void onDeactivate() { status = Status.SEL_START; } + @EventHandler + private void onTick(TickEvent.Post event) { + if (disableLowDura.get()) { + if (isToolLowDurability()) { + info("Tool durability is below 100, stopping Excavator to prevent breaking."); + toggle(); + return; + } + } + + if (status == Status.READY_TO_WORK && !baritone.getBuilderProcess().isActive()) { + baritone.getBuilderProcess().clearArea(start, end); + status = Status.WORKING; + } + } + + private boolean isToolLowDurability() { + ItemStack mainHandStack = mc.player.getMainHandStack(); + if (mainHandStack.isEmpty() || !mainHandStack.isDamageable()) { + return false; + } + return mainHandStack.getMaxDamage() - mainHandStack.getDamage() < 100; + } + @EventHandler private void onMouseButton(MouseButtonEvent event) { if (event.action != KeyAction.Press || !selectionBind.get().isPressed() || mc.currentScreen != null) { @@ -119,12 +154,11 @@ private void selectCorners() { } } else if (status == Status.SEL_END) { end = BetterBlockPos.from(result.getBlockPos()); - status = Status.WORKING; + status = Status.READY_TO_WORK; if (logSelection.get()) { info("End corner set: (%d, %d, %d)".formatted(end.getX(), end.getY(), end.getZ())); } baritone.getSelectionManager().addSelection(start, end); - baritone.getBuilderProcess().clearArea(start, end); } } @@ -133,11 +167,15 @@ private void onRender3D(Render3DEvent event) { if (status == Status.SEL_START || status == Status.SEL_END) { if (!(mc.crosshairTarget instanceof BlockHitResult result)) return; event.renderer.box(result.getBlockPos(), sideColor.get(), lineColor.get(), shapeMode.get(), 0); - } else if (status == Status.WORKING && !baritone.getBuilderProcess().isActive()) { - if (keepActive.get()) { + } else if (status == Status.WORKING) { + if (!baritone.getBuilderProcess().isActive()) { baritone.getSelectionManager().removeSelection(baritone.getSelectionManager().getLastSelection()); - status = Status.SEL_START; - } else toggle(); + if (keepActive.get()) { + status = Status.SEL_START; + } else { + toggle(); + } + } } } -} +} \ No newline at end of file