diff --git a/build.gradle b/build.gradle index f5e73bea45..cb542a93da 100644 --- a/build.gradle +++ b/build.gradle @@ -58,7 +58,7 @@ dependencies { modCompileOnly("maven.modrinth:indium:${project.indium_version}") { transitive = false } // Baritone (https://github.com/MeteorDevelopment/baritone) - modInclude "baritone:fabric:${project.minecraft_version}-SNAPSHOT" + modCompileOnly "meteordevelopment:baritone:${project.minecraft_version}-SNAPSHOT" // Libraries library "meteordevelopment:orbit:${project.orbit_version}" diff --git a/src/main/java/meteordevelopment/meteorclient/commands/Commands.java b/src/main/java/meteordevelopment/meteorclient/commands/Commands.java index fbae5aac16..6550ce95d9 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/Commands.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/Commands.java @@ -8,6 +8,7 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.exceptions.CommandSyntaxException; import meteordevelopment.meteorclient.commands.commands.*; +import meteordevelopment.meteorclient.pathing.PathManagers; import meteordevelopment.meteorclient.utils.PostInit; import net.minecraft.client.network.ClientCommandSource; import net.minecraft.command.CommandSource; @@ -23,7 +24,7 @@ public class Commands { public static final CommandSource COMMAND_SOURCE = new ClientCommandSource(null, mc); public static final List COMMANDS = new ArrayList<>(); - @PostInit + @PostInit(dependencies = PathManagers.class) public static void init() { add(new VClipCommand()); add(new HClipCommand()); @@ -35,7 +36,6 @@ public static void init() { add(new FriendsCommand()); add(new CommandsCommand()); add(new InventoryCommand()); - add(new LocateCommand()); add(new NbtCommand()); add(new NotebotCommand()); add(new PeekCommand()); @@ -61,6 +61,7 @@ public static void init() { add(new RotationCommand()); add(new WaypointCommand()); add(new InputCommand()); + add(new LocateCommand()); COMMANDS.sort(Comparator.comparing(Command::getName)); } diff --git a/src/main/java/meteordevelopment/meteorclient/commands/commands/LocateCommand.java b/src/main/java/meteordevelopment/meteorclient/commands/commands/LocateCommand.java index 241bc6cad9..fbddc68791 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/commands/LocateCommand.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/commands/LocateCommand.java @@ -10,6 +10,8 @@ import meteordevelopment.meteorclient.MeteorClient; import meteordevelopment.meteorclient.commands.Command; import meteordevelopment.meteorclient.events.packets.PacketEvent; +import meteordevelopment.meteorclient.pathing.BaritoneUtils; +import meteordevelopment.meteorclient.pathing.PathManagers; import meteordevelopment.meteorclient.utils.player.ChatUtils; import meteordevelopment.meteorclient.utils.player.InvUtils; import meteordevelopment.orbit.EventHandler; @@ -17,6 +19,7 @@ import net.minecraft.block.Blocks; import net.minecraft.command.CommandSource; import net.minecraft.entity.EntityType; +import net.minecraft.entity.EyeOfEnderEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.nbt.NbtCompound; @@ -143,10 +146,15 @@ public void build(LiteralArgumentBuilder builder) { })); builder.then(literal("stronghold").executes(s -> { + if (!BaritoneUtils.IS_AVAILABLE) { + error("Locating this structure requires Baritone."); + return SINGLE_SUCCESS; + } + boolean foundEye = InvUtils.testInHotbar(Items.ENDER_EYE); if (foundEye) { - BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager().execute("follow entity minecraft:eye_of_ender"); + PathManagers.get().follow(entity -> entity instanceof EyeOfEnderEntity); firstStart = null; firstEnd = null; secondStart = null; @@ -168,6 +176,11 @@ public void build(LiteralArgumentBuilder builder) { })); builder.then(literal("nether_fortress").executes(s -> { + if (!BaritoneUtils.IS_AVAILABLE) { + error("Locating this structure requires Baritone."); + return SINGLE_SUCCESS; + } + Vec3d coords = findByBlockList(netherFortressBlocks); if (coords == null) { error("No nether fortress found."); @@ -181,6 +194,11 @@ public void build(LiteralArgumentBuilder builder) { })); builder.then(literal("monument").executes(s -> { + if (!BaritoneUtils.IS_AVAILABLE) { + error("Locating this structure requires Baritone."); + return SINGLE_SUCCESS; + } + ItemStack stack = mc.player.getInventory().getMainHandStack(); if (stack.getItem() == Items.FILLED_MAP) { NbtCompound tag = stack.getNbt(); @@ -271,7 +289,8 @@ private void lastPosition(double x, double y, double z) { } private void findStronghold() { - BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager().execute("stop"); + PathManagers.get().stop(); + if (this.firstStart == null || this.firstEnd == null || this.secondStart == null || this.secondEnd == null) { error("Missing position data"); cancel(); diff --git a/src/main/java/meteordevelopment/meteorclient/commands/commands/SwarmCommand.java b/src/main/java/meteordevelopment/meteorclient/commands/commands/SwarmCommand.java index 8ce4ec004e..fda2554682 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/commands/SwarmCommand.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/commands/SwarmCommand.java @@ -5,8 +5,6 @@ package meteordevelopment.meteorclient.commands.commands; -import baritone.api.BaritoneAPI; -import baritone.api.pathing.goals.GoalXZ; import com.mojang.brigadier.arguments.BoolArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; @@ -15,6 +13,7 @@ import meteordevelopment.meteorclient.commands.Command; import meteordevelopment.meteorclient.commands.arguments.ModuleArgumentType; import meteordevelopment.meteorclient.commands.arguments.PlayerArgumentType; +import meteordevelopment.meteorclient.pathing.PathManagers; import meteordevelopment.meteorclient.systems.modules.Module; import meteordevelopment.meteorclient.systems.modules.Modules; import meteordevelopment.meteorclient.systems.modules.misc.swarm.Swarm; @@ -27,6 +26,7 @@ import net.minecraft.command.argument.BlockStateArgumentType; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.text.Text; +import net.minecraft.util.math.BlockPos; import java.util.List; import java.util.Random; @@ -124,7 +124,7 @@ else if (swarm.isWorker()) { swarm.host.sendMessage(context.getInput()); } else if (swarm.isWorker() && playerEntity != null) { - BaritoneAPI.getProvider().getPrimaryBaritone().getFollowProcess().follow(entity -> entity.getEntityName().equalsIgnoreCase(playerEntity.getEntityName())); + PathManagers.get().follow(entity -> entity.getEntityName().equalsIgnoreCase(playerEntity.getEntityName())); } } else { @@ -146,7 +146,7 @@ else if (swarm.isWorker()) { int x = IntegerArgumentType.getInteger(context, "x"); int z = IntegerArgumentType.getInteger(context, "z"); - BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(new GoalXZ(x, z)); + PathManagers.get().moveTo(new BlockPos(x, 0, z), true); } } else { @@ -330,7 +330,7 @@ else if (swarm.isWorker()) { if (swarm.isHost()) { swarm.host.sendMessage(context.getInput()); } else if (swarm.isWorker()) { - BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().cancelEverything(); + PathManagers.get().stop(); } } else { throw SWARM_NOT_ACTIVE.create(); @@ -362,11 +362,13 @@ private void runInfinityMiner() { private void scatter(int radius) { Random random = new Random(); + double a = random.nextDouble() * 2 * Math.PI; double r = radius * Math.sqrt(random.nextDouble()); double x = mc.player.getX() + r * Math.cos(a); double z = mc.player.getZ() + r * Math.sin(a); - BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().cancelEverything(); - BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(new GoalXZ((int) x, (int) z)); + + PathManagers.get().stop(); + PathManagers.get().moveTo(new BlockPos((int) x, 0, (int) z), true); } } diff --git a/src/main/java/meteordevelopment/meteorclient/gui/tabs/Tabs.java b/src/main/java/meteordevelopment/meteorclient/gui/tabs/Tabs.java index 237466fcc4..704eb5989e 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/tabs/Tabs.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/tabs/Tabs.java @@ -6,6 +6,8 @@ package meteordevelopment.meteorclient.gui.tabs; import meteordevelopment.meteorclient.gui.tabs.builtin.*; +import meteordevelopment.meteorclient.pathing.BaritoneUtils; +import meteordevelopment.meteorclient.pathing.PathManagers; import meteordevelopment.meteorclient.utils.PreInit; import java.util.ArrayList; @@ -14,7 +16,7 @@ public class Tabs { private static final List tabs = new ArrayList<>(); - @PreInit + @PreInit(dependencies = PathManagers.class) public static void init() { add(new ModulesTab()); add(new ConfigTab()); @@ -23,7 +25,10 @@ public static void init() { add(new FriendsTab()); add(new MacrosTab()); add(new ProfilesTab()); - add(new BaritoneTab()); + + if (PathManagers.get().getSettings().get().sizeGroups() > 0) { + add(new PathManagerTab()); + } } public static void add(Tab tab) { diff --git a/src/main/java/meteordevelopment/meteorclient/gui/tabs/builtin/PathManagerTab.java b/src/main/java/meteordevelopment/meteorclient/gui/tabs/builtin/PathManagerTab.java new file mode 100644 index 0000000000..404dd529ee --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/gui/tabs/builtin/PathManagerTab.java @@ -0,0 +1,59 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.gui.tabs.builtin; + +import baritone.api.BaritoneAPI; +import baritone.api.utils.SettingsUtil; +import meteordevelopment.meteorclient.gui.GuiTheme; +import meteordevelopment.meteorclient.gui.tabs.Tab; +import meteordevelopment.meteorclient.gui.tabs.TabScreen; +import meteordevelopment.meteorclient.gui.tabs.WindowTabScreen; +import meteordevelopment.meteorclient.gui.widgets.input.WTextBox; +import meteordevelopment.meteorclient.pathing.PathManagers; +import net.minecraft.client.gui.screen.Screen; + +public class PathManagerTab extends Tab { + public PathManagerTab() { + super(PathManagers.get().getName()); + } + + @Override + public TabScreen createScreen(GuiTheme theme) { + return new PathManagerScreen(theme, this); + } + + @Override + public boolean isScreen(Screen screen) { + return screen instanceof PathManagerScreen; + } + + private static class PathManagerScreen extends WindowTabScreen { + public PathManagerScreen(GuiTheme theme, Tab tab) { + super(theme, tab); + + PathManagers.get().getSettings().get().onActivated(); + } + + @Override + public void initWidgets() { + WTextBox filter = add(theme.textBox("")).minWidth(400).expandX().widget(); + filter.setFocused(true); + filter.action = () -> { + clear(); + + add(filter); + add(theme.settings(PathManagers.get().getSettings().get(), filter.get().trim())).expandX(); + }; + + add(theme.settings(PathManagers.get().getSettings().get(), filter.get().trim())).expandX(); + } + + @Override + protected void onClosed() { + SettingsUtil.save(BaritoneAPI.getSettings()); + } + } +} diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayNetworkHandlerMixin.java index e5858794f4..2e51e27d72 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayNetworkHandlerMixin.java @@ -19,6 +19,7 @@ import meteordevelopment.meteorclient.events.packets.PlaySoundPacketEvent; import meteordevelopment.meteorclient.events.world.ChunkDataEvent; import meteordevelopment.meteorclient.mixininterface.IExplosionS2CPacket; +import meteordevelopment.meteorclient.pathing.BaritoneUtils; import meteordevelopment.meteorclient.systems.config.Config; import meteordevelopment.meteorclient.systems.modules.Modules; import meteordevelopment.meteorclient.systems.modules.movement.Velocity; @@ -140,7 +141,7 @@ private void onItemPickupAnimation(ItemPickupAnimationS2CPacket packet, Callback private void onSendChatMessage(String message, CallbackInfo ci) { if (ignoreChatMessage) return; - if (!message.startsWith(Config.get().prefix.get()) && !message.startsWith(BaritoneAPI.getSettings().prefix.value)) { + if (!message.startsWith(Config.get().prefix.get()) && (BaritoneUtils.IS_AVAILABLE || !message.startsWith(BaritoneUtils.getPrefix()))) { SendMessageEvent event = MeteorClient.EVENT_BUS.post(SendMessageEvent.get(message)); if (!event.isCancelled()) { diff --git a/src/main/java/meteordevelopment/meteorclient/pathing/BaritonePathManager.java b/src/main/java/meteordevelopment/meteorclient/pathing/BaritonePathManager.java new file mode 100644 index 0000000000..408c7288f0 --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/pathing/BaritonePathManager.java @@ -0,0 +1,248 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.pathing; + +import baritone.api.BaritoneAPI; +import baritone.api.pathing.goals.Goal; +import baritone.api.pathing.goals.GoalGetToBlock; +import baritone.api.pathing.goals.GoalXZ; +import baritone.api.process.IBaritoneProcess; +import baritone.api.process.PathingCommand; +import baritone.api.process.PathingCommandType; +import baritone.api.utils.Rotation; +import baritone.api.utils.SettingsUtil; +import meteordevelopment.meteorclient.MeteorClient; +import meteordevelopment.meteorclient.events.world.TickEvent; +import meteordevelopment.orbit.EventHandler; +import meteordevelopment.orbit.EventPriority; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; +import java.lang.reflect.Field; +import java.util.function.Predicate; + +import static meteordevelopment.meteorclient.MeteorClient.mc; + +public class BaritonePathManager implements IPathManager { + private final VarHandle rotationField; + private final BaritoneSettings settings; + + private GoalDirection directionGoal; + private boolean pathingPaused; + + public BaritonePathManager() { + // Subscribe to event bus + MeteorClient.EVENT_BUS.subscribe(this); + + // Find rotation field + Class klass = BaritoneAPI.getProvider().getPrimaryBaritone().getLookBehavior().getClass(); + VarHandle rotationField = null; + + for (Field field : klass.getDeclaredFields()) { + if (field.getType() == Rotation.class) { + try { + rotationField = MethodHandles.lookup().unreflectVarHandle(field); + break; + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + + this.rotationField = rotationField; + + // Create settings + settings = new BaritoneSettings(); + + // Baritone pathing control + BaritoneAPI.getProvider().getPrimaryBaritone().getPathingControlManager().registerProcess(new BaritoneProcess()); + } + + @Override + public String getName() { + return "Baritone"; + } + + @Override + public boolean isPathing() { + return BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().isPathing(); + } + + @Override + public void pause() { + pathingPaused = true; + } + + @Override + public void resume() { + pathingPaused = false; + } + + @Override + public void stop() { + BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().cancelEverything(); + } + + @Override + public void moveTo(BlockPos pos, boolean ignoreY) { + if (ignoreY) { + BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(new GoalXZ(pos.getX(), pos.getZ())); + return; + } + + BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(new GoalGetToBlock(pos)); + } + + @Override + public void moveInDirection(float yaw) { + directionGoal = new GoalDirection(yaw); + BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(directionGoal); + } + + @Override + public void mine(Block... blocks) { + BaritoneAPI.getProvider().getPrimaryBaritone().getMineProcess().mine(blocks); + } + + @Override + public void follow(Predicate entity) { + BaritoneAPI.getProvider().getPrimaryBaritone().getFollowProcess().follow(entity); + } + + @Override + public float getTargetYaw() { + Rotation rotation = (Rotation) rotationField.get(BaritoneAPI.getProvider().getPrimaryBaritone().getLookBehavior()); + return rotation == null ? 0 : rotation.getYaw(); + } + + @Override + public float getTargetPitch() { + Rotation rotation = (Rotation) rotationField.get(BaritoneAPI.getProvider().getPrimaryBaritone().getLookBehavior()); + return rotation == null ? 0 : rotation.getPitch(); + } + + @Override + public ISettings getSettings() { + return settings; + } + + @EventHandler(priority = EventPriority.HIGHEST) + private void onTick(TickEvent.Pre event) { + if (directionGoal == null) return; + + if (directionGoal != BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().getGoal()) { + directionGoal = null; + return; + } + + directionGoal.tick(); + } + + private static class GoalDirection implements Goal { + private static final double SQRT_2 = Math.sqrt(2); + + private final float yaw; + private int x; + private int z; + + private int timer; + + public GoalDirection(float yaw) { + this.yaw = yaw; + tick(); + } + + public static double calculate(double xDiff, double zDiff) { + double x = Math.abs(xDiff); + double z = Math.abs(zDiff); + double straight; + double diagonal; + if (x < z) { + straight = z - x; + diagonal = x; + } else { + straight = x - z; + diagonal = z; + } + + diagonal *= SQRT_2; + return (diagonal + straight) * BaritoneAPI.getSettings().costHeuristic.value; + } + + public void tick() { + if (timer > 20) { + timer = 0; + + Vec3d pos = mc.player.getPos(); + float theta = (float) Math.toRadians(yaw); + + x = (int) Math.floor(pos.x - (double) MathHelper.sin(theta) * 100); + z = (int) Math.floor(pos.z + (double) MathHelper.cos(theta) * 100); + } + + timer++; + } + + public boolean isInGoal(int x, int y, int z) { + return x == this.x && z == this.z; + } + + public double heuristic(int x, int y, int z) { + int xDiff = x - this.x; + int zDiff = z - this.z; + return calculate(xDiff, zDiff); + } + + public String toString() { + return String.format("GoalXZ{x=%s,z=%s}", SettingsUtil.maybeCensor(this.x), SettingsUtil.maybeCensor(this.z)); + } + + public int getX() { + return this.x; + } + + public int getZ() { + return this.z; + } + } + + private class BaritoneProcess implements IBaritoneProcess { + @Override + public boolean isActive() { + return pathingPaused; + } + + @Override + public PathingCommand onTick(boolean b, boolean b1) { + BaritoneAPI.getProvider().getPrimaryBaritone().getInputOverrideHandler().clearAllKeys(); + return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); + } + + @Override + public boolean isTemporary() { + return true; + } + + @Override + public void onLostControl() { + } + + @Override + public double priority() { + return 0d; + } + + @Override + public String displayName0() { + return "Meteor Client"; + } + } +} diff --git a/src/main/java/meteordevelopment/meteorclient/gui/tabs/builtin/BaritoneTab.java b/src/main/java/meteordevelopment/meteorclient/pathing/BaritoneSettings.java similarity index 92% rename from src/main/java/meteordevelopment/meteorclient/gui/tabs/builtin/BaritoneTab.java rename to src/main/java/meteordevelopment/meteorclient/pathing/BaritoneSettings.java index 6514ee493f..c50c73345b 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/tabs/builtin/BaritoneTab.java +++ b/src/main/java/meteordevelopment/meteorclient/pathing/BaritoneSettings.java @@ -3,19 +3,12 @@ * Copyright (c) Meteor Development. */ -package meteordevelopment.meteorclient.gui.tabs.builtin; +package meteordevelopment.meteorclient.pathing; import baritone.api.BaritoneAPI; -import baritone.api.utils.SettingsUtil; -import meteordevelopment.meteorclient.gui.GuiTheme; -import meteordevelopment.meteorclient.gui.tabs.Tab; -import meteordevelopment.meteorclient.gui.tabs.TabScreen; -import meteordevelopment.meteorclient.gui.tabs.WindowTabScreen; -import meteordevelopment.meteorclient.gui.widgets.input.WTextBox; import meteordevelopment.meteorclient.settings.*; import meteordevelopment.meteorclient.utils.render.color.SettingColor; import net.minecraft.block.Block; -import net.minecraft.client.gui.screen.Screen; import net.minecraft.item.Item; import java.awt.*; @@ -26,20 +19,45 @@ import java.util.List; import java.util.Map; -public class BaritoneTab extends Tab { - private static Settings settings; - private static Map descriptions; +public class BaritoneSettings implements IPathManager.ISettings { + private final Settings settings = new Settings(); + + private Setting walkOnWater, walkOnLava; + private Setting step, noFall; - public BaritoneTab() { - super("Baritone"); + public BaritoneSettings() { + createWrappers(); } - @SuppressWarnings("unchecked") - private static Settings getSettings() { - if (settings != null) return settings; + @Override + public Settings get() { + return settings; + } - settings = new Settings(); + @Override + public Setting getWalkOnWater() { + return walkOnWater; + } + + @Override + public Setting getWalkOnLava() { + return walkOnLava; + } + + @Override + public Setting getStep() { + return step; + } + @Override + public Setting getNoFall() { + return noFall; + } + + // Wrappers + + @SuppressWarnings({"rawtypes", "unchecked"}) + private void createWrappers() { SettingGroup sgBool = settings.createGroup("Checkboxes"); SettingGroup sgDouble = settings.createGroup("Numbers"); SettingGroup sgInt = settings.createGroup("Whole Numbers"); @@ -51,6 +69,7 @@ private static Settings getSettings() { try { Class klass = BaritoneAPI.getSettings().getClass(); + for (Field field : klass.getDeclaredFields()) { Object obj = field.get(BaritoneAPI.getSettings()); if (!(obj instanceof baritone.api.Settings.Setting setting)) continue; @@ -58,7 +77,7 @@ private static Settings getSettings() { Object value = setting.value; if (value instanceof Boolean) { - sgBool.add(new BoolSetting.Builder() + Setting wrapper = sgBool.add(new BoolSetting.Builder() .name(setting.getName()) .description(getDescription(setting.getName())) .defaultValue((boolean) setting.defaultValue) @@ -66,7 +85,14 @@ private static Settings getSettings() { .onModuleActivated(booleanSetting -> booleanSetting.set((Boolean) setting.value)) .build() ); - } else if (value instanceof Double) { + + switch (wrapper.name) { + case "assumeWalkOnWater" -> walkOnWater = wrapper; + case "assumeWalkOnLava" -> walkOnLava = wrapper; + case "assumeStep" -> step = wrapper; + } + } + else if (value instanceof Double) { sgDouble.add(new DoubleSetting.Builder() .name(setting.getName()) .description(getDescription(setting.getName())) @@ -75,7 +101,8 @@ private static Settings getSettings() { .onModuleActivated(doubleSetting -> doubleSetting.set((Double) setting.value)) .build() ); - } else if (value instanceof Float) { + } + else if (value instanceof Float) { sgDouble.add(new DoubleSetting.Builder() .name(setting.getName()) .description(getDescription(setting.getName())) @@ -84,8 +111,9 @@ private static Settings getSettings() { .onModuleActivated(doubleSetting -> doubleSetting.set(((Float) setting.value).doubleValue())) .build() ); - } else if (value instanceof Integer) { - sgInt.add(new IntSetting.Builder() + } + else if (value instanceof Integer) { + Setting wrapper = sgInt.add(new IntSetting.Builder() .name(setting.getName()) .description(getDescription(setting.getName())) .defaultValue((int) setting.defaultValue) @@ -93,7 +121,18 @@ private static Settings getSettings() { .onModuleActivated(integerSetting -> integerSetting.set((Integer) setting.value)) .build() ); - } else if (value instanceof Long) { + + if (wrapper.name.equals("maxFallHeightNoWater")) { + noFall = new BoolSetting.Builder() + .name(wrapper.name) + .description(wrapper.description) + .defaultValue(false) + .onChanged(aBoolean -> wrapper.set(aBoolean ? 159159 : wrapper.getDefaultValue())) + .onModuleActivated(booleanSetting -> booleanSetting.set(wrapper.get() >= 255)) + .build(); + } + } + else if (value instanceof Long) { sgInt.add(new IntSetting.Builder() .name(setting.getName()) .description(getDescription(setting.getName())) @@ -102,7 +141,8 @@ private static Settings getSettings() { .onModuleActivated(integerSetting -> integerSetting.set(((Long) setting.value).intValue())) .build() ); - } else if (value instanceof String) { + } + else if (value instanceof String) { sgString.add(new StringSetting.Builder() .name(setting.getName()) .description(getDescription(setting.getName())) @@ -111,7 +151,8 @@ private static Settings getSettings() { .onModuleActivated(stringSetting -> stringSetting.set((String) setting.value)) .build() ); - } else if (value instanceof Color) { + } + else if (value instanceof Color) { Color c = (Color) setting.value; sgColor.add(new ColorSetting.Builder() @@ -122,7 +163,8 @@ private static Settings getSettings() { .onModuleActivated(colorSetting -> colorSetting.set(new SettingColor(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()))) .build() ); - } else if (value instanceof List) { + } + else if (value instanceof List) { Type listType = ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]; Type type = ((ParameterizedType) listType).getActualTypeArguments()[0]; @@ -135,7 +177,8 @@ private static Settings getSettings() { .onModuleActivated(blockListSetting -> blockListSetting.set((List) setting.value)) .build() ); - } else if (type == Item.class) { + } + else if (type == Item.class) { sgItemLists.add(new ItemListSetting.Builder() .name(setting.getName()) .description(getDescription(setting.getName())) @@ -147,22 +190,15 @@ private static Settings getSettings() { } } } - } catch (IllegalAccessException e) { - e.printStackTrace(); } - - return settings; + catch (IllegalAccessException e) { + throw new RuntimeException(e); + } } - @Override - public TabScreen createScreen(GuiTheme theme) { - return new BaritoneScreen(theme, this); - } + // Descriptions - @Override - public boolean isScreen(Screen screen) { - return screen instanceof BaritoneScreen; - } + private static Map descriptions; private static void addDescription(String settingName, String description) { descriptions.put(settingName.toLowerCase(), description); @@ -174,33 +210,6 @@ private static String getDescription(String settingName) { return descriptions.get(settingName.toLowerCase()); } - private static class BaritoneScreen extends WindowTabScreen { - public BaritoneScreen(GuiTheme theme, Tab tab) { - super(theme, tab); - - getSettings().onActivated(); - } - - @Override - public void initWidgets() { - WTextBox filter = add(theme.textBox("")).minWidth(400).expandX().widget(); - filter.setFocused(true); - filter.action = () -> { - clear(); - - add(filter); - add(theme.settings(getSettings(), filter.get().trim())).expandX(); - }; - - add(theme.settings(getSettings(), filter.get().trim())).expandX(); - } - - @Override - protected void onClosed() { - SettingsUtil.save(BaritoneAPI.getSettings()); - } - } - private static void loadDescriptions() { descriptions = new HashMap<>(); addDescription("acceptableThrowawayItems", "Blocks that Baritone is allowed to place (as throwaway, for sneak bridging, pillaring, etc.)"); diff --git a/src/main/java/meteordevelopment/meteorclient/pathing/BaritoneUtils.java b/src/main/java/meteordevelopment/meteorclient/pathing/BaritoneUtils.java new file mode 100644 index 0000000000..7830aafad9 --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/pathing/BaritoneUtils.java @@ -0,0 +1,20 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.pathing; + +import baritone.api.BaritoneAPI; + +public class BaritoneUtils { + public static boolean IS_AVAILABLE = false; + + public static String getPrefix() { + if (IS_AVAILABLE) { + return BaritoneAPI.getSettings().prefix.value; + } + + return ""; + } +} diff --git a/src/main/java/meteordevelopment/meteorclient/pathing/IPathManager.java b/src/main/java/meteordevelopment/meteorclient/pathing/IPathManager.java new file mode 100644 index 0000000000..533c285ee7 --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/pathing/IPathManager.java @@ -0,0 +1,47 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.pathing; + +import meteordevelopment.meteorclient.settings.Setting; +import meteordevelopment.meteorclient.settings.Settings; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.BlockPos; + +import java.util.function.Predicate; + +public interface IPathManager { + String getName(); + + boolean isPathing(); + + void pause(); + void resume(); + void stop(); + + default void moveTo(BlockPos pos) { moveTo(pos, false); } + void moveTo(BlockPos pos, boolean ignoreY); + void moveInDirection(float yaw); + + void mine(Block... blocks); + + void follow(Predicate entity); + + float getTargetYaw(); + float getTargetPitch(); + + ISettings getSettings(); + + interface ISettings { + Settings get(); + + Setting getWalkOnWater(); + Setting getWalkOnLava(); + + Setting getStep(); + Setting getNoFall(); + } +} diff --git a/src/main/java/meteordevelopment/meteorclient/pathing/NopPathManager.java b/src/main/java/meteordevelopment/meteorclient/pathing/NopPathManager.java new file mode 100644 index 0000000000..873b3915a3 --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/pathing/NopPathManager.java @@ -0,0 +1,99 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.pathing; + +import meteordevelopment.meteorclient.settings.BoolSetting; +import meteordevelopment.meteorclient.settings.Setting; +import meteordevelopment.meteorclient.settings.Settings; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.BlockPos; + +import java.util.function.Predicate; + +public class NopPathManager implements IPathManager { + private final NopSettings settings = new NopSettings(); + + @Override + public String getName() { + return "none"; + } + + @Override + public boolean isPathing() { + return false; + } + + @Override + public void pause() {} + + @Override + public void resume() {} + + @Override + public void stop() {} + + @Override + public void moveTo(BlockPos pos, boolean ignoreY) {} + + @Override + public void moveInDirection(float yaw) {} + + @Override + public void mine(Block... blocks) {} + + @Override + public void follow(Predicate entity) {} + + @Override + public float getTargetYaw() { + return 0; + } + + @Override + public float getTargetPitch() { + return 0; + } + + @Override + public ISettings getSettings() { + return settings; + } + + private static class NopSettings implements ISettings { + private final Settings settings = new Settings(); + private final Setting setting = new BoolSetting.Builder().build(); + + @Override + public Settings get() { + return settings; + } + + @Override + public Setting getWalkOnWater() { + setting.reset(); + return setting; + } + + @Override + public Setting getWalkOnLava() { + setting.reset(); + return setting; + } + + @Override + public Setting getStep() { + setting.reset(); + return setting; + } + + @Override + public Setting getNoFall() { + setting.reset(); + return setting; + } + } +} diff --git a/src/main/java/meteordevelopment/meteorclient/pathing/PathManagers.java b/src/main/java/meteordevelopment/meteorclient/pathing/PathManagers.java new file mode 100644 index 0000000000..d7f9ebf45d --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/pathing/PathManagers.java @@ -0,0 +1,49 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.pathing; + +import meteordevelopment.meteorclient.MeteorClient; +import meteordevelopment.meteorclient.utils.PreInit; + +import java.lang.reflect.InvocationTargetException; + +public class PathManagers { + private static IPathManager INSTANCE = new NopPathManager(); + + public static IPathManager get() { + return INSTANCE; + } + + @PreInit + public static void init() { + if (exists("meteordevelopment.voyager.PathManager")) { + try { + INSTANCE = (IPathManager) Class.forName("meteordevelopment.voyager.PathManager").getConstructor().newInstance(); + } catch (InstantiationException | IllegalAccessException | InvocationTargetException | + NoSuchMethodException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + + if (exists("baritone.api.BaritoneAPI")) { + BaritoneUtils.IS_AVAILABLE = true; + + if (INSTANCE instanceof NopPathManager) + INSTANCE = new BaritonePathManager(); + } + + MeteorClient.LOG.info("Path Manager: {}", INSTANCE.getName()); + } + + private static boolean exists(String name) { + try { + Class.forName(name); + return true; + } catch (ClassNotFoundException e) { + return false; + } + } +} diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/Modules.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/Modules.java index 1e18bfd65d..0d1d18e527 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/Modules.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/Modules.java @@ -16,6 +16,7 @@ import meteordevelopment.meteorclient.events.meteor.KeyEvent; import meteordevelopment.meteorclient.events.meteor.ModuleBindChangedEvent; import meteordevelopment.meteorclient.events.meteor.MouseButtonEvent; +import meteordevelopment.meteorclient.pathing.BaritoneUtils; import meteordevelopment.meteorclient.settings.Setting; import meteordevelopment.meteorclient.settings.SettingGroup; import meteordevelopment.meteorclient.systems.System; @@ -529,9 +530,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()); add(new MountBypass()); add(new NoGhostBlocks()); @@ -541,6 +540,11 @@ private void initWorld() { add(new Timer()); add(new VeinMiner()); add(new HighwayBuilder()); + + if (BaritoneUtils.IS_AVAILABLE) { + add(new Excavator()); + add(new InfinityMiner()); + } } private void initMisc() { diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/BowAimbot.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/BowAimbot.java index 4f5361fb35..7a3a86f667 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/BowAimbot.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/BowAimbot.java @@ -5,8 +5,8 @@ package meteordevelopment.meteorclient.systems.modules.combat; -import baritone.api.BaritoneAPI; import meteordevelopment.meteorclient.events.render.Render3DEvent; +import meteordevelopment.meteorclient.pathing.PathManagers; import meteordevelopment.meteorclient.settings.*; import meteordevelopment.meteorclient.systems.friends.Friends; import meteordevelopment.meteorclient.systems.modules.Categories; @@ -111,15 +111,15 @@ private void onRender(Render3DEvent event) { if (target == null) { if (wasPathing) { - BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager().execute("resume"); + PathManagers.get().resume(); wasPathing = false; } return; } if (mc.options.useKey.isPressed() && itemInHand()) { - if (pauseOnCombat.get() && BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().isPathing() && !wasPathing) { - BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager().execute("pause"); + if (pauseOnCombat.get() && PathManagers.get().isPathing() && !wasPathing) { + PathManagers.get().pause(); wasPathing = true; } aim(event.tickDelta); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/KillAura.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/KillAura.java index 2b7170b046..3ec357a68f 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/KillAura.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/KillAura.java @@ -5,9 +5,9 @@ package meteordevelopment.meteorclient.systems.modules.combat; -import baritone.api.BaritoneAPI; import meteordevelopment.meteorclient.events.packets.PacketEvent; import meteordevelopment.meteorclient.events.world.TickEvent; +import meteordevelopment.meteorclient.pathing.PathManagers; import meteordevelopment.meteorclient.settings.*; import meteordevelopment.meteorclient.systems.friends.Friends; import meteordevelopment.meteorclient.systems.modules.Categories; @@ -270,7 +270,7 @@ private void onTick(TickEvent.Pre event) { if (targets.isEmpty()) { if (wasPathing) { - BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager().execute("resume"); + PathManagers.get().resume(); wasPathing = false; } return; @@ -298,8 +298,8 @@ private void onTick(TickEvent.Pre event) { if (!itemInHand()) return; if (rotation.get() == RotationMode.Always) Rotations.rotate(Rotations.getYaw(primary), Rotations.getPitch(primary, Target.Body)); - if (pauseOnCombat.get() && BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().isPathing() && !wasPathing) { - BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager().execute("pause"); + if (pauseOnCombat.get() && PathManagers.get().isPathing() && !wasPathing) { + PathManagers.get().pause(); wasPathing = true; } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/swarm/SwarmWorker.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/swarm/SwarmWorker.java index 55852e2c8f..090a089359 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/swarm/SwarmWorker.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/swarm/SwarmWorker.java @@ -5,8 +5,8 @@ package meteordevelopment.meteorclient.systems.modules.misc.swarm; -import baritone.api.BaritoneAPI; import meteordevelopment.meteorclient.commands.Commands; +import meteordevelopment.meteorclient.pathing.PathManagers; import meteordevelopment.meteorclient.utils.player.ChatUtils; import net.minecraft.block.Block; @@ -68,7 +68,7 @@ public void disconnect() { e.printStackTrace(); } - BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().cancelEverything(); + PathManagers.get().stop(); ChatUtils.infoPrefix("Swarm", "Disconnected from host."); @@ -77,8 +77,10 @@ public void disconnect() { public void tick() { if (target == null) return; - BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().cancelEverything(); - BaritoneAPI.getProvider().getPrimaryBaritone().getMineProcess().mine(target); + + PathManagers.get().stop(); + PathManagers.get().mine(target); + target = null; } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/AutoWalk.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/AutoWalk.java index 7277b5ecca..ccfb619c18 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/AutoWalk.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/AutoWalk.java @@ -5,15 +5,15 @@ package meteordevelopment.meteorclient.systems.modules.movement; -import baritone.api.BaritoneAPI; import meteordevelopment.meteorclient.events.world.TickEvent; +import meteordevelopment.meteorclient.pathing.NopPathManager; +import meteordevelopment.meteorclient.pathing.PathManagers; import meteordevelopment.meteorclient.settings.EnumSetting; import meteordevelopment.meteorclient.settings.Setting; import meteordevelopment.meteorclient.settings.SettingGroup; import meteordevelopment.meteorclient.systems.modules.Categories; import meteordevelopment.meteorclient.systems.modules.Module; import meteordevelopment.meteorclient.utils.misc.input.Input; -import meteordevelopment.meteorclient.utils.world.GoalDirection; import meteordevelopment.orbit.EventHandler; import meteordevelopment.orbit.EventPriority; import net.minecraft.client.option.KeyBinding; @@ -28,10 +28,8 @@ public class AutoWalk extends Module { .onChanged(mode1 -> { if (isActive()) { if (mode1 == Mode.Simple) { - BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().cancelEverything(); - goal = null; + PathManagers.get().stop(); } else { - timer = 0; createGoal(); } @@ -52,9 +50,6 @@ public class AutoWalk extends Module { .build() ); - private int timer = 0; - private GoalDirection goal; - public AutoWalk() { super(Categories.Movement, "auto-walk", "Automatically walks forward."); } @@ -67,9 +62,7 @@ public void onActivate() { @Override public void onDeactivate() { if (mode.get() == Mode.Simple) unpress(); - else BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().cancelEverything(); - - goal = null; + else PathManagers.get().stop(); } @EventHandler(priority = EventPriority.HIGH) @@ -82,12 +75,10 @@ private void onTick(TickEvent.Pre event) { case Right -> setPressed(mc.options.rightKey, true); } } else { - if (timer > 20) { - timer = 0; - goal.recalculate(mc.player.getPos()); + if (PathManagers.get() instanceof NopPathManager) { + info("Smart mode requires Baritone"); + toggle(); } - - timer++; } } @@ -104,9 +95,7 @@ private void setPressed(KeyBinding key, boolean pressed) { } private void createGoal() { - timer = 0; - goal = new GoalDirection(mc.player.getPos(), mc.player.getYaw()); - BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(goal); + PathManagers.get().moveInDirection(mc.player.getYaw()); } public enum Mode { diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Jesus.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Jesus.java index 3b7a6b68c2..b4cb52f0e6 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Jesus.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Jesus.java @@ -5,7 +5,6 @@ package meteordevelopment.meteorclient.systems.modules.movement; -import baritone.api.BaritoneAPI; import com.google.common.collect.Streams; import meteordevelopment.meteorclient.events.entity.player.CanWalkOnFluidEvent; import meteordevelopment.meteorclient.events.packets.PacketEvent; @@ -13,6 +12,7 @@ import meteordevelopment.meteorclient.events.world.TickEvent; import meteordevelopment.meteorclient.mixin.LivingEntityAccessor; import meteordevelopment.meteorclient.mixininterface.IVec3d; +import meteordevelopment.meteorclient.pathing.PathManagers; import meteordevelopment.meteorclient.settings.*; import meteordevelopment.meteorclient.systems.modules.Categories; import meteordevelopment.meteorclient.systems.modules.Module; @@ -144,8 +144,8 @@ public class Jesus extends Module { private int tickTimer = 10; private int packetTimer = 0; - private boolean preBaritoneAssumeWalkOnWater; - private boolean preBaritoneAssumeWalkOnLava; + private boolean prePathManagerWalkOnWater; + private boolean prePathManagerWalkOnLava; public Jesus() { super(Categories.Movement, "jesus", "Walk on liquids and powder snow like Jesus."); @@ -153,17 +153,17 @@ public Jesus() { @Override public void onActivate() { - preBaritoneAssumeWalkOnWater = BaritoneAPI.getSettings().assumeWalkOnWater.value; - preBaritoneAssumeWalkOnLava = BaritoneAPI.getSettings().assumeWalkOnLava.value; + prePathManagerWalkOnWater = PathManagers.get().getSettings().getWalkOnWater().get(); + prePathManagerWalkOnLava = PathManagers.get().getSettings().getWalkOnLava().get(); - BaritoneAPI.getSettings().assumeWalkOnWater.value = waterMode.get() == Mode.Solid; - BaritoneAPI.getSettings().assumeWalkOnLava.value = lavaMode.get() == Mode.Solid; + PathManagers.get().getSettings().getWalkOnWater().set(waterMode.get() == Mode.Solid); + PathManagers.get().getSettings().getWalkOnLava().set(lavaMode.get() == Mode.Solid); } @Override public void onDeactivate() { - BaritoneAPI.getSettings().assumeWalkOnWater.value = preBaritoneAssumeWalkOnWater; - BaritoneAPI.getSettings().assumeWalkOnLava.value = preBaritoneAssumeWalkOnLava; + PathManagers.get().getSettings().getWalkOnWater().set(prePathManagerWalkOnWater); + PathManagers.get().getSettings().getWalkOnLava().set(prePathManagerWalkOnLava); } @EventHandler diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/NoFall.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/NoFall.java index 6bc05b35bb..0ec72a7f64 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/NoFall.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/NoFall.java @@ -5,12 +5,12 @@ package meteordevelopment.meteorclient.systems.modules.movement; -import baritone.api.BaritoneAPI; import meteordevelopment.meteorclient.events.packets.PacketEvent; import meteordevelopment.meteorclient.events.world.TickEvent; import meteordevelopment.meteorclient.mixin.PlayerMoveC2SPacketAccessor; import meteordevelopment.meteorclient.mixininterface.IPlayerMoveC2SPacket; import meteordevelopment.meteorclient.mixininterface.IVec3d; +import meteordevelopment.meteorclient.pathing.PathManagers; import meteordevelopment.meteorclient.settings.BoolSetting; import meteordevelopment.meteorclient.settings.EnumSetting; import meteordevelopment.meteorclient.settings.Setting; @@ -92,7 +92,7 @@ public class NoFall extends Module { private boolean placedWater; private BlockPos targetPos; private int timer; - private int preBaritoneFallHeight; + private boolean prePathManagerNoFall; public NoFall() { super(Categories.Movement, "no-fall", "Attempts to prevent you from taking fall damage."); @@ -100,14 +100,15 @@ public NoFall() { @Override public void onActivate() { - preBaritoneFallHeight = BaritoneAPI.getSettings().maxFallHeightNoWater.value; - if (mode.get() == Mode.Packet) BaritoneAPI.getSettings().maxFallHeightNoWater.value = 255; + prePathManagerNoFall = PathManagers.get().getSettings().getNoFall().get(); + if (mode.get() == Mode.Packet) PathManagers.get().getSettings().getNoFall().set(true); + placedWater = false; } @Override public void onDeactivate() { - BaritoneAPI.getSettings().maxFallHeightNoWater.value = preBaritoneFallHeight; + PathManagers.get().getSettings().getNoFall().set(prePathManagerNoFall); } @EventHandler diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Step.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Step.java index 63b2994f3d..785df81932 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Step.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Step.java @@ -5,9 +5,9 @@ package meteordevelopment.meteorclient.systems.modules.movement; -import baritone.api.BaritoneAPI; import com.google.common.collect.Streams; import meteordevelopment.meteorclient.events.world.TickEvent; +import meteordevelopment.meteorclient.pathing.PathManagers; import meteordevelopment.meteorclient.settings.*; import meteordevelopment.meteorclient.systems.modules.Categories; import meteordevelopment.meteorclient.systems.modules.Module; @@ -55,7 +55,7 @@ public class Step extends Module { ); private float prevStepHeight; - private boolean prevBaritoneAssumeStep; + private boolean prevPathManagerStep; public Step() { super(Categories.Movement, "step", "Allows you to walk up full blocks instantly."); @@ -64,9 +64,9 @@ public Step() { @Override public void onActivate() { prevStepHeight = mc.player.getStepHeight(); - prevBaritoneAssumeStep = BaritoneAPI.getSettings().assumeStep.value; - BaritoneAPI.getSettings().assumeStep.value = true; + prevPathManagerStep = PathManagers.get().getSettings().getStep().get(); + PathManagers.get().getSettings().getStep().set(true); } @EventHandler @@ -84,7 +84,8 @@ private void onTick(TickEvent.Post event) { @Override public void onDeactivate() { mc.player.setStepHeight(prevStepHeight); - BaritoneAPI.getSettings().assumeStep.value = prevBaritoneAssumeStep; + + PathManagers.get().getSettings().getStep().set(prevPathManagerStep); } private float getHealth(){ diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoEat.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoEat.java index 2ed7a92a6c..307854c048 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoEat.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoEat.java @@ -5,9 +5,9 @@ package meteordevelopment.meteorclient.systems.modules.player; -import baritone.api.BaritoneAPI; import meteordevelopment.meteorclient.events.entity.player.ItemUseCrosshairTargetEvent; import meteordevelopment.meteorclient.events.world.TickEvent; +import meteordevelopment.meteorclient.pathing.PathManagers; import meteordevelopment.meteorclient.settings.*; import meteordevelopment.meteorclient.systems.modules.Categories; import meteordevelopment.meteorclient.systems.modules.Module; @@ -179,9 +179,9 @@ private void startEating() { } // Pause baritone - if (pauseBaritone.get() && BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().isPathing() && !wasBaritone) { + if (pauseBaritone.get() && PathManagers.get().isPathing() && !wasBaritone) { wasBaritone = true; - BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager().execute("pause"); + PathManagers.get().pause(); } } @@ -213,7 +213,7 @@ private void stopEating() { // Resume baritone if (pauseBaritone.get() && wasBaritone) { wasBaritone = false; - BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager().execute("resume"); + PathManagers.get().resume(); } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoGap.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoGap.java index 9c7aa5eb85..5ce30960c1 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoGap.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoGap.java @@ -5,9 +5,9 @@ package meteordevelopment.meteorclient.systems.modules.player; -import baritone.api.BaritoneAPI; import meteordevelopment.meteorclient.events.entity.player.ItemUseCrosshairTargetEvent; import meteordevelopment.meteorclient.events.world.TickEvent; +import meteordevelopment.meteorclient.pathing.PathManagers; import meteordevelopment.meteorclient.settings.BoolSetting; import meteordevelopment.meteorclient.settings.IntSetting; import meteordevelopment.meteorclient.settings.Setting; @@ -195,9 +195,9 @@ private void startEating() { // Pause baritone wasBaritone = false; - if (pauseBaritone.get() && BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().isPathing()) { + if (pauseBaritone.get() && PathManagers.get().isPathing()) { wasBaritone = true; - BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager().execute("pause"); + PathManagers.get().pause(); } } @@ -228,7 +228,7 @@ private void stopEating() { // Resume baritone if (pauseBaritone.get() && wasBaritone) { - BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager().execute("resume"); + PathManagers.get().resume(); } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/WaypointsModule.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/WaypointsModule.java index 45b64bf019..0af2db5d59 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/WaypointsModule.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/WaypointsModule.java @@ -5,9 +5,6 @@ package meteordevelopment.meteorclient.systems.modules.render; -import baritone.api.BaritoneAPI; -import baritone.api.IBaritone; -import baritone.api.pathing.goals.GoalGetToBlock; import meteordevelopment.meteorclient.events.game.OpenScreenEvent; import meteordevelopment.meteorclient.gui.GuiTheme; import meteordevelopment.meteorclient.gui.renderer.GuiRenderer; @@ -18,6 +15,7 @@ import meteordevelopment.meteorclient.gui.widgets.pressable.WButton; import meteordevelopment.meteorclient.gui.widgets.pressable.WCheckbox; import meteordevelopment.meteorclient.gui.widgets.pressable.WMinus; +import meteordevelopment.meteorclient.pathing.PathManagers; import meteordevelopment.meteorclient.settings.*; import meteordevelopment.meteorclient.systems.modules.Categories; import meteordevelopment.meteorclient.systems.modules.Module; @@ -155,9 +153,10 @@ private void initTable(GuiTheme theme, WTable table) { if (validDim) { WButton gotoB = table.add(theme.button("Goto")).widget(); gotoB.action = () -> { - IBaritone baritone = BaritoneAPI.getProvider().getPrimaryBaritone(); - if (baritone.getPathingBehavior().isPathing()) baritone.getPathingBehavior().cancelEverything(); - baritone.getCustomGoalProcess().setGoalAndPath(new GoalGetToBlock(waypoint.getPos())); + if (PathManagers.get().isPathing()) + PathManagers.get().stop(); + + PathManagers.get().moveTo(waypoint.getPos()); }; } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/StashFinder.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/StashFinder.java index b79aa52617..3cfc6b6d86 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/StashFinder.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/StashFinder.java @@ -5,8 +5,6 @@ package meteordevelopment.meteorclient.systems.modules.world; -import baritone.api.BaritoneAPI; -import baritone.api.pathing.goals.GoalXZ; import com.google.common.reflect.TypeToken; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -19,6 +17,7 @@ import meteordevelopment.meteorclient.gui.widgets.containers.WVerticalList; import meteordevelopment.meteorclient.gui.widgets.pressable.WButton; import meteordevelopment.meteorclient.gui.widgets.pressable.WMinus; +import meteordevelopment.meteorclient.pathing.PathManagers; import meteordevelopment.meteorclient.settings.*; import meteordevelopment.meteorclient.systems.modules.Categories; import meteordevelopment.meteorclient.systems.modules.Module; @@ -27,6 +26,7 @@ import meteordevelopment.orbit.EventHandler; import net.minecraft.block.entity.*; import net.minecraft.item.Items; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; import java.io.*; @@ -170,7 +170,7 @@ private void fillTable(GuiTheme theme, WTable table) { open.action = () -> mc.setScreen(new ChunkScreen(theme, chunk)); WButton gotoBtn = table.add(theme.button("Goto")).widget(); - gotoBtn.action = () -> BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(new GoalXZ(chunk.x, chunk.z)); + gotoBtn.action = () -> PathManagers.get().moveTo(new BlockPos(chunk.x, 0, chunk.z), true); WMinus delete = table.add(theme.minus()).widget(); delete.action = () -> { diff --git a/src/main/java/meteordevelopment/meteorclient/utils/misc/BaritoneUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/misc/BaritoneUtils.java deleted file mode 100644 index 317385d8ea..0000000000 --- a/src/main/java/meteordevelopment/meteorclient/utils/misc/BaritoneUtils.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). - * Copyright (c) Meteor Development. - */ - -package meteordevelopment.meteorclient.utils.misc; - -import baritone.api.BaritoneAPI; -import baritone.api.utils.Rotation; - -import java.lang.reflect.Field; - -public class BaritoneUtils { - private static Field targetField; - - public static Rotation getTarget() { - findField(); - if (targetField == null) return null; - - targetField.setAccessible(true); - - try { - return (Rotation) targetField.get(BaritoneAPI.getProvider().getPrimaryBaritone().getLookBehavior()); - } catch (IllegalAccessException e) { - e.printStackTrace(); - return null; - } - } - - private static void findField() { - if (targetField != null) return; - - Class klass = BaritoneAPI.getProvider().getPrimaryBaritone().getLookBehavior().getClass(); - - for (Field field : klass.getDeclaredFields()) { - if (field.getType() == Rotation.class) { - targetField = field; - break; - } - } - } -} diff --git a/src/main/java/meteordevelopment/meteorclient/utils/misc/MeteorStarscript.java b/src/main/java/meteordevelopment/meteorclient/utils/misc/MeteorStarscript.java index 242fb36a4b..eba2bba254 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/misc/MeteorStarscript.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/misc/MeteorStarscript.java @@ -11,6 +11,8 @@ import meteordevelopment.meteorclient.MeteorClient; import meteordevelopment.meteorclient.mixin.ClientPlayerInteractionManagerAccessor; import meteordevelopment.meteorclient.mixin.MinecraftClientAccessor; +import meteordevelopment.meteorclient.pathing.BaritoneUtils; +import meteordevelopment.meteorclient.pathing.PathManagers; import meteordevelopment.meteorclient.systems.config.Config; import meteordevelopment.meteorclient.systems.modules.Module; import meteordevelopment.meteorclient.systems.modules.Modules; @@ -69,7 +71,7 @@ public class MeteorStarscript { private static final BlockPos.Mutable BP = new BlockPos.Mutable(); private static final StringBuilder SB = new StringBuilder(); - @PreInit + @PreInit(dependencies = PathManagers.class) public static void init() { StandardLib.init(ss); @@ -92,13 +94,15 @@ public static void init() { ); // Baritone - ss.set("baritone", new ValueMap() - .set("is_pathing", () -> Value.bool(BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().isPathing())) - .set("distance_to_goal", MeteorStarscript::baritoneDistanceToGoal) - .set("process", MeteorStarscript::baritoneProcess) - .set("process_name", MeteorStarscript::baritoneProcessName) - .set("eta", MeteorStarscript::baritoneETA) - ); + if (BaritoneUtils.IS_AVAILABLE) { + ss.set("baritone", new ValueMap() + .set("is_pathing", () -> Value.bool(BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().isPathing())) + .set("distance_to_goal", MeteorStarscript::baritoneDistanceToGoal) + .set("process", MeteorStarscript::baritoneProcess) + .set("process_name", MeteorStarscript::baritoneProcessName) + .set("eta", MeteorStarscript::baritoneETA) + ); + } // Camera ss.set("camera", new ValueMap() diff --git a/src/main/java/meteordevelopment/meteorclient/utils/player/ChatUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/player/ChatUtils.java index bf2283e4f6..d4eace822e 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/player/ChatUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/player/ChatUtils.java @@ -5,10 +5,10 @@ package meteordevelopment.meteorclient.utils.player; -import baritone.api.BaritoneAPI; import com.mojang.brigadier.StringReader; import meteordevelopment.meteorclient.MeteorClient; import meteordevelopment.meteorclient.mixininterface.IChatHud; +import meteordevelopment.meteorclient.pathing.BaritoneUtils; import meteordevelopment.meteorclient.systems.config.Config; import meteordevelopment.meteorclient.utils.PostInit; import net.minecraft.text.*; @@ -241,17 +241,20 @@ private static MutableText formatMsg(String message, Formatting defaultColor) { public static MutableText formatCoords(Vec3d pos) { String coordsString = String.format("(highlight)(underline)%.0f, %.0f, %.0f(default)", pos.x, pos.y, pos.z); MutableText coordsText = formatMsg(coordsString, Formatting.GRAY); - coordsText.setStyle(coordsText.getStyle() - .withFormatting(Formatting.BOLD) - .withClickEvent(new ClickEvent( - ClickEvent.Action.RUN_COMMAND, - String.format("%sgoto %d %d %d", BaritoneAPI.getSettings().prefix.value, (int) pos.x, (int) pos.y, (int) pos.z) - )) - .withHoverEvent(new HoverEvent( - HoverEvent.Action.SHOW_TEXT, - Text.literal("Set as Baritone goal") - )) - ); + + Style style = coordsText.getStyle().withFormatting(Formatting.BOLD).withHoverEvent(new HoverEvent( + HoverEvent.Action.SHOW_TEXT, + Text.literal("Set as Baritone goal") + )); + + if (BaritoneUtils.IS_AVAILABLE) { + style = style.withClickEvent(new ClickEvent( + ClickEvent.Action.RUN_COMMAND, + String.format("%sgoto %d %d %d", BaritoneUtils.getPrefix(), (int) pos.x, (int) pos.y, (int) pos.z) + )); + } + + coordsText.setStyle(style); return coordsText; } } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/player/PlayerUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/player/PlayerUtils.java index 13b7604ef1..df40bf5cb3 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/player/PlayerUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/player/PlayerUtils.java @@ -5,16 +5,14 @@ package meteordevelopment.meteorclient.utils.player; -import baritone.api.BaritoneAPI; -import baritone.api.utils.Rotation; import meteordevelopment.meteorclient.mixininterface.IVec3d; +import meteordevelopment.meteorclient.pathing.PathManagers; import meteordevelopment.meteorclient.systems.config.Config; import meteordevelopment.meteorclient.systems.friends.Friends; import meteordevelopment.meteorclient.systems.modules.Modules; import meteordevelopment.meteorclient.systems.modules.movement.NoFall; import meteordevelopment.meteorclient.utils.Utils; import meteordevelopment.meteorclient.utils.entity.EntityUtils; -import meteordevelopment.meteorclient.utils.misc.BaritoneUtils; import meteordevelopment.meteorclient.utils.misc.text.TextUtils; import meteordevelopment.meteorclient.utils.render.color.Color; import meteordevelopment.meteorclient.utils.world.Dimension; @@ -60,9 +58,8 @@ public static Color getPlayerColor(PlayerEntity entity, Color defaultColor) { public static Vec3d getHorizontalVelocity(double bps) { float yaw = mc.player.getYaw(); - if (BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().isPathing()) { - Rotation target = BaritoneUtils.getTarget(); - if (target != null) yaw = target.getYaw(); + if (PathManagers.get().isPathing()) { + yaw = PathManagers.get().getTargetYaw(); } Vec3d forward = Vec3d.fromPolar(0, yaw); diff --git a/src/main/java/meteordevelopment/meteorclient/utils/world/GoalDirection.java b/src/main/java/meteordevelopment/meteorclient/utils/world/GoalDirection.java deleted file mode 100644 index 72d282f971..0000000000 --- a/src/main/java/meteordevelopment/meteorclient/utils/world/GoalDirection.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). - * Copyright (c) Meteor Development. - */ - -package meteordevelopment.meteorclient.utils.world; - -import baritone.api.BaritoneAPI; -import baritone.api.pathing.goals.Goal; -import baritone.api.utils.SettingsUtil; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.Vec3d; - -public class GoalDirection implements Goal { - private static final double SQRT_2 = Math.sqrt(2.0D); - private final float yaw; - private int x; - private int z; - - public GoalDirection(Vec3d origin, float yaw) { - this.yaw = yaw; - recalculate(origin); - } - - public static double calculate(double xDiff, double zDiff) { - double x = Math.abs(xDiff); - double z = Math.abs(zDiff); - double straight; - double diagonal; - if (x < z) { - straight = z - x; - diagonal = x; - } else { - straight = x - z; - diagonal = z; - } - - diagonal *= SQRT_2; - return (diagonal + straight) * BaritoneAPI.getSettings().costHeuristic.value; - } - - public void recalculate(Vec3d origin) { - float theta = (float) Math.toRadians(yaw); - x = (int) Math.floor(origin.x - (double) MathHelper.sin(theta) * 100); - z = (int) Math.floor(origin.z + (double) MathHelper.cos(theta) * 100); - } - - public boolean isInGoal(int x, int y, int z) { - return x == this.x && z == this.z; - } - - public double heuristic(int x, int y, int z) { - int xDiff = x - this.x; - int zDiff = z - this.z; - return calculate(xDiff, zDiff); - } - - public String toString() { - return String.format("GoalXZ{x=%s,z=%s}", SettingsUtil.maybeCensor(this.x), SettingsUtil.maybeCensor(this.z)); - } - - public int getX() { - return this.x; - } - - public int getZ() { - return this.z; - } -}