From 4b2718dce782ab48df427d41bbfd7b3f01aaa1ab Mon Sep 17 00:00:00 2001 From: Big Iron <52252627+Big-Iron-Cheems@users.noreply.github.com> Date: Thu, 10 Aug 2023 00:06:23 +0200 Subject: [PATCH] Add excavator module (#3873) --- .../meteorclient/systems/modules/Modules.java | 1 + .../systems/modules/world/Excavator.java | 143 ++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 src/main/java/meteordevelopment/meteorclient/systems/modules/world/Excavator.java diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/Modules.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/Modules.java index baf104c181..6a10a6f29b 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/Modules.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/Modules.java @@ -529,6 +529,7 @@ private void initWorld() { add(new BuildHeight()); add(new EChestFarmer()); add(new EndermanLook()); + add(new Excavator()); add(new Flamethrower()); add(new InfinityMiner()); add(new LiquidFiller()); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/Excavator.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/Excavator.java new file mode 100644 index 0000000000..5f2f38a312 --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/Excavator.java @@ -0,0 +1,143 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.systems.modules.world; + +import baritone.api.BaritoneAPI; +import baritone.api.IBaritone; +import baritone.api.utils.BetterBlockPos; +import meteordevelopment.meteorclient.events.meteor.KeyEvent; +import meteordevelopment.meteorclient.events.meteor.MouseButtonEvent; +import meteordevelopment.meteorclient.events.render.Render3DEvent; +import meteordevelopment.meteorclient.renderer.ShapeMode; +import meteordevelopment.meteorclient.settings.*; +import meteordevelopment.meteorclient.systems.modules.Categories; +import meteordevelopment.meteorclient.systems.modules.Module; +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.util.hit.BlockHitResult; +import org.lwjgl.glfw.GLFW; + +public class Excavator extends Module { + private final IBaritone baritone = BaritoneAPI.getProvider().getPrimaryBaritone(); + private final SettingGroup sgGeneral = settings.getDefaultGroup(); + private final SettingGroup sgRendering = settings.createGroup("Rendering"); + + // Keybindings + private final Setting selectionKey = sgGeneral.add(new KeybindSetting.Builder() + .name("selection-key") + .description("Key to draw the selection.") + .defaultValue(Keybind.fromButton(GLFW.GLFW_MOUSE_BUTTON_RIGHT)) + .build() + ); + + // Logging + private final Setting logSelection = sgGeneral.add(new BoolSetting.Builder() + .name("log-selection") + .description("Logs the selection coordinates to the chat.") + .defaultValue(true) + .build() + ); + + private final Setting keepActive = sgGeneral.add(new BoolSetting.Builder() + .name("keep-active") + .description("Keep the module active after finishing the excavation.") + .defaultValue(false) + .build() + ); + + // Rendering + private final Setting shapeMode = sgRendering.add(new EnumSetting.Builder() + .name("shape-mode") + .description("How the shapes are rendered.") + .defaultValue(ShapeMode.Both) + .build() + ); + + private final Setting sideColor = sgRendering.add(new ColorSetting.Builder() + .name("side-color") + .description("The side color.") + .defaultValue(new SettingColor(255, 255, 255, 50)) + .build() + ); + + private final Setting lineColor = sgRendering.add(new ColorSetting.Builder() + .name("line-color") + .description("The line color.") + .defaultValue(new SettingColor(255, 255, 255, 255)) + .build() + ); + + private enum Status { + SEL_START, + SEL_END, + WORKING + } + + private Status status = Status.SEL_START; + private BetterBlockPos start, end; + + public Excavator() { + super(Categories.World, "excavator", "Excavate a selection area."); + } + + @Override + public void onDeactivate() { + baritone.getSelectionManager().removeSelection(baritone.getSelectionManager().getLastSelection()); + if (baritone.getBuilderProcess().isActive()) baritone.getCommandManager().execute("stop"); + status = Status.SEL_START; + } + + @EventHandler + private void onMouseButton(MouseButtonEvent event) { + if (event.action != KeyAction.Press || event.button != selectionKey.get().getValue() || mc.currentScreen != null) { + return; + } + selectCorners(); + } + + @EventHandler + private void onKey(KeyEvent event) { + if (event.action != KeyAction.Press || event.key != selectionKey.get().getValue() || mc.currentScreen != null) { + return; + } + selectCorners(); + } + + private void selectCorners() { + if (!(mc.crosshairTarget instanceof BlockHitResult result)) return; + + if (status == Status.SEL_START) { + start = BetterBlockPos.from(result.getBlockPos()); + status = Status.SEL_END; + if (logSelection.get()) { + info("Start corner set: (%d, %d, %d)".formatted(start.getX(), start.getY(), start.getZ())); + } + } else if (status == Status.SEL_END) { + end = BetterBlockPos.from(result.getBlockPos()); + status = Status.WORKING; + 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); + } + } + + @EventHandler + 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()) { + baritone.getSelectionManager().removeSelection(baritone.getSelectionManager().getLastSelection()); + status = Status.SEL_START; + } else toggle(); + } + } +}