Jump to content

[Question] - New Recipe Problem


Recommended Posts

Hello again everyone. I've been working on modding this game recently, and I have stumbled on my first problem. I'm really new on programming on C# using Visual Studio, although I know JavaScript and some extent of Ruby. I recently tried a new recipe for the Kiln, which worked successfully, except for two lines problem. First look at the code, which is posted down here. The problem CS0117, which it says that both entries has no definition. I researched high and low about this issue, and I could fix it myself. I know this may be really silly, but bear with someone who is still learning.

 

using Harmony;
using System.Collections.Generic;

namespace SulfurSandstone
{
    [HarmonyPatch(typeof(KilnConfig), "ConfigureBuildingTemplate")]
    public static class Sulfur_Recipe
    {
        public static void Postfix()
        {
            Tag tag1 = SimHashes.SandStone.CreateTag();
            Tag tag2 = SimHashes.Carbon.CreateTag();
            Tag tag3 = SimHashes.Sulfur.CreateTag();
            string stag1 = ElementLoader.FindElementByHash(SimHashes.Sulfur).name;
            string stag2 = ElementLoader.FindElementByHash(SimHashes.SandStone).name;
            ComplexRecipe.RecipeElement[] ingredients = new ComplexRecipe.RecipeElement[]
            {
new ComplexRecipe.RecipeElement(tag1, 1000f), //Sandstone used : 1000kg
new ComplexRecipe.RecipeElement(tag2, 500f)   //Coal used: 500kg
            };
            ComplexRecipe.RecipeElement[] results = new ComplexRecipe.RecipeElement[]
            {
new ComplexRecipe.RecipeElement(tag3, 200f) //Sulfur created: 200kg
            };

            string str = ComplexRecipeManager.MakeRecipeID("Kiln", ingredients, results);
            new ComplexRecipe(str, ingredients, results)
            {
                time = 500f,
                useResultAsDescription = true, // <----- ERROR  CS0117: ComplexRecipe has no definiton for useResultAsDescription
                displayInputAndOutput = true, // <------ ERROR  CS0117: ComplexRecipe has no definiton for displayInputAndOutput
                description = string.Format($"Make {stag1} from {stag2}", stag1)
            }.fabricators = new List<Tag>() { TagManager.Create("Kiln") };
        }
    }
}

I should mention that the Visual Studio does compile if I comment those two lines, however, in the Kiln it shows the ingredient icon and not the final product (which are the instructions provided by the lines).

Link to comment
Share on other sites

If you check the class ComplexRecipe, neither useResultAsDescription nor displayInputAndOutput are variables of it. So there is no way to set them.

In fact I didn't even find any occurrence in Assembly-CSharp at all... Where did you even get these names from?

I think what you are looking for is the RecipeNameDisplay enum

  public enum RecipeNameDisplay
  {
    Ingredient,
    Result,
    IngredientToResult,
    ResultWithIngredient,
  }

So try this line instead:

nameDisplay = ComplexRecipe.RecipeNameDisplay.IngredientToResult

Link to comment
Share on other sites

13 hours ago, Candide said:

If you check the class ComplexRecipe, neither useResultAsDescription nor displayInputAndOutput are variables of it. So there is no way to set them.......

You have my thanks sir, it worked like a charm. The Kiln was just a test, I was looking in to the Glass Forge so it could smelt metals from ore. Bellow follows a sample to produce molten steel from iron (with your code tip included : ) ):

//=== GLASS FORGE : MOLTEM STEEL

namespace MoltenSteelIron
{
    [HarmonyPatch(typeof(GlassForgeConfig), "ConfigureBuildingTemplate")]
    public static class MoltenSteelIron_Recipe
    {
        public static void Postfix()
        {
            Tag tag1 = SimHashes.Iron.CreateTag();
            Tag tag2 = SimHashes.RefinedCarbon.CreateTag();
            Tag tag3 = SimHashes.Lime.CreateTag();
            Tag tag4 = SimHashes.MoltenSteel.CreateTag();
            string stag1 = ElementLoader.FindElementByHash(SimHashes.MoltenSteel).name;
            string stag2 = ElementLoader.FindElementByHash(SimHashes.Iron).name;
            ComplexRecipe.RecipeElement[] ingredients = new ComplexRecipe.RecipeElement[]
            {
new ComplexRecipe.RecipeElement(tag1, 800f), //Iron used
new ComplexRecipe.RecipeElement(tag2, 200f), //Refined Carbon used
new ComplexRecipe.RecipeElement(tag3, 200f) //Lime used
            };
            ComplexRecipe.RecipeElement[] results = new ComplexRecipe.RecipeElement[]
            {
new ComplexRecipe.RecipeElement(tag4, 500f) //Steel produced
            };
            string str = ComplexRecipeManager.MakeRecipeID("GlassForge", ingredients, results);
            new ComplexRecipe(str, ingredients, results)
            {
                time = 60f,
                nameDisplay = ComplexRecipe.RecipeNameDisplay.IngredientToResult,
                description = string.Format($"Smelt pure {stag1} from {stag2}", stag1)
            }.fabricators = new List<Tag>() { TagManager.Create("GlassForge") };
        }
    }
}

Thanks again for the help. I'll leave the sample so it may help anyone trying the same thing.

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...