Tutorial: Sending a Recipe Letter (Content Patcher)

From The Stardew Modding Wiki
Jump to navigation Jump to search

During this tutorial, I will assume you have already read:

And therefore have some basic familiarity with the mail formatting.

How to Send Recipes via Content Patcher[edit | edit source | hide | hide all]

You can have the game send recipes from custom NPCs, just by doing two steps:

  • Formatting your mail the same way as the vanilla cooking recipe
  • Editing the Data/CookingRecipes entry to have the right friendship conditions

For the mail, the id should be [CustomNPCName]Cooking and include %item cookingRecipe %%. Note that the letter id must be [CustomNPCName]Cooking and cannot be anything else. For example, if your NPC is named Blobin (no relation to Robin), your mail would be named BlobinCooking. When I say NPC name here, I mean the internal ID, and not the display name (per usual).

Here's an example letter (with i18n formatting for the letter content and letter title):

{
    "LogName": "Blobin Recipe Mail",
    "Action": "EditData",
    "Target": "Data/Mail",
    "Entries": {
        "BlobinCooking": "{{i18n:Mail.Blobin_DeliciousRecipe}}%item cookingRecipe %%[#]{{i18n:Blobin_DeliciousRecipe}}"
    }
},

Here's an example of editing the entry in Data/CookingRecipes (Blobin's Delicious Food may or may not be equivalent to two fried eggs):

{
    "LogName": "Blobin Recipe Edits"
    "Action": "EditData",
    "Target": "Data/CookingRecipes",
    "Entries": {
        "Blobin's Delicious Food": "-5 1/10 10/{{spacechase0.jsonAssets/ObjectId:Blobin's Delicious Food}} 2/f Blobin 7",
    },
    "When": {
        "HasMod |contains=spacechase0.jsonAssets": true
    }
}

Sending Multiple Cooking Recipes[edit | edit source | hide]

Say you have one recipe with f Blobin 3 and one with f Blobin 7, it will pick the 3 heart one first, and then next time, it will pick the 7 heart one. You can try using Content Patcher conditions to swap the letter content between these two conditions, or just write the letter to be generic enough to cover both.

Why This Works[edit | edit source | hide]

Per vert:

It's a pretty complicated chunk of code that happens in LetterViewerMenu's constructor. If you look at the data in CookingRecipes.json, you'll see that many recipes have requirements listed there. For example:

{
  "Salad": "20 1 22 1 419 1/25 5/196/f Emily 3",
}
The last section, f Emily 3, means you need to have 3 friendship hearts with Emily before you can receive that recipe in the mail. So when the game parses cookingRecipe in a letter, it checks those conditions, matches up the letter to the character, gets the lowest heart-level recipe that you meet the requirements for, and gives it to you.