baritone/src/main/java/baritone/bot/Settings.java

135 lines
5.0 KiB
Java
Raw Normal View History

2018-08-14 00:15:59 +00:00
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.bot;
2018-08-14 22:19:35 +00:00
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
2018-08-14 22:04:41 +00:00
import java.lang.reflect.Field;
import java.util.*;
2018-08-14 00:15:59 +00:00
/**
* Baritone's settings
*
* @author leijurv
*/
public class Settings {
2018-08-14 22:04:41 +00:00
public Setting<Boolean> allowBreak = new Setting<>(true);
public Setting<Boolean> allowPlaceThrowaway = new Setting<>(true);
/**
* It doesn't actually take twenty ticks to place a block, this cost is so high
* because we want to generally conserve blocks which might be limited
*/
public Setting<Double> blockPlacementPenalty = new Setting<>(20D);
2018-08-17 17:52:58 +00:00
public Setting<Boolean> allowSprint = new Setting<>(true);
2018-08-14 22:04:41 +00:00
public Setting<Double> costHeuristic = new <Double>Setting<Double>(4D);
public Setting<Boolean> chuckCaching = new Setting<>(false);
public Setting<Boolean> allowWaterBucketFall = new Setting<>(true);
public Setting<Integer> planningTickLookAhead = new Setting<>(150);
public Setting<Boolean> chatDebug = new Setting<>(true);
public Setting<Boolean> chatControl = new Setting<>(true); // probably false in impact
2018-08-16 22:10:15 +00:00
public Setting<Boolean> renderPath = new Setting<>(true);
2018-08-14 22:04:41 +00:00
public Setting<Boolean> fadePath = new Setting<>(false); // give this a better name in the UI, like "better path fps" idk
2018-08-16 22:10:15 +00:00
public Setting<Number> pathTimeoutMS = new Setting<>(4000L);
2018-08-14 22:04:41 +00:00
public Setting<Boolean> slowPath = new Setting<>(false);
2018-08-16 22:10:15 +00:00
public Setting<Number> slowPathTimeDelayMS = new Setting<>(100L);
public Setting<Number> slowPathTimeoutMS = new Setting<>(40000L);
public Setting<List<Item>> acceptableThrowawayItems = new Setting<>(Arrays.asList(
2018-08-14 22:19:35 +00:00
Item.getItemFromBlock(Blocks.DIRT),
Item.getItemFromBlock(Blocks.COBBLESTONE),
Item.getItemFromBlock(Blocks.NETHERRACK)
));
2018-08-16 00:53:42 +00:00
public Setting<Boolean> renderGoal = new Setting<>(true);
2018-08-16 22:10:15 +00:00
public Setting<Integer> pathingMaxChunkBorderFetch = new Setting<>(50);
public Setting<Boolean> backtrackCostFavor = new Setting<>(true);
2018-08-17 19:24:40 +00:00
public Setting<Double> backtrackCostFavoringCoefficient = new Setting<>(0.9); // see issue #18
2018-08-16 22:34:23 +00:00
public Setting<Float> pathRenderLineWidth = new Setting<>(5F);
public Setting<Float> goalRenderLineWidth = new Setting<>(3F);
2018-08-14 22:04:41 +00:00
public final Map<String, Setting<?>> byName;
public final List<Setting<?>> allSettings;
public class Setting<T> {
public T value;
private String name;
2018-08-14 22:16:38 +00:00
private final Class<T> klass;
2018-08-14 22:04:41 +00:00
2018-08-14 22:16:38 +00:00
private Setting(T value) {
2018-08-14 22:24:23 +00:00
if (value == null) {
throw new IllegalArgumentException("Cannot determine value type class from null");
}
2018-08-14 22:04:41 +00:00
this.value = value;
2018-08-14 22:16:38 +00:00
this.klass = (Class<T>) value.getClass();
2018-08-14 22:04:41 +00:00
}
2018-08-14 00:15:59 +00:00
2018-08-16 22:10:15 +00:00
public final <K extends T> K get() {
return (K) value;
2018-08-14 22:04:41 +00:00
}
public final String getName() {
return name;
}
2018-08-14 22:22:52 +00:00
public Class<T> getValueClass() {
return klass;
}
2018-08-14 22:04:41 +00:00
public String toString() {
return name + ": " + value;
}
2018-08-14 00:15:59 +00:00
}
2018-08-14 22:04:41 +00:00
// here be dragons
{
Field[] temp = getClass().getFields();
HashMap<String, Setting<?>> tmpByName = new HashMap<>();
List<Setting<?>> tmpAll = new ArrayList<>();
2018-08-14 22:16:38 +00:00
try {
for (Field field : temp) {
if (field.getType().equals(Setting.class)) {
2018-08-14 22:04:41 +00:00
Setting<?> setting = (Setting<? extends Object>) field.get(this);
String name = field.getName();
setting.name = name;
if (tmpByName.containsKey(name)) {
throw new IllegalStateException("Duplicate setting name");
}
tmpByName.put(name, setting);
tmpAll.add(setting);
}
}
2018-08-14 22:16:38 +00:00
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
2018-08-14 22:04:41 +00:00
}
byName = Collections.unmodifiableMap(tmpByName);
allSettings = Collections.unmodifiableList(tmpAll);
}
2018-08-14 22:16:38 +00:00
public <T> List<Setting<T>> getByValueType(Class<T> klass) {
ArrayList<Setting<T>> result = new ArrayList<>();
2018-08-14 22:04:41 +00:00
for (Setting<?> setting : allSettings) {
if (setting.klass.equals(klass)) {
2018-08-14 22:16:38 +00:00
result.add((Setting<T>) setting);
2018-08-14 22:04:41 +00:00
}
}
return result;
}
Settings() { }
2018-08-14 00:15:59 +00:00
}