use of crazypants.enderio.base.config.recipes.xml.Recipes 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();
}
}
}
use of crazypants.enderio.base.config.recipes.xml.Recipes in project EnderIO by SleepyTrousers.
the class RecipeLoader method handleIMCRecipes.
private static Recipes handleIMCRecipes(Recipes config) {
for (String recipe : imcRecipes) {
try (InputStream is = IOUtils.toInputStream(recipe, Charset.forName("UTF-8"))) {
Recipes recipes = RecipeFactory.readStax(new Recipes(), "recipes", is);
recipes.enforceValidity();
config = recipes.addRecipes(config, true);
} catch (InvalidRecipeConfigException e) {
recipeError(NullHelper.first(e.getFilename(), "IMC from other mod"), e.getMessage());
} catch (IOException e) {
Log.error("IO error while parsing string:");
e.printStackTrace();
recipeError("IMC from other mod", "IO error while parsing string:" + e.getMessage());
} catch (XMLStreamException e) {
Log.error("IMC has malformed XML:");
e.printStackTrace();
recipeError("IMC from other mod", "IMC has malformed XML:" + e.getMessage());
}
}
return config;
}
use of crazypants.enderio.base.config.recipes.xml.Recipes in project EnderIO by SleepyTrousers.
the class RecipeLoader method addIMCRecipe.
public static void addIMCRecipe(String recipe) throws XMLStreamException, IOException {
if (imcRecipes != null) {
imcRecipes.add(recipe);
} else {
try (InputStream is = IOUtils.toInputStream(recipe, Charset.forName("UTF-8"))) {
Recipes recipes = RecipeFactory.readStax(new Recipes(), "recipes", is);
recipes.enforceValidity();
recipes.register("IMC recipes");
}
throw new InvalidRecipeConfigException("empty XML");
}
}
Aggregations