public void LoadRecipe(AssetLocation loc, GridRecipe recipe) { if (!recipe.Enabled) { return; } if (recipe.Name == null) { recipe.Name = loc; } Dictionary <string, string[]> nameToCodeMapping = recipe.GetNameToCodeMapping(api.World); if (nameToCodeMapping.Count > 0) { List <GridRecipe> subRecipes = new List <GridRecipe>(); int qCombs = 0; bool first = true; foreach (var val2 in nameToCodeMapping) { if (first) { qCombs = val2.Value.Length; } else { qCombs *= val2.Value.Length; } first = false; } first = true; foreach (var val2 in nameToCodeMapping) { string variantCode = val2.Key; string[] variants = val2.Value; for (int i = 0; i < qCombs; i++) { GridRecipe rec; if (first) { subRecipes.Add(rec = recipe.Clone()); } else { rec = subRecipes[i]; } foreach (CraftingRecipeIngredient ingred in rec.Ingredients.Values) { if (ingred.Name == variantCode) { ingred.Code.Path = ingred.Code.Path.Replace("*", variants[i % variants.Length]); } } rec.Output.FillPlaceHolder(variantCode, variants[i % variants.Length]); } first = false; } foreach (GridRecipe subRecipe in subRecipes) { if (!subRecipe.ResolveIngredients(api.World)) { continue; } api.RegisterCraftingRecipe(subRecipe); } } else { if (!recipe.ResolveIngredients(api.World)) { return; } api.RegisterCraftingRecipe(recipe); } }
private void LoadGridRecipes() { Dictionary <AssetLocation, GridRecipe> recipes = api.Assets.GetMany <GridRecipe>(api.Server.Logger, "recipes/grid"); foreach (var val in recipes) { GridRecipe recipe = val.Value; if (!recipe.Enabled) { continue; } if (recipe.Name == null) { recipe.Name = val.Key; } Dictionary <string, string[]> nameToCodeMapping = recipe.GetNameToCodeMapping(api.World); if (nameToCodeMapping.Count > 0) { List <GridRecipe> subRecipes = new List <GridRecipe>(); int qCombs = 0; bool first = true; foreach (var val2 in nameToCodeMapping) { if (first) { qCombs = val2.Value.Length; } else { qCombs *= val2.Value.Length; } first = false; } first = true; foreach (var val2 in nameToCodeMapping) { string variantCode = val2.Key; string[] variants = val2.Value; for (int i = 0; i < qCombs; i++) { GridRecipe rec; if (first) { subRecipes.Add(rec = recipe.Clone()); } else { rec = subRecipes[i]; } foreach (CraftingRecipeIngredient ingred in rec.Ingredients.Values) { if (ingred.Name == variantCode) { ingred.Code.Path = ingred.Code.Path.Replace("*", variants[i % variants.Length]); } } rec.Output.FillPlaceHolder(variantCode, variants[i % variants.Length]); } first = false; } foreach (GridRecipe subRecipe in subRecipes) { if (!subRecipe.ResolveIngredients(api.World)) { continue; } api.RegisterCraftingRecipe(subRecipe); } } else { if (!recipe.ResolveIngredients(api.World)) { continue; } api.RegisterCraftingRecipe(recipe); } } api.World.Logger.Event("{0} crafting recipes loaded", recipes.Count); }