下面列出了怎么用net.minecraftforge.common.config.ConfigCategory的API类实例代码及写法,或者点击链接到github查看源代码。
private void loadLocalGroups() {
//Add local groups from config
ConfigCategory config = mod.getWorldConfigCategory(world);
Iterator<ConfigCategory> localIt;
for(localIt = config.getChildren().iterator(); localIt.hasNext(); )
{
ConfigCategory localGroupCategory = localIt.next();
String name = localGroupCategory.getName();
EntityGroup localGroup = mod.getWorldEntityGroup(world, name, entityType, true, true);
if(localGroup.getGroupType() != entityType || localGroups.contains(localGroup))
continue;
if(mod.debug)
System.out.println("Load local group: " + name);
localGroups.add(localGroup);
localGroup.list = this;
}
}
private void loadGlobalGroups() {
ConfigCategory config = mod.config.getCategory("groups");
Iterator<ConfigCategory> globalIt;
for(globalIt = config.getChildren().iterator(); globalIt.hasNext(); )
{
ConfigCategory groupCategory = globalIt.next();
String name = groupCategory.getName();
EntityGroup globalGroup = mod.getEntityGroup("groups." + name);
if(globalGroup == null || globalGroup.getGroupType() != entityType)
continue;
//Get or create the local group as a copy of the global, but without a world config entry.
//Will inherit config from the global group.
EntityGroup localGroup = mod.getWorldEntityGroup(world, name, entityType, true, false);
if(localGroups.contains(localGroup))
continue; //Local group already defined
if(mod.debug)
System.out.println("Load global group: " + name);
localGroups.add(localGroup);
localGroup.list = this;
}
}
@SuppressWarnings({ "rawtypes" })
private static List<IConfigElement> createConfigElements() {
ConfigCategory modules = OpenPeripheralIntegration.instance.config().getCategory(OpenPeripheralIntegration.CATEGORY_MODULES);
modules.setLanguageKey("openperipheralintegration.config.modules");
final ConfigElement modulesElement = new ConfigElement(modules);
return Lists.<IConfigElement> newArrayList(modulesElement);
}
private static List<IConfigElement> getConfigElements(GuiScreen parent) {
List<IConfigElement> list = new ArrayList<IConfigElement>();
String prefix = "neiintegration.config.";
for (Section configSection : Config.configSections) {
list.add(new ConfigElement<ConfigCategory>(Config.config.getCategory(configSection.toLowerCase()).setLanguageKey(prefix + configSection.id)));
}
return list;
}
private static List<IConfigElement> getConfigElements(GuiScreen parent) {
List<IConfigElement> list = new ArrayList<IConfigElement>();
String prefix = SimplyJetpacks.PREFIX + "config.";
for (Section configSection : Config.configSections) {
if (configSection.client) {
list.add(new ConfigElement<ConfigCategory>(Config.configClient.getCategory(configSection.toLowerCase()).setLanguageKey(prefix + configSection.id)));
} else {
list.add(new ConfigElement<ConfigCategory>(Config.config.getCategory(configSection.toLowerCase()).setLanguageKey(prefix + configSection.id)));
}
}
return list;
}
@SuppressWarnings("rawtypes")
private static List<IConfigElement> getConfigElements(GuiScreen parent) {
List<IConfigElement> list = new ArrayList<IConfigElement>();
list.add(new ConfigElement<ConfigCategory>(config.getCategory(CATEGORY_RANDOM.toLowerCase())));
list.add(new ConfigElement<ConfigCategory>(config.getCategory(CATEGORY_VALUES.toLowerCase())));
list.add(new ConfigElement<ConfigCategory>(config.getCategory(CATEGORY_RESEARCH.toLowerCase())));
list.add(new ConfigElement<ConfigCategory>(config.getCategory(CATEGORY_OUTPUTS.toLowerCase())));
list.add(new ConfigElement<ConfigCategory>(config.getCategory(CATEGORY_MODULES.toLowerCase())));
return list;
}
private static List<IConfigElement> getConfigElements(final Configuration configuration, final String langPrefix) {
final List<IConfigElement> elements = new ArrayList<IConfigElement>();
for (final String name : configuration.getCategoryNames()) {
final ConfigCategory category = configuration.getCategory(name).setLanguageKey(langPrefix + ".category." + name);
if (category.parent == null) {
elements.add(new ConfigElement(category));
}
}
return elements;
}
private static IConfigElement createModConfig() {
final Configuration config = OpenPeripheralCore.instance.config();
final List<IConfigElement> result = Lists.newArrayList();
for (String categoryName : config.getCategoryNames()) {
if (!categoryName.equalsIgnoreCase(Config.CATEGORY_FEATURE_GROUPS)) {
ConfigCategory category = config.getCategory(categoryName);
result.add(new ConfigElement(category));
}
}
return new DummyCategoryElement("modConfig", "openperipheralcore.config.miscConfig", result);
}
public ConfigCategory getWorldConfigCategory(World world) {
return config.getCategory(getWorldPrefix(world));
}
public ConfigCategory getConfigurationCategory()
{
return _configuration.getCategory(Configuration.CATEGORY_GENERAL);
}
@EventHandler
public void preInit(FMLPreInitializationEvent evt) {
config = new Configuration(evt.getSuggestedConfigurationFile());
if (config.hasCategory("integration")) {
ConfigCategory integration = config.getCategory("integration");
config.removeCategory(integration);
}
if (checkConfig(config, "vanilla")) Integration.addModule(new ModuleVanilla());
if (checkConfig(config, "vanilla-inventory")) Integration.addModule(new ModuleVanillaInventory());
if (checkConfig(config, "vanilla-inventory-manipulation")) Integration.addModule(new ModuleVanillaInventoryManipulation());
if (checkConfig(config, "cofh-api-energy")) Integration.addModule(new ModuleCofhEnergy());
if (checkConfig(config, "cofh-api-inventory")) Integration.addModule(new ModuleCofhInventory());
if (checkConfig(config, "cofh-api-item")) Integration.addModule(new ModuleCofhItem());
if (checkConfig(config, "cofh-api-tileentity")) Integration.addModule(new ModuleCofhTileEntity());
if (checkConfig(config, "cofh-api-transport")) Integration.addModule(new ModuleCofhTransport());
if (checkConfig(config, "buildcraft-api-transport")) Integration.addModule(new ModuleBuildCraftTransport());
if (checkConfig(config, "buildcraft-api-tilenentity")) Integration.addModule(new ModuleBuildCraftTile());
if (checkConfig(config, "buildcraft-api-facades")) Integration.addModule(new ModuleBuildCraftFacades());
if (checkConfig(config, "ic2-mod")) Integration.addModule(new ModuleIC2());
if (checkConfig(config, "ic2-api")) Integration.addModule(new ModuleIC2Api());
if (checkConfig(config, "railcraft-mod")) Integration.addModule(new ModuleRailcraft());
if (checkConfig(config, "railcraft-api-carts")) Integration.addModule(new ModuleRailcraftCarts());
if (checkConfig(config, "railcraft-api-fuel")) Integration.addModule(new ModuleRailcraftFuel());
if (checkConfig(config, "thaumcraft-mod")) Integration.addModule(new ModuleThaumcraft());
if (checkConfig(config, "thaumcraft-api")) Integration.addModule(new ModuleThaumcraftApi());
if (checkConfig(config, "mfr-mod")) Integration.addModule(new ModuleMinefactoryReloaded());
if (checkConfig(config, "mfr-mod-storage")) Integration.addModule(new ModuleMinefactoryReloadedStorage());
if (checkConfig(config, "computercraft-mod")) Integration.addModule(new ModuleComputerCraft());
if (checkConfig(config, "enderstorage-mod")) Integration.addModule(new ModuleEnderStorage());
if (checkConfig(config, "forestry-mod")) Integration.addModule(new ModuleForestry());
if (checkConfig(config, "mystcraft-mod")) {
if (sameOrNewerVersion(Mods.MYSTCRAFT, "0.11.1.00")) {
if (sameOrNewerVersion(Mods.MYSTCRAFT, "0.11.6.02")) {
FMLInterModComms.sendMessage(Mods.MYSTCRAFT, "API", "openperipheral.integration.mystcraft.v2.MystcraftAccess.init");
Integration.addModule(new ModuleMystcraftV2());
} else {
Log.warn("Unsupported Mystcraft version!");
}
} else {
Log.warn("Using old Mystcraft integration, things may explode");
Integration.addModule(new ModuleMystcraftV1());
}
}
if (checkConfig(config, "thaumcraft-mod")) Integration.addModule(new ModuleThaumcraft());
if (checkConfig(config, "tmechworks-mod")) Integration.addModule(new ModuleTMechworks());
if (checkConfig(config, "thermalexpansion-mod")) Integration.addModule(new ModuleThermalExpansion());
if (checkConfig(config, "ae2-mod")) Integration.addModule(new ModuleAppEng());
ConfigProcessing.processAnnotations(MOD_ID, config, Config.class);
FMLCommonHandler.instance().bus().register(new ConfigChangeListener(MOD_ID, config));
if (config.hasChanged()) config.save();
}
public GuiChiselConfig(GuiScreen parent) {
super(parent, new ConfigElement<ConfigCategory>(Configurations.config.getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(), Chisel.MOD_ID, false, false, GuiConfig
.getAbridgedConfigPath(Configurations.config.toString()));
}