static void setBounds(Property prop, Bound<?> bound) throws IllegalArgumentException { if (bound.equals(Bound.MAX_BOUND)) { return; } if (prop.getType() == Type.INTEGER) { Bound<Integer> b = Bound.of(bound.min.intValue(), bound.max.intValue()); prop.setMinValue(b.min); prop.setMaxValue(b.max); } else if (prop.getType() == Type.DOUBLE) { Bound<Double> b = Bound.of(bound.min.doubleValue(), bound.max.doubleValue()); prop.setMinValue(b.min); prop.setMaxValue(b.max); } else { throw new IllegalArgumentException(String.format("A mod tried to set bounds %s on a property that was not either of Integer of Double type.", bound)); } }
public double getMachineDouble(String machine, String prop, double def, double min, double max, String comment) { Property p = config.get(CATEGORY_MACHINES + "." + machine.replaceFirst("tile.", ""), prop, def); p.setComment(comment); p.setLanguageKey(String.format("%s.config.%s", machine, prop)); p.setMinValue(min); p.setMaxValue(max); return p.getDouble(def); }
public static float FLOAT(Configuration config, String name, String category, float defaultValue, float minValue, float maxValue){ Property prop = config.get(category, name, Float.toString(defaultValue), name); prop.setLanguageKey(name); prop.setComment(""); prop.setMinValue(minValue); prop.setMaxValue(maxValue); try { float parseFloat = Float.parseFloat(prop.getString()); return Floats.constrainToRange(parseFloat, minValue, maxValue); } catch (Exception e) { FMLLog.log.error("Failed to get float for {}/{}", name, category, e); } return defaultValue; } }
public static double DOUBLE(Configuration config, String category, String name, float defaultValue, float minValue, float maxValue){ Property prop = config.get(category, name, defaultValue); prop.setLanguageKey(name); prop.setComment(""); prop.setMinValue(minValue); prop.setMaxValue(maxValue); return (prop.getDouble(defaultValue) < minValue ? minValue : (prop.getDouble(defaultValue) > maxValue ? maxValue : prop.getDouble(defaultValue))); }
public static int INT(Configuration config, String category, String name, int defaultValue, int minValue, int maxValue){ Property prop = config.get(category, name, defaultValue); prop.setLanguageKey(name); prop.setComment(""); prop.setMinValue(minValue); prop.setMaxValue(maxValue); return prop.getInt(defaultValue) < minValue ? minValue : (prop.getInt(defaultValue) > maxValue ? maxValue : prop.getInt(defaultValue)); }
private TreeConfig parseConfig(LocalizedConfiguration config) { for (int dimId : config.get(CONFIG_CATEGORY_TREE + "." + treeName + ".dimensions", "blacklist", new int[0]).getIntList()) { blacklistedDimensions.add(dimId); } for (int dimId : config.get(CONFIG_CATEGORY_TREE + "." + treeName + ".dimensions", "whitelist", new int[0]).getIntList()) { whitelistedDimensions.add(dimId); } for (String typeName : config.get(CONFIG_CATEGORY_TREE + "." + treeName + ".biomes.blacklist", "types", new String[0]).getStringList()) { blacklistedBiomeTypes.add(BiomeDictionary.Type.getType(typeName)); } for (String biomeName : config.get(CONFIG_CATEGORY_TREE + "." + treeName + ".biomes.blacklist", "names", new String[0]).getStringList()) { Biome biome = ForgeRegistries.BIOMES.getValue(new ResourceLocation(biomeName)); if (biome != null) { blacklistedBiomes.add(biome); } else { Log.error("Failed to identify biome for the config property for the tree with the uid '" + treeName + "'. No biome is registered under the registry name '" + biomeName + "'."); } } spawnRarity = (float) config.get(CONFIG_CATEGORY_TREE + "." + treeName, "rarity", defaultRarity).setMinValue(0.0F).setMaxValue(1.0F).getDouble(); return this; }