/// <summary> /// Called by APIProvider ModEntries /// </summary> public static void RegisterRecipes() { for (int i = 0; i < LimitsProviders.Count; i++) { try { var recipeLimitsProvider = LimitsProviders[i].Value; var list = recipeLimitsProvider.GetCraftingLimitsRecipes(); if (list != null) { RecipeStorage.AddLimitTypeRecipes(recipeLimitsProvider.GetCraftingLimitsType(), list); var triggers = recipeLimitsProvider.GetCraftingLimitsTriggers(); if (triggers == null) { RecipeStorage.AddBlockToRecipeMapping(LimitsProviders[i].Key, recipeLimitsProvider.GetCraftingLimitsType()); } else { for (int i2 = 0; i2 < triggers.Count; i2++) { RecipeStorage.AddBlockToRecipeMapping(triggers[i2], recipeLimitsProvider.GetCraftingLimitsType()); } } } } catch (Exception e) { Log.WriteException("Error registering recipes for blockjob {0}:", e, LimitsProviders[i].ToString()); } } LimitsProviders = null; }
public static void LoadRecipes() { foreach (string fullDirPath in Directory.GetDirectories(BlocksDirectory)) { string packageName = Path.GetFileName(fullDirPath); if (packageName.Equals("examples")) { continue; } Pipliz.Log.Write(string.Format("Started loading '{0}' recipes...", packageName)); try { foreach (string[] jobAndFilename in new string[][] { new string[] { "workbench", "crafting.json" }, new string[] { "tailorshop", "tailoring.json" }, new string[] { "grindstone", "grinding.json" }, new string[] { "mint", "minting.json" }, new string[] { "shop", "shopping.json" }, new string[] { "technologisttable", "technologist.json" }, new string[] { "furnace", "smelting.json" }, new string[] { "oven", "baking.json" } }) { JSONNode jsonRecipes; if (Pipliz.JSON.JSON.Deserialize(MultiPath.Combine(BlocksDirectory, packageName, jobAndFilename [1]), out jsonRecipes, false)) { if (jsonRecipes.NodeType == NodeType.Array) { foreach (JSONNode craftingEntry in jsonRecipes.LoopArray()) { foreach (string recipePart in new string[] { "results", "requires" }) { JSONNode jsonRecipeParts = craftingEntry.GetAs <JSONNode> (recipePart); foreach (JSONNode jsonRecipePart in jsonRecipeParts.LoopArray()) { string type = jsonRecipePart.GetAs <string> ("type"); string realtype; if (type.StartsWith(VANILLA_PREFIX)) { realtype = type.Substring(VANILLA_PREFIX.Length); } else { realtype = MOD_PREFIX + packageName + "." + type; } Pipliz.Log.Write(string.Format("Rewriting block recipe type from '{0}' to '{1}'", type, realtype)); jsonRecipePart.SetAs("type", realtype); } } Recipe craftingRecipe = new Recipe(craftingEntry); RecipeStorage.AddRecipe(craftingRecipe); RecipeStorage.AddBlockToRecipeMapping(jobAndFilename [0], craftingRecipe.Name); if (jobAndFilename [1].Equals("crafting.json")) { RecipePlayer.AddDefaultRecipe(craftingRecipe); } } } else { Pipliz.Log.WriteError(string.Format("Expected json array in {0}, but got {1} instead", jobAndFilename [1], jsonRecipes.NodeType)); } } } } catch (Exception exception) { Pipliz.Log.WriteError(string.Format("Exception while loading recipes from {0}; {1}", packageName, exception.Message)); } } }