/** * Parses the string and returns the rarity between 0.000001 and 100 * (inclusive) * @param string The string to parse. * @return The rarity. * @throws InvalidConfigException If the number is invalid. */ protected final double readRarity(String string) throws InvalidConfigException { return StringHelper.readDouble(string, 0.000001, 100); }
@Override public Double read(String string) throws InvalidConfigException { return StringHelper.readDouble(string, minValue, maxValue); }
@Override public Float read(String string) throws InvalidConfigException { return (float) StringHelper.readDouble(string, minValue, maxValue); }
/** * Parses the string and returns a number between minValue and * maxValue. * @param string The string to parse. * @param minValue The minimum value. * @param maxValue The maximum value. * @return A double between min and max. * @throws InvalidConfigException If the number is invalid. */ protected final double readDouble(String string, double minValue, double maxValue) throws InvalidConfigException { return StringHelper.readDouble(string, minValue, maxValue); }
@Override public double[] read(String string) throws InvalidConfigException { if (string.isEmpty()) { return new double[0]; } String[] split = StringHelper.readCommaSeperatedString(string); double[] values = new double[split.length]; for (int i = 0; i < split.length; i++) { // Trimming the values allows "Value1, Value2" values[i] = StringHelper.readDouble(split[i], -Double.MAX_VALUE, Double.MAX_VALUE); } return values; }
public MultipleLayersSurfaceGenerator(String[] args) throws InvalidConfigException { if (args.length < 2) { throw new InvalidConfigException("Needs at least two arguments"); } layerChoices = new ArrayList<LayerChoice>(); for (int i = 0; i < args.length - 2; i += 3) { LocalMaterialData surfaceBlock = TerrainControl.readMaterial(args[i]); LocalMaterialData groundBlock = TerrainControl.readMaterial(args[i+1]); float maxNoise = (float) StringHelper.readDouble(args[i + 2], -20, 20); layerChoices.add(new LayerChoice(surfaceBlock, groundBlock, maxNoise)); } Collections.sort(layerChoices); }