From 6f7a2f2f45de06b14da4d9f08cf905e6c4f99891 Mon Sep 17 00:00:00 2001 From: MineGame159 Date: Sat, 21 Oct 2023 13:38:48 +0200 Subject: [PATCH] Abstract away the Baritone tab, the settings are now provided by the current path manager --- .../meteorclient/gui/tabs/Tabs.java | 4 +- .../gui/tabs/builtin/PathManagerTab.java | 59 ++++++++ .../pathing/BaritonePathManager.java | 51 +------ .../BaritoneSettings.java} | 141 ++++++++++-------- .../meteorclient/pathing/IPathManager.java | 18 +-- .../meteorclient/pathing/NopPathManager.java | 48 +++--- .../systems/modules/movement/Jesus.java | 12 +- .../systems/modules/movement/NoFall.java | 6 +- .../systems/modules/movement/Step.java | 8 +- 9 files changed, 193 insertions(+), 154 deletions(-) create mode 100644 src/main/java/meteordevelopment/meteorclient/gui/tabs/builtin/PathManagerTab.java rename src/main/java/meteordevelopment/meteorclient/{gui/tabs/builtin/BaritoneTab.java => pathing/BaritoneSettings.java} (92%) diff --git a/src/main/java/meteordevelopment/meteorclient/gui/tabs/Tabs.java b/src/main/java/meteordevelopment/meteorclient/gui/tabs/Tabs.java index 4788ad2d49..704eb5989e 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/tabs/Tabs.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/tabs/Tabs.java @@ -26,8 +26,8 @@ public static void init() { add(new MacrosTab()); add(new ProfilesTab()); - if (BaritoneUtils.IS_AVAILABLE) { - add(new BaritoneTab()); + if (PathManagers.get().getSettings().get().sizeGroups() > 0) { + add(new PathManagerTab()); } } 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/pathing/BaritonePathManager.java b/src/main/java/meteordevelopment/meteorclient/pathing/BaritonePathManager.java index ec3f0b4312..408c7288f0 100644 --- a/src/main/java/meteordevelopment/meteorclient/pathing/BaritonePathManager.java +++ b/src/main/java/meteordevelopment/meteorclient/pathing/BaritonePathManager.java @@ -33,7 +33,7 @@ public class BaritonePathManager implements IPathManager { private final VarHandle rotationField; - private final Settings settings; + private final BaritoneSettings settings; private GoalDirection directionGoal; private boolean pathingPaused; @@ -60,12 +60,17 @@ public BaritonePathManager() { this.rotationField = rotationField; // Create settings - settings = new 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(); @@ -141,48 +146,6 @@ private void onTick(TickEvent.Pre event) { 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); 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/IPathManager.java b/src/main/java/meteordevelopment/meteorclient/pathing/IPathManager.java index 5c4452f69e..533c285ee7 100644 --- a/src/main/java/meteordevelopment/meteorclient/pathing/IPathManager.java +++ b/src/main/java/meteordevelopment/meteorclient/pathing/IPathManager.java @@ -5,6 +5,8 @@ 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; @@ -12,6 +14,8 @@ import java.util.function.Predicate; public interface IPathManager { + String getName(); + boolean isPathing(); void pause(); @@ -32,16 +36,12 @@ public interface IPathManager { ISettings getSettings(); interface ISettings { - boolean getWalkOnWater(); - void setWalkOnWater(boolean value); - - boolean getWalkOnLava(); - void setWalkOnLava(boolean value); + Settings get(); - boolean getStep(); - void setStep(boolean value); + Setting getWalkOnWater(); + Setting getWalkOnLava(); - boolean getNoFall(); - void setNoFall(boolean value); + Setting getStep(); + Setting getNoFall(); } } diff --git a/src/main/java/meteordevelopment/meteorclient/pathing/NopPathManager.java b/src/main/java/meteordevelopment/meteorclient/pathing/NopPathManager.java index 63acf05296..873b3915a3 100644 --- a/src/main/java/meteordevelopment/meteorclient/pathing/NopPathManager.java +++ b/src/main/java/meteordevelopment/meteorclient/pathing/NopPathManager.java @@ -5,6 +5,9 @@ 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; @@ -12,7 +15,12 @@ import java.util.function.Predicate; public class NopPathManager implements IPathManager { - private final Settings settings = new Settings(); + private final NopSettings settings = new NopSettings(); + + @Override + public String getName() { + return "none"; + } @Override public boolean isPathing() { @@ -55,37 +63,37 @@ public ISettings getSettings() { return settings; } - private static class Settings implements ISettings { - @Override - public boolean getWalkOnWater() { - return false; - } + private static class NopSettings implements ISettings { + private final Settings settings = new Settings(); + private final Setting setting = new BoolSetting.Builder().build(); @Override - public void setWalkOnWater(boolean value) {} - - @Override - public boolean getWalkOnLava() { - return false; + public Settings get() { + return settings; } @Override - public void setWalkOnLava(boolean value) {} - - @Override - public boolean getStep() { - return false; + public Setting getWalkOnWater() { + setting.reset(); + return setting; } @Override - public void setStep(boolean value) {} + public Setting getWalkOnLava() { + setting.reset(); + return setting; + } @Override - public boolean getNoFall() { - return false; + public Setting getStep() { + setting.reset(); + return setting; } @Override - public void setNoFall(boolean value) {} + public Setting getNoFall() { + setting.reset(); + return setting; + } } } 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 1b1824897d..b4cb52f0e6 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Jesus.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Jesus.java @@ -153,17 +153,17 @@ public Jesus() { @Override public void onActivate() { - prePathManagerWalkOnWater = PathManagers.get().getSettings().getWalkOnWater(); - prePathManagerWalkOnLava = PathManagers.get().getSettings().getWalkOnLava(); + prePathManagerWalkOnWater = PathManagers.get().getSettings().getWalkOnWater().get(); + prePathManagerWalkOnLava = PathManagers.get().getSettings().getWalkOnLava().get(); - PathManagers.get().getSettings().setWalkOnWater(waterMode.get() == Mode.Solid); - PathManagers.get().getSettings().setWalkOnLava(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() { - PathManagers.get().getSettings().setWalkOnWater(prePathManagerWalkOnWater); - PathManagers.get().getSettings().setWalkOnLava(prePathManagerWalkOnLava); + 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 0aa5aae0d1..0ec72a7f64 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/NoFall.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/NoFall.java @@ -100,15 +100,15 @@ public NoFall() { @Override public void onActivate() { - prePathManagerNoFall = PathManagers.get().getSettings().getNoFall(); - if (mode.get() == Mode.Packet) PathManagers.get().getSettings().setNoFall(true); + prePathManagerNoFall = PathManagers.get().getSettings().getNoFall().get(); + if (mode.get() == Mode.Packet) PathManagers.get().getSettings().getNoFall().set(true); placedWater = false; } @Override public void onDeactivate() { - PathManagers.get().getSettings().setNoFall(prePathManagerNoFall); + 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 d399bdc99a..785df81932 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Step.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Step.java @@ -65,8 +65,8 @@ public Step() { public void onActivate() { prevStepHeight = mc.player.getStepHeight(); - prevPathManagerStep = PathManagers.get().getSettings().getStep(); - PathManagers.get().getSettings().setStep(true); + prevPathManagerStep = PathManagers.get().getSettings().getStep().get(); + PathManagers.get().getSettings().getStep().set(true); } @EventHandler @@ -84,8 +84,8 @@ private void onTick(TickEvent.Post event) { @Override public void onDeactivate() { mc.player.setStepHeight(prevStepHeight); - - PathManagers.get().getSettings().setStep(prevPathManagerStep); + + PathManagers.get().getSettings().getStep().set(prevPathManagerStep); } private float getHealth(){