mirror of
https://github.com/cabaletta/baritone
synced 2024-12-23 07:23:45 +00:00
settings overhaul
This commit is contained in:
parent
16dcd2f44d
commit
d32e822057
2
USAGE.md
2
USAGE.md
@ -21,7 +21,7 @@ Other clients like Kami and Asuna have their own custom things (like `-path`), a
|
||||
|
||||
`help` for (rudimentary) help. You can see what it says [here](https://github.com/cabaletta/baritone/blob/master/src/main/java/baritone/utils/ExampleBaritoneControl.java#L53).
|
||||
|
||||
To toggle a boolean setting, just say its name in chat (for example saying `allowBreak` toggles whether Baritone will consider breaking blocks). For a numeric setting, say its name then the new value (like `primaryTimeoutMS 250`). It's case insensitive.
|
||||
To toggle a boolean setting, just say its name in chat (for example saying `allowBreak` toggles whether Baritone will consider breaking blocks). For a numeric setting, say its name then the new value (like `primaryTimeoutMS 250`). It's case insensitive. To reset a setting to its default value, say `acceptableThrowawayItems reset`. To reset all settings, say `reset`. To see all settings that have been modified from their default values, say `modified`.
|
||||
|
||||
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
package baritone.api;
|
||||
|
||||
import baritone.api.utils.SettingsUtil;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
@ -704,12 +705,6 @@ public final class Settings {
|
||||
*/
|
||||
public final List<Setting<?>> allSettings;
|
||||
|
||||
public void reset() {
|
||||
for (Setting setting : allSettings) {
|
||||
setting.value = setting.defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public final class Setting<T> {
|
||||
public T value;
|
||||
public final T defaultValue;
|
||||
@ -739,8 +734,13 @@ public final class Settings {
|
||||
return klass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name + ": " + value;
|
||||
return SettingsUtil.settingToString(this);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
value = defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,10 +27,8 @@ import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
@ -89,22 +87,8 @@ public class SettingsUtil {
|
||||
|
||||
public static synchronized void save(Settings settings) {
|
||||
try (BufferedWriter out = Files.newBufferedWriter(SETTINGS_PATH)) {
|
||||
for (Settings.Setting setting : settings.allSettings) {
|
||||
if (setting.get() == null) {
|
||||
System.out.println("NULL SETTING?" + setting.getName());
|
||||
continue;
|
||||
}
|
||||
if (setting.getName().equals("logger")) {
|
||||
continue; // NO
|
||||
}
|
||||
if (setting.value == setting.defaultValue) {
|
||||
continue;
|
||||
}
|
||||
SettingsIO io = map.get(setting.getValueClass());
|
||||
if (io == null) {
|
||||
throw new IllegalStateException("Missing " + setting.getValueClass() + " " + setting + " " + setting.getName());
|
||||
}
|
||||
out.write(setting.getName() + " " + io.toString.apply(setting.get()) + "\n");
|
||||
for (Settings.Setting setting : modifiedSettings(settings)) {
|
||||
out.write(settingToString(setting) + "\n");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Exception thrown while saving Baritone settings!");
|
||||
@ -112,7 +96,36 @@ public class SettingsUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static void parseAndApply(Settings settings, String settingName, String settingValue) throws IllegalStateException, NumberFormatException {
|
||||
public static List<Settings.Setting> modifiedSettings(Settings settings) {
|
||||
List<Settings.Setting> modified = new ArrayList<>();
|
||||
for (Settings.Setting setting : settings.allSettings) {
|
||||
if (setting.get() == null) {
|
||||
System.out.println("NULL SETTING?" + setting.getName());
|
||||
continue;
|
||||
}
|
||||
if (setting.getName().equals("logger")) {
|
||||
continue; // NO
|
||||
}
|
||||
if (setting.value == setting.defaultValue) {
|
||||
continue;
|
||||
}
|
||||
modified.add(setting);
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
public static String settingToString(Settings.Setting setting) throws IllegalStateException {
|
||||
if (setting.getName().equals("logger")) {
|
||||
return "logger";
|
||||
}
|
||||
SettingsIO io = map.get(setting.getValueClass());
|
||||
if (io == null) {
|
||||
throw new IllegalStateException("Missing " + setting.getValueClass() + " " + setting.getName());
|
||||
}
|
||||
return setting.getName() + " " + io.toString.apply(setting.get());
|
||||
}
|
||||
|
||||
public static void parseAndApply(Settings settings, String settingName, String settingValue) throws IllegalStateException, NumberFormatException {
|
||||
Settings.Setting setting = settings.byLowerName.get(settingName);
|
||||
if (setting == null) {
|
||||
throw new IllegalStateException("No setting by that name");
|
||||
|
@ -117,12 +117,33 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (msg.equals("baritone") || msg.equals("settings")) {
|
||||
for (Settings.Setting<?> setting : Baritone.settings().allSettings) {
|
||||
if (msg.equals("baritone") || msg.equals("modifiedsettings") || msg.startsWith("settings m") || msg.equals("modified")) {
|
||||
logDirect("All settings that have been modified from their default values:");
|
||||
for (Settings.Setting<?> setting : SettingsUtil.modifiedSettings(Baritone.settings())) {
|
||||
logDirect(setting.toString());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (msg.startsWith("settings")) {
|
||||
String rest = msg.substring("settings".length());
|
||||
try {
|
||||
int page = Integer.parseInt(rest.trim());
|
||||
int min = page * 10;
|
||||
int max = Math.min(Baritone.settings().allSettings.size(), (page + 1) * 10);
|
||||
logDirect("Settings " + min + " to " + (max - 1) + ":");
|
||||
for (int i = min; i < max; i++) {
|
||||
logDirect(Baritone.settings().allSettings.get(i).toString());
|
||||
}
|
||||
} catch (Exception ex) { // NumberFormatException | ArrayIndexOutOfBoundsException and probably some others I'm forgetting lol
|
||||
ex.printStackTrace();
|
||||
logDirect("All settings:");
|
||||
for (Settings.Setting<?> setting : Baritone.settings().allSettings) {
|
||||
logDirect(setting.toString());
|
||||
}
|
||||
logDirect("To get one page of ten settings at a time, do settings <num>");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (msg.equals("") || msg.equals("help") || msg.equals("?")) {
|
||||
for (String line : HELP_MSG.split("\n")) {
|
||||
logDirect(line);
|
||||
@ -130,31 +151,24 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
return true;
|
||||
}
|
||||
if (msg.contains(" ")) {
|
||||
String[] data = msg.split(" ");
|
||||
if (data.length == 2) {
|
||||
Settings.Setting setting = Baritone.settings().byLowerName.get(data[0]);
|
||||
if (setting != null) {
|
||||
String settingName = msg.substring(0, msg.indexOf(' '));
|
||||
String settingValue = msg.substring(msg.indexOf(' ') + 1);
|
||||
Settings.Setting setting = Baritone.settings().byLowerName.get(settingName);
|
||||
if (setting != null) {
|
||||
if (settingValue.equals("reset")) {
|
||||
logDirect("Resetting setting " + settingName + " to default value.");
|
||||
setting.reset();
|
||||
} else {
|
||||
try {
|
||||
if (setting.value.getClass() == Long.class) {
|
||||
setting.value = Long.parseLong(data[1]);
|
||||
}
|
||||
if (setting.value.getClass() == Integer.class) {
|
||||
setting.value = Integer.parseInt(data[1]);
|
||||
}
|
||||
if (setting.value.getClass() == Double.class) {
|
||||
setting.value = Double.parseDouble(data[1]);
|
||||
}
|
||||
if (setting.value.getClass() == Float.class) {
|
||||
setting.value = Float.parseFloat(data[1]);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
logDirect("Unable to parse " + data[1]);
|
||||
SettingsUtil.parseAndApply(Baritone.settings(), settingName, settingValue);
|
||||
} catch (Exception ex) {
|
||||
logDirect("Unable to parse setting");
|
||||
return true;
|
||||
}
|
||||
SettingsUtil.save(Baritone.settings());
|
||||
logDirect(setting.toString());
|
||||
return true;
|
||||
}
|
||||
SettingsUtil.save(Baritone.settings());
|
||||
logDirect(setting.toString());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (Baritone.settings().byLowerName.containsKey(msg)) {
|
||||
@ -278,7 +292,10 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
return true;
|
||||
}
|
||||
if (msg.equals("reset")) {
|
||||
Baritone.settings().reset();
|
||||
for (Settings.Setting setting : Baritone.settings().allSettings) {
|
||||
setting.reset();
|
||||
}
|
||||
SettingsUtil.save(Baritone.settings());
|
||||
logDirect("Baritone settings reset");
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user