Java tutorial
/* * This file is part of ProjectX. * Copyright (c) 2015 - 2018, KitsuneAlex, All rights reserved. * * ProjectX is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ProjectX 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with ProjectX. If not, see <http://www.gnu.org/licenses/lgpl>. */ package de.kitsunealex.projectx.init; import de.kitsunealex.projectx.ProjectX; import net.minecraftforge.common.config.Configuration; import org.apache.commons.lang3.time.StopWatch; import java.io.File; public class ModConfig { private static final String CATEGORY_GENERAL = "general"; private static final String CATEGORY_CLIENT = "client"; private static final String CATEGORY_WORLD = "world"; private static final String CATEGORY_COMPAT = "compat"; private static final int[] DEFAULT_ORE_PARAMS = { 3, 20, 52, 4, 8 }; public static int ANIMATION_RESOLUTION; public static boolean IMPROVED_ANIMATION; public static int GENERATOR_WEIGHT; public static int[] ORE_BLUE_PARAMS; public static int[] ORE_GREEN_PARAMS; public static int[] ORE_RED_PARAMS; public static int[] ORE_DARK_PARAMS; public static int[] ORE_LIGHT_PARAMS; public static boolean COMPAT_WAILA; public static boolean COMPAT_THAUMCRAFT; public static boolean COMPAT_FMP; public static void loadConfig(File file) { Configuration config = new Configuration(file); StopWatch timer = new StopWatch(); timer.start(); config.load(); addProperties(config); config.save(); timer.stop(); ProjectX.LOGGER.info("Loaded config file in {}ms!", timer.getTime()); } private static void addProperties(Configuration config) { ANIMATION_RESOLUTION = config.get(CATEGORY_CLIENT, "animationResolution", 32, "Resoluion of the animation for texture for blocks & items, does not affect the animation if improvedAnimation is enabled", 16, 128).getInt(); IMPROVED_ANIMATION = config.get(CATEGORY_CLIENT, "improvedAnimation", true, "Offloads the animation rendering to the GPU if OpenGL 4.3 is supported").getBoolean(); GENERATOR_WEIGHT = config.get(CATEGORY_WORLD, "generatorWeight", 1, "The weight of all world generators", 0, Integer.MAX_VALUE).getInt(); ORE_BLUE_PARAMS = config.get(CATEGORY_WORLD, "xycroniumOreBlue", DEFAULT_ORE_PARAMS, "Chance, min height, max height, min vein size, max vein size").getIntList(); ORE_GREEN_PARAMS = config.get(CATEGORY_WORLD, "xycroniumOreGreen", DEFAULT_ORE_PARAMS, "Chance, min height, max height, min vein size, max vein size").getIntList(); ORE_RED_PARAMS = config.get(CATEGORY_WORLD, "xycroniumOreRed", DEFAULT_ORE_PARAMS, "Chance, min height, max height, min vein size, max vein size").getIntList(); ORE_DARK_PARAMS = config.get(CATEGORY_WORLD, "xycroniumOreDark", DEFAULT_ORE_PARAMS, "Chance, min height, max height, min vein size, max vein size").getIntList(); ORE_LIGHT_PARAMS = config.get(CATEGORY_WORLD, "xycroniumOreLight", DEFAULT_ORE_PARAMS, "Chance, min height, max height, min vein size, max vein size").getIntList(); COMPAT_WAILA = config.get(CATEGORY_COMPAT, "waila", true, "Enable/disable WAILA integration").getBoolean(); COMPAT_THAUMCRAFT = config.get(CATEGORY_COMPAT, "thaumcraft", true, "Enable/disable Thaumcraft integration") .getBoolean(); COMPAT_FMP = config .get(CATEGORY_COMPAT, "forgeMultipart", true, "Enable/disable Forge Multipart integration") .getBoolean(); } }