use of com.codetaylor.mc.athenaeum.parser.recipe.item.RecipeItemParser in project artisan-worktables by codetaylor.
the class ModuleTools method onPreInitializationEvent.
@Override
public void onPreInitializationEvent(FMLPreInitializationEvent event) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
File configurationDirectory = event.getModConfigurationDirectory();
Path configurationPath = Paths.get(configurationDirectory.toString(), ModuleTools.MOD_ID);
if (!Files.exists(configurationPath)) {
try {
Files.createDirectories(configurationPath);
} catch (IOException e) {
event.getModLog().error("", e);
}
}
Path generatedPath = Paths.get(configurationPath.toString(), "artisanworktables.module.Tools.Materials.Generated.json");
Path customPath = Paths.get(configurationPath.toString(), "artisanworktables.module.Tools.Materials.Custom.json");
// Delete the generated file if it exists.
if (Files.exists(generatedPath)) {
try {
Files.delete(generatedPath);
} catch (IOException e) {
event.getModLog().error("", e);
}
}
// Create and write the generated file.
BufferedWriter writer = null;
try {
writer = Files.newBufferedWriter(generatedPath);
gson.toJson(new DataCustomMaterialListFactory().create(), writer);
writer.close();
} catch (IOException e) {
event.getModLog().error("", e);
} finally {
FileHelper.closeSilently(writer);
}
// Copy the generated file to the custom file if the custom file doesn't exist.
if (!Files.exists(customPath)) {
try {
Files.copy(generatedPath, customPath);
} catch (IOException e) {
event.getModLog().error("", e);
}
}
BufferedReader reader = null;
try {
reader = Files.newBufferedReader(customPath);
DataCustomMaterialList dataCustomMaterialList = gson.fromJson(reader, DataCustomMaterialList.class);
CustomMaterialListConverter customMaterialListConverter = new CustomMaterialListConverter(new CustomMaterialValidator(), new CustomMaterialConverter(new RecipeItemParser()));
this.materialList = customMaterialListConverter.convert(dataCustomMaterialList, event.getModLog());
} catch (IOException e) {
event.getModLog().error("", e);
} finally {
FileHelper.closeSilently(reader);
}
super.onPreInitializationEvent(event);
}
Aggregations