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);
|
|
|
|
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> renderPath = new Setting<>(true);
|
|
|
|
public Setting<Boolean> chatDebug = new Setting<>(true);
|
|
|
|
public Setting<Boolean> chatControl = new Setting<>(true); // probably false in impact
|
|
|
|
public Setting<Boolean> fadePath = new Setting<>(false); // give this a better name in the UI, like "better path fps" idk
|
|
|
|
public Setting<Boolean> slowPath = new Setting<>(false);
|
2018-08-14 22:19:35 +00:00
|
|
|
public Setting<List<Item>> acceptableThrowAwayItems = new Setting<>(Arrays.asList(
|
|
|
|
Item.getItemFromBlock(Blocks.DIRT),
|
|
|
|
Item.getItemFromBlock(Blocks.COBBLESTONE),
|
|
|
|
Item.getItemFromBlock(Blocks.NETHERRACK)
|
|
|
|
));
|
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-14 22:04:41 +00:00
|
|
|
public final T get() {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|