Search in sources :

Example 1 with IEnderIOAddon

use of crazypants.enderio.api.addon.IEnderIOAddon in project EnderIO by SleepyTrousers.

the class RecipeLoader method addRecipes.

public static void addRecipes() {
    final RecipeFactory recipeFactory = new RecipeFactory(Config.getConfigDirectory(), EnderIO.DOMAIN);
    recipeFactory.createFolder("recipes");
    recipeFactory.createFolder("recipes/user");
    recipeFactory.createFolder("recipes/examples");
    recipeFactory.placeXSD("recipes");
    recipeFactory.placeXSD("recipes/user");
    recipeFactory.placeXSD("recipes/examples");
    recipeFactory.createFileUser("recipes/user/user_recipes.xml");
    NNList<Triple<Integer, RecipeFactory, String>> recipeFiles = new NNList<>();
    for (ModContainer modContainer : Loader.instance().getModList()) {
        Object mod = modContainer.getMod();
        if (mod instanceof IEnderIOAddon) {
            recipeFiles.addAll(((IEnderIOAddon) mod).getRecipeFiles());
            for (String filename : ((IEnderIOAddon) mod).getExampleFiles()) {
                recipeFactory.copyCore("recipes/examples/" + filename + ".xml");
            }
        }
    }
    Collections.sort(recipeFiles, new Comparator<Triple<Integer, RecipeFactory, String>>() {

        @Override
        public int compare(Triple<Integer, RecipeFactory, String> o1, Triple<Integer, RecipeFactory, String> o2) {
            return o1.getLeft().compareTo(o2.getLeft());
        }
    });
    Set<File> userfiles = new HashSet<>(recipeFactory.listXMLFiles("recipes/user"));
    for (Triple<Integer, RecipeFactory, String> triple : recipeFiles) {
        RecipeFactory factory = triple.getMiddle();
        if (factory != null) {
            userfiles.addAll(factory.listXMLFiles("recipes/user"));
        }
    }
    /*
     * Note that we load the recipes in core-imc-user order but merge them in reverse order. The loading order allows aliases to be added in the expected order,
     * while the reverse merging allows user recipes to replace imc recipes to replace core recipes.
     */
    Recipes config = new Recipes();
    if (RecipeConfig.loadCoreRecipes.get()) {
        try {
            for (Triple<Integer, RecipeFactory, String> triple : recipeFiles) {
                config = readCoreFile(NullHelper.first(triple.getMiddle(), recipeFactory), "recipes/" + triple.getRight()).addRecipes(config, false);
            }
        } catch (InvalidRecipeConfigException e) {
            recipeError(NullHelper.first(e.getFilename(), "Core Recipes"), e.getMessage());
        }
    }
    if (imcRecipes != null) {
        config = handleIMCRecipes(config);
        imcRecipes = null;
    }
    for (File file : userfiles) {
        final Recipes userFile = readUserFile(recipeFactory, file.getName(), file);
        if (userFile != null) {
            try {
                config = userFile.addRecipes(config, true);
            } catch (InvalidRecipeConfigException e) {
                recipeError(NullHelper.first(e.getFilename(), file.getName()), e.getMessage());
            }
        }
    }
    config.register("");
    for (ModContainer modContainer : Loader.instance().getModList()) {
        Object mod = modContainer.getMod();
        if (mod instanceof IEnderIOAddon) {
            ((IEnderIOAddon) mod).postRecipeRegistration();
        }
    }
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer) IEnderIOAddon(crazypants.enderio.api.addon.IEnderIOAddon) Triple(org.apache.commons.lang3.tuple.Triple) NNList(com.enderio.core.common.util.NNList) Recipes(crazypants.enderio.base.config.recipes.xml.Recipes) File(java.io.File) HashSet(java.util.HashSet)

Example 2 with IEnderIOAddon

use of crazypants.enderio.api.addon.IEnderIOAddon in project EnderIO by SleepyTrousers.

the class GuiConfigFactoryEIO method getConfigElements.

/*
   * Note: We are using the Forge config structure to build our GUI. This makes our ConfigElementEio a bit hacky, so it would be better to keep our own tree in
   * ValueFactory.
   */
private static List<IConfigElement> getConfigElements(GuiScreen parent) {
    List<IConfigElement> result = new ArrayList<>();
    List<ModContainer> modList = Loader.instance().getModList();
    for (ModContainer modContainer : modList) {
        Object mod = modContainer.getMod();
        if (mod instanceof IEnderIOAddon) {
            Configuration configuration = ((IEnderIOAddon) mod).getConfiguration();
            if (configuration != null) {
                List<IConfigElement> list = new ArrayList<>();
                for (String section : configuration.getCategoryNames()) {
                    final ConfigCategory category = configuration.getCategory(section);
                    category.setLanguageKey(EnderIO.lang.addPrefix("config." + category.getQualifiedName()));
                    if (!category.isChild()) {
                        list.add(new ConfigElementEio(category));
                    }
                }
                result.add(new DummyCategoryElement(modContainer.getName(), EnderIO.lang.addPrefix("config.title." + modContainer.getModId()), list));
            }
        }
    }
    return result;
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer) Configuration(net.minecraftforge.common.config.Configuration) ConfigCategory(net.minecraftforge.common.config.ConfigCategory) ArrayList(java.util.ArrayList) IEnderIOAddon(crazypants.enderio.api.addon.IEnderIOAddon) IConfigElement(net.minecraftforge.fml.client.config.IConfigElement) DummyCategoryElement(net.minecraftforge.fml.client.config.DummyConfigElement.DummyCategoryElement)

Aggregations

IEnderIOAddon (crazypants.enderio.api.addon.IEnderIOAddon)2 ModContainer (net.minecraftforge.fml.common.ModContainer)2 NNList (com.enderio.core.common.util.NNList)1 Recipes (crazypants.enderio.base.config.recipes.xml.Recipes)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ConfigCategory (net.minecraftforge.common.config.ConfigCategory)1 Configuration (net.minecraftforge.common.config.Configuration)1 DummyCategoryElement (net.minecraftforge.fml.client.config.DummyConfigElement.DummyCategoryElement)1 IConfigElement (net.minecraftforge.fml.client.config.IConfigElement)1 Triple (org.apache.commons.lang3.tuple.Triple)1