public static void LoadRecipes() { try { Pipliz.Log.Write(string.Format("Started loading door recipes...")); JSONNode jsonCrafting; if (!JSON.Deserialize(Path.Combine(DoorsDirectory, "doorscrafting.json"), out jsonCrafting, false)) { Pipliz.Log.Write("No door recipes file found, so no recipes loaded"); return; } if (jsonCrafting.NodeType != NodeType.Array) { Pipliz.Log.WriteError(string.Format("Expected json array in {0}, but got {1} instead", "doorscrafting.json", jsonCrafting.NodeType)); return; } foreach (JSONNode craftingEntry in jsonCrafting.LoopArray()) { JSONNode jsonResults = craftingEntry.GetAs <JSONNode> ("results"); foreach (JSONNode jsonResult in jsonResults.LoopArray()) { string type = jsonResult.GetAs <string> ("type"); string realtype = MOD_PREFIX + type; Pipliz.Log.Write(string.Format("Replacing door recipe result type '{0}' with '{1}'", type, realtype)); jsonResult.SetAs("type", realtype); } RecipePlayer.AddDefaultRecipe(new Recipe(craftingEntry)); } } catch (Exception exception) { Pipliz.Log.WriteError(string.Format("Exception while loading door recipes from {0}; {1}", "doorscrafting.json", exception.Message)); } }
public static void LoadRecipes() { buildtoolRecipe = new Recipe(JOB_ITEM_KEY + ".recipe", new List <InventoryItem> () { new InventoryItem(BuiltinBlocks.IronIngot, 1), new InventoryItem(BuiltinBlocks.Planks, 1) }, new InventoryItem(JOB_ITEM_KEY, 1), 0); RecipeStorage.AddDefaultLimitTypeRecipe("pipliz.crafter", buildtoolRecipe); RecipePlayer.AddDefaultRecipe(buildtoolRecipe); }
/// <summary> /// Does all the work of adding this recipe to the server's database. Should be called in the AfterItemTypesDefined callback. /// </summary> public void addRecipeToLimitType() { if (enabled) { try { // First remove any recipes we are replacing. foreach (string deleteMe in Replaces) { Pipliz.Log.Write("{0}: Recipe {1} is marked as replacing {2}, attempting to comply.", NAMESPACE == null ? "" : NAMESPACE, this.Name, deleteMe); RecipeHelper.tryRemoveRecipe(deleteMe); } // Convert shell references into actual InventoryItem objects. foreach (ItemShell I in Results) { if (Variables.itemsMaster == null) { Pipliz.Log.WriteError("{0}.SimpleRecipe.addRecipeToLimitType() has reached a critical error: 'Variables.itemsMaster' is not yet available. Recipe: {1}", NAMESPACE == null ? "" : NAMESPACE, this.Name); } else { string useKey = I.asSimpleItem == null ? I.strItemkey : I.asSimpleItem.ID; if (Variables.itemsMaster.ContainsKey(useKey)) { realResults.Add(new InventoryItem(useKey, I.intAmount)); } else { Pipliz.Log.WriteError("{0}: A problem occurred adding recipe RESULT {1} to recipe {2}, the item key was not found.", NAMESPACE == null ? "" : NAMESPACE, I.strItemkey, this.Name); } } } foreach (ItemShell I in Requirements) { if (Variables.itemsMaster == null) { Pipliz.Log.WriteError("{0}.SimpleRecipe.addRecipeToLimitType() has reached a critical error: 'Variables.itemsMaster' is not yet available. Recipe: {1}", NAMESPACE == null ? "" : NAMESPACE, this.Name); } else { string useKey = I.asSimpleItem == null ? I.strItemkey : I.asSimpleItem.ID; if (Variables.itemsMaster.ContainsKey(useKey)) { realRequirements.Add(new InventoryItem(useKey, I.intAmount)); } else { Pipliz.Log.WriteError("{0}: A problem occurred adding recipe REQUIREMENT {1} to recipe {2}, the item key was not found.", NAMESPACE == null ? "" : NAMESPACE, I.strItemkey, this.Name); } } } // Build actual Recipe object. Recipe thisRecipe = new Recipe(this.fullName, this.realRequirements, this.realResults, this.defaultLimit, this.isOptional, this.defaultPriority); // Commence registering it. Pipliz.Log.Write("{0}: Attempting to register recipe {1}", NAMESPACE == null ? "" : NAMESPACE, thisRecipe.Name); if (this.limitType != null) { if (isOptional) { Pipliz.Log.Write("{0}: Attempting to register optional limit type recipe {1}", NAMESPACE == null ? "" : NAMESPACE, thisRecipe.Name); RecipeStorage.AddOptionalLimitTypeRecipe(limitType, thisRecipe); } else { Pipliz.Log.Write("{0}: Attempting to register default limit type recipe {1}", NAMESPACE == null ? "" : NAMESPACE, thisRecipe.Name); RecipeStorage.AddDefaultLimitTypeRecipe(limitType, thisRecipe); } } if (userCraftable) { Recipe playerRecipe = new Recipe("player." + this.Name, this.realRequirements, this.realResults, this.defaultLimit, this.isOptional); Pipliz.Log.Write("{0}: Attempting to register default player type recipe {1}", NAMESPACE == null ? "" : NAMESPACE, playerRecipe.Name); RecipePlayer.AddDefaultRecipe(playerRecipe); } } catch (Exception ex) { Pipliz.Log.WriteError("{0}: Error adding recipe: {1}", NAMESPACE == null ? "" : NAMESPACE, ex.Message); } } else { Pipliz.Log.Write("{0}: Recipe {1} has been disabled and will NOT be registered.", NAMESPACE == null ? "" : NAMESPACE, this.Name); } }
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)); } } }
public static void LoadRecipes() { RecipePlayer.AddDefaultRecipe(new Recipe(JOB_ITEM_KEY + ".recipe", new InventoryItem(BuiltinBlocks.Planks, 1), new InventoryItem(JOB_ITEM_KEY, 1), 0)); }