/* * 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 . */ package baritone.bot; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import java.lang.reflect.Field; import java.util.*; /** * Baritone's settings * * @author leijurv */ public class Settings { public Setting allowBreak = new Setting<>(true); public Setting 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 blockPlacementPenalty = new Setting<>(20D); public Setting allowSprint = new Setting<>(true); public Setting costHeuristic = new Setting(4D); public Setting chuckCaching = new Setting<>(false); public Setting allowWaterBucketFall = new Setting<>(true); public Setting planningTickLookAhead = new Setting<>(150); public Setting chatDebug = new Setting<>(true); public Setting chatControl = new Setting<>(true); // probably false in impact public Setting renderPath = new Setting<>(true); public Setting fadePath = new Setting<>(false); // give this a better name in the UI, like "better path fps" idk public Setting pathTimeoutMS = new Setting<>(4000L); public Setting slowPath = new Setting<>(false); public Setting slowPathTimeDelayMS = new Setting<>(100L); public Setting slowPathTimeoutMS = new Setting<>(40000L); public Setting> acceptableThrowawayItems = new Setting<>(Arrays.asList( Item.getItemFromBlock(Blocks.DIRT), Item.getItemFromBlock(Blocks.COBBLESTONE), Item.getItemFromBlock(Blocks.NETHERRACK) )); public Setting renderGoal = new Setting<>(true); public Setting pathingMaxChunkBorderFetch = new Setting<>(50); public Setting backtrackCostFavor = new Setting<>(true); public Setting backtrackCostFavoringCoefficient = new Setting<>(0.9); // see issue #18 public Setting pathRenderLineWidth = new Setting<>(5F); public Setting goalRenderLineWidth = new Setting<>(3F); public final Map> byName; public final List> allSettings; public class Setting { public T value; private String name; private final Class klass; private Setting(T value) { if (value == null) { throw new IllegalArgumentException("Cannot determine value type class from null"); } this.value = value; this.klass = (Class) value.getClass(); } public final K get() { return (K) value; } public final String getName() { return name; } public Class getValueClass() { return klass; } public String toString() { return name + ": " + value; } } // here be dragons { Field[] temp = getClass().getFields(); HashMap> tmpByName = new HashMap<>(); List> tmpAll = new ArrayList<>(); try { for (Field field : temp) { if (field.getType().equals(Setting.class)) { Setting setting = (Setting) 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); } } } catch (IllegalAccessException e) { throw new RuntimeException(e); } byName = Collections.unmodifiableMap(tmpByName); allSettings = Collections.unmodifiableList(tmpAll); } public List> getByValueType(Class klass) { ArrayList> result = new ArrayList<>(); for (Setting setting : allSettings) { if (setting.klass.equals(klass)) { result.add((Setting) setting); } } return result; } Settings() { } }