From b3f82ab6d72c149498e4253a355c6f3a094b9c7d Mon Sep 17 00:00:00 2001 From: MineGame159 Date: Wed, 18 Oct 2023 21:31:15 +0200 Subject: [PATCH] Make Baritone optional and not bundled with Meteor --- build.gradle | 2 +- .../meteorclient/commands/Commands.java | 9 +- .../commands/commands/LocateCommand.java | 7 +- .../commands/commands/SwarmCommand.java | 16 +- .../meteorclient/gui/tabs/Tabs.java | 9 +- .../mixin/ClientPlayNetworkHandlerMixin.java | 3 +- .../pathing/BaritonePathManager.java | 252 ++++++++++++++++++ .../meteorclient/pathing/BaritoneUtils.java | 20 ++ .../meteorclient/pathing/IPathManager.java | 47 ++++ .../meteorclient/pathing/NopPathManager.java | 91 +++++++ .../meteorclient/pathing/PathManagers.java | 26 ++ .../meteorclient/systems/modules/Modules.java | 8 +- .../systems/modules/combat/BowAimbot.java | 8 +- .../systems/modules/combat/KillAura.java | 8 +- .../modules/misc/swarm/SwarmWorker.java | 10 +- .../systems/modules/movement/AutoWalk.java | 27 +- .../systems/modules/movement/Jesus.java | 18 +- .../systems/modules/movement/NoFall.java | 11 +- .../systems/modules/movement/Step.java | 11 +- .../systems/modules/player/AutoEat.java | 8 +- .../systems/modules/player/AutoGap.java | 8 +- .../modules/render/WaypointsModule.java | 11 +- .../systems/modules/world/StashFinder.java | 6 +- .../utils/misc/BaritoneUtils.java | 42 --- .../utils/misc/MeteorStarscript.java | 20 +- .../meteorclient/utils/player/ChatUtils.java | 27 +- .../utils/player/PlayerUtils.java | 9 +- .../utils/world/GoalDirection.java | 69 ----- 28 files changed, 562 insertions(+), 221 deletions(-) create mode 100644 src/main/java/meteordevelopment/meteorclient/pathing/BaritonePathManager.java create mode 100644 src/main/java/meteordevelopment/meteorclient/pathing/BaritoneUtils.java create mode 100644 src/main/java/meteordevelopment/meteorclient/pathing/IPathManager.java create mode 100644 src/main/java/meteordevelopment/meteorclient/pathing/NopPathManager.java create mode 100644 src/main/java/meteordevelopment/meteorclient/pathing/PathManagers.java delete mode 100644 src/main/java/meteordevelopment/meteorclient/utils/misc/BaritoneUtils.java delete mode 100644 src/main/java/meteordevelopment/meteorclient/utils/world/GoalDirection.java diff --git a/build.gradle b/build.gradle index f5e73bea45..5b54163778 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 "baritone:fabric:${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..8885f8a2ad 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/Commands.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/Commands.java @@ -8,6 +8,8 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.exceptions.CommandSyntaxException; import meteordevelopment.meteorclient.commands.commands.*; +import meteordevelopment.meteorclient.pathing.BaritoneUtils; +import meteordevelopment.meteorclient.pathing.PathManagers; import meteordevelopment.meteorclient.utils.PostInit; import net.minecraft.client.network.ClientCommandSource; import net.minecraft.command.CommandSource; @@ -23,7 +25,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 +37,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()); @@ -62,6 +63,10 @@ public static void init() { add(new WaypointCommand()); add(new InputCommand()); + if (BaritoneUtils.IS_AVAILABLE) { + 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..8df324ea38 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/commands/LocateCommand.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/commands/LocateCommand.java @@ -10,6 +10,7 @@ import meteordevelopment.meteorclient.MeteorClient; import meteordevelopment.meteorclient.commands.Command; import meteordevelopment.meteorclient.events.packets.PacketEvent; +import meteordevelopment.meteorclient.pathing.PathManagers; import meteordevelopment.meteorclient.utils.player.ChatUtils; import meteordevelopment.meteorclient.utils.player.InvUtils; import meteordevelopment.orbit.EventHandler; @@ -17,6 +18,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; @@ -146,7 +148,7 @@ public void build(LiteralArgumentBuilder builder) { 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; @@ -271,7 +273,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..4788ad2d49 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 (BaritoneUtils.IS_AVAILABLE) { + add(new BaritoneTab()); + } } public static void add(Tab tab) { diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayNetworkHandlerMixin.java index a6f62321b2..bc8baf116d 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..9921245d38 --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/pathing/BaritonePathManager.java @@ -0,0 +1,252 @@ +/* + * 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.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.reflect.Field; +import java.util.function.Predicate; + +import static meteordevelopment.meteorclient.MeteorClient.mc; + +public class BaritonePathManager implements IPathManager { + private final Field rotationField; + private final Settings settings; + + private GoalDirection directionGoal; + + public BaritonePathManager() { + // Subscribe to event bus + MeteorClient.EVENT_BUS.subscribe(this); + + // Find rotation field + Class klass = BaritoneAPI.getProvider().getPrimaryBaritone().getLookBehavior().getClass(); + Field rotationField = null; + + for (Field field : klass.getDeclaredFields()) { + if (field.getType() == Rotation.class) { + field.setAccessible(true); + + rotationField = field; + break; + } + } + + this.rotationField = rotationField; + + // Create settings + settings = new Settings(); + } + + @Override + public boolean isPathing() { + return BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().isPathing(); + } + + @Override + public void pause() { + BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager().execute("pause"); + } + + @Override + public void resume() { + BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager().execute("resume"); + } + + @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() { + if (rotationField == null) return 0; + + try { + return ((Rotation) rotationField.get(BaritoneAPI.getProvider().getPrimaryBaritone().getLookBehavior())).getYaw(); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + @Override + public float getTargetPitch() { + if (rotationField == null) return 0; + + try { + return ((Rotation) rotationField.get(BaritoneAPI.getProvider().getPrimaryBaritone().getLookBehavior())).getPitch(); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + @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 Settings implements ISettings { + @Override + public boolean getWalkOnWater() { + return BaritoneAPI.getSettings().assumeWalkOnWater.value; + } + + @Override + public void setWalkOnWater(boolean value) { + BaritoneAPI.getSettings().assumeWalkOnWater.value = value; + } + + @Override + public boolean getWalkOnLava() { + return BaritoneAPI.getSettings().assumeWalkOnLava.value; + } + + @Override + public void setWalkOnLava(boolean value) { + BaritoneAPI.getSettings().assumeWalkOnLava.value = value; + } + + @Override + public boolean getStep() { + return BaritoneAPI.getSettings().assumeStep.value; + } + + @Override + public void setStep(boolean value) { + BaritoneAPI.getSettings().assumeStep.value = value; + } + + @Override + public boolean getNoFall() { + return BaritoneAPI.getSettings().maxFallHeightNoWater.value > BaritoneAPI.getSettings().maxFallHeightNoWater.defaultValue; + } + + @Override + public void setNoFall(boolean value) { + BaritoneAPI.getSettings().maxFallHeightNoWater.value = value ? 159159 : BaritoneAPI.getSettings().maxFallHeightNoWater.defaultValue; + } + } + + 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; + } + } +} 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..5c4452f69e --- /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 net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.BlockPos; + +import java.util.function.Predicate; + +public interface IPathManager { + 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 { + boolean getWalkOnWater(); + void setWalkOnWater(boolean value); + + boolean getWalkOnLava(); + void setWalkOnLava(boolean value); + + boolean getStep(); + void setStep(boolean value); + + boolean getNoFall(); + void setNoFall(boolean value); + } +} 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..63acf05296 --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/pathing/NopPathManager.java @@ -0,0 +1,91 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.pathing; + +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 Settings settings = new Settings(); + + @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 Settings implements ISettings { + @Override + public boolean getWalkOnWater() { + return false; + } + + @Override + public void setWalkOnWater(boolean value) {} + + @Override + public boolean getWalkOnLava() { + return false; + } + + @Override + public void setWalkOnLava(boolean value) {} + + @Override + public boolean getStep() { + return false; + } + + @Override + public void setStep(boolean value) {} + + @Override + public boolean getNoFall() { + return false; + } + + @Override + public void setNoFall(boolean value) {} + } +} 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..ff10caedd7 --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/pathing/PathManagers.java @@ -0,0 +1,26 @@ +/* + * 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.utils.PreInit; + +public class PathManagers { + private static IPathManager INSTANCE = new NopPathManager(); + + public static IPathManager get() { + return INSTANCE; + } + + @PreInit + public static void init() { + try { + Class.forName("baritone.api.BaritoneAPI"); + + BaritoneUtils.IS_AVAILABLE = true; + INSTANCE = new BaritonePathManager(); + } catch (ClassNotFoundException ignored) {} + } +} 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..1b1824897d 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(); + prePathManagerWalkOnLava = PathManagers.get().getSettings().getWalkOnLava(); - BaritoneAPI.getSettings().assumeWalkOnWater.value = waterMode.get() == Mode.Solid; - BaritoneAPI.getSettings().assumeWalkOnLava.value = lavaMode.get() == Mode.Solid; + PathManagers.get().getSettings().setWalkOnWater(waterMode.get() == Mode.Solid); + PathManagers.get().getSettings().setWalkOnLava(lavaMode.get() == Mode.Solid); } @Override public void onDeactivate() { - BaritoneAPI.getSettings().assumeWalkOnWater.value = preBaritoneAssumeWalkOnWater; - BaritoneAPI.getSettings().assumeWalkOnLava.value = preBaritoneAssumeWalkOnLava; + PathManagers.get().getSettings().setWalkOnWater(prePathManagerWalkOnWater); + PathManagers.get().getSettings().setWalkOnLava(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..0aa5aae0d1 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(); + if (mode.get() == Mode.Packet) PathManagers.get().getSettings().setNoFall(true); + placedWater = false; } @Override public void onDeactivate() { - BaritoneAPI.getSettings().maxFallHeightNoWater.value = preBaritoneFallHeight; + PathManagers.get().getSettings().setNoFall(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..d399bdc99a 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(); + PathManagers.get().getSettings().setStep(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().setStep(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; - } -}