tModLoader wiki
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    *** This Guide has been updated to 1.4. If you need to view the old 1.3 version of this wiki page, click [here](https://github.com/tModLoader/tModLoader/wiki/Basic-Recipes/f1a9c7a29f517a696631670bf58f75e7a7e4ccb9) *** # Basic Recipe Recipes can be added to the game in 3 places. In `Mod.AddRecipes`, `ModItem.AddRecipes`, and `ModSystem.AddRecipes`. Where you add your recipes is up to your organizational preferences, but do note that the `CreateRecipe` method used in code below has different behavior depending on where you use it. Recipes consist of Ingredients (Items consumed to craft the result), Tiles (Tiles you need to stand by), and Results (Item created). # Basic Recipe Structure ## Required Using Statements First, make sure that you have the following using statements in the .cs file. These using statements will let us access recipe related functions: ```cs using Terraria; using Terraria.ID; using Terraria.ModLoader; ``` ## Create Recipe and Assign Recipe Result To start a recipe we create an instance of the `Recipe` class. We do this through the `Mod.CreateRecipe` method or the `ModItem.CreateRecipe` method. When creating a recipe, we need to assign the recipe result type and result stack. The `ModItem.CreateRecipe` method assumes that the recipe results in the current ModItem, so only the stack size is needed. The stack size is optional and defaults to 1: ```cs // In Mod class, we type "CreateRecipe" to use the Mod.CreateRecipe method. Here are various examples, showing vanilla and modded ingredients as well as default stack sizes and custom stack sizes. Recipe recipe = CreateRecipe(ItemID.AlphabetStatueZ); Recipe recipe = CreateRecipe(ItemID.AlphabetStatueZ, 5); Recipe recipe = CreateRecipe(ModContent.ItemType<Content.Items.ExampleItem>()); Recipe recipe = CreateRecipe(ModContent.ItemType<Content.Items.ExampleItem>(), 10); // In ModSystem class, we need to use "Mod.CreateRecipe": Recipe recipe = Mod.CreateRecipe(ItemID.AlphabetStatueZ); // In ModItem class, we can use "Mod.CreateRecipe" to create a recipe that doesn't have this ModItem as a result: Recipe recipe = Mod.CreateRecipe(ItemID.AlphabetStatueZ); // ... And we can use "CreateRecipe" directly to create a recipe that results in this ModItem. We can optionally provide a stack size: Recipe recipe = CreateRecipe(); Recipe recipe = CreateRecipe(10); ``` ## Add Recipe Ingredients Now, we add the ingredients. These are the items we want the recipe to be consumed when the recipe is crafted: ```cs recipe.AddIngredient(ItemID.DirtBlock); recipe.AddIngredient(ItemID.Ruby); ``` AddIngredient also takes an optional argument for specifying a stack size: ```cs recipe.AddIngredient(ItemID.Chain, 10); ``` The previous examples added vanilla items to the recipe by referencing the ItemID class. With a capable IDE such as Visual Studio, you will find autocomplete and intellisense very useful, but you can also [look up ItemID names or values here](https://github.com/tModLoader/tModLoader/wiki/Vanilla-Item-IDs). We can also add modded items added by this mod. There are several ways we can do this. Go for whatever approach you like. The 1st approach is the cleanest. All of these methods can add the stack parameter. These examples all point to the `ExampleItem` class in the `ExampleMod.Content.Items` namespace: ```cs recipe.AddIngredient<Content.Items.ExampleItem>(); recipe.AddIngredient<Content.Items.ExampleItem>(10); recipe.AddIngredient(ModContent.ItemType<Content.Items.ExampleItem>()); recipe.AddIngredient(ModContent.GetInstance<Content.Items.ExampleItem>()); recipe.AddIngredient(Mod, "ExampleItem"); ``` Next, we can specify the crafting stations. This follows the same patterns as items. You can [look up TileIDs here](https://github.com/tModLoader/tModLoader/wiki/Vanilla-Tile-IDs). ```cs recipe.AddTile(TileID.WorkBenches); recipe.AddTile(TileID.Anvils); recipe.AddTile<Content.Tiles.Furniture.ExampleWorkbench>(); recipe.AddTile(ModContent.TileType<Content.Tiles.Furniture.ExampleWorkbench>()); recipe.AddTile(ModContent.GetInstance<Content.Tiles.Furniture.ExampleWorkbench>()); recipe.AddTile(Mod, "ExampleWorkbench"); ``` Finally, we need to tell tModLoader that our Recipe is complete and add it to the game: ```cs recipe.Register(); ``` ### Using Vanilla vs Modded Ingredients and Tiles As a recap, vanilla items and tiles use the `TileID` and `ItemID` classes, while modded items and items use the `ModContent.TileType` and `ModContent.ItemType` methods: ```cs recipe.AddTile(TileID.WorkBenches); // Vanilla Tile recipe.AddTile(ModContent.TileType<Content.Tiles.Furniture.ExampleWorkbench>()); // Modded Tile recipe.AddIngredient(ItemID.Meowmere); // Vanilla Item recipe.AddIngredient(ModContent.ItemType<Content.Items.ExampleItem>()); // Modded Item ``` ## Full Basic Recipe Example Here are a few full basic recipe example. This first example resides in a ModSystem class. The recipe takes 1 Chain and 10 Stone Blocks, it is crafted at a workbench and anvil, and the resulting item is 1 AlphabetStatueA. ```cs Recipe recipe = Mod.CreateRecipe(ItemID.AlphabetStatueA); recipe.AddIngredient(ItemID.StoneBlock, 10); recipe.AddIngredient(ItemID.Chain); recipe.AddTile(TileID.WorkBenches); recipe.AddTile(TileID.Anvils); recipe.Register(); ``` This example is in a `ModItem` class. This recipe crafts 3 of the ModItem from 5 `ExampleItem`s: ```cs Recipe recipe = CreateRecipe(3); recipe.AddIngredient<Content.Items.ExampleItem>(5); recipe.Register(); ``` # Chain Syntax The code in this guide is quite wordy. Using the chaining syntax, we can reduce the verbosity of our code. This approach may be more pleasing to the modder. Only the final line has a semi-colon. ```cs Mod.CreateRecipe(ItemID.AlphabetStatueA) .AddIngredient(ItemID.StoneBlock, 10) .AddIngredient(ItemID.Chain) .AddTile(TileID.WorkBenches) .AddTile(TileID.Anvils) .Register(); ``` # Recipe Groups Recipe Groups allow a single ingredient to be satisfied from a selection of similar items. The most common example of this is using Iron Bar or Lead Bar to craft a recipe. Recipe Groups are discussed in [Intermediate Recipes](https://github.com/tModLoader/tModLoader/wiki/Intermediate-Recipes#recipegroups) # Conditions In addition to ingredients and crafting stations, recipes can also have conditions. Each condition must be satisfied for the recipe to be able to be crafted. ## Water, Honey, Lava Water, Honey, and Lava are not technically Tiles, so to make a recipe require standing next to those, use one of the following: ```cs recipe.AddCondition(Recipe.Condition.NearWater); recipe.AddCondition(Recipe.Condition.NearLava); recipe.AddCondition(Recipe.Condition.NearHoney); ``` Note that `NearWater` is also satisfied by Sinks, so don't add the Sink tile separately. Also note that there is a needSnowBiome you can also set, but anything more advanced would utilize ModRecipe.RecipeAvailable. ## Custom Condition Intermediate? ### RecipeAvailable Intermediate? ## Multiple Recipes With multiple Recipes in the same AddRecipes, make sure not to re-declare your variable name. The following will cause errors: ```cs Recipe recipe = Mod.CreateRecipe(ItemID.AlphabetStatueA); // other code Recipe recipe = Mod.CreateRecipe(ItemID.AlphabetStatueB); // other code ``` You can name your variables recipe1, recipe2, and so on, but a cleaner approach would be to just reuse the same variable: ```cs Recipe recipe = Mod.CreateRecipe(ItemID.AlphabetStatueA); // other code recipe = Mod.CreateRecipe(ItemID.AlphabetStatueB); // other code ``` ## Making an "upgraded" vanilla tile As an aside, you may want your ModTile to count as, say, a workbench or anvil. To do this, add the following to your `ModTile.SetStaticDefaults`: ```cs AdjTiles = new int[]{ TileID.WorkBenches }; ``` ## Complete Examples Here are 2 complete examples, one showing recipes added in a `ModItem` class more suitable for recipes involving that `ModItem`, and the other showing adding recipes in a `Mod` class more suitable for recipes involving vanilla items. Technically the recipes can go in either location, but for organization purposes it is sometimes nice to have recipes in ModItem classes. ### ModItem Example ```cs using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace ExampleMod.Items.Abomination { public class FoulOrb : ModItem { public override void SetDefaults() { // other code } public override void AddRecipes() { Recipe recipe = CreateRecipe(); recipe.AddIngredient(ItemID.BeetleHusk); recipe.AddIngredient(ItemID.Ectoplasm, 5); recipe.AddTile(TileID.MythrilAnvil); recipe.Register(); recipe = CreateRecipe(20); recipe.AddIngredient<Content.Items.ExampleItem>(10); recipe.AddTile<Content.Tiles.Furniture.ExampleWorkbench>(); recipe.AddCondition(Recipe.Condition.NearLava) recipe.Register(); } } } ``` ### Mod Example Remember that in `Mod` or `ModSystem`, we must pass in the receipe result item type. ```cs using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace ExampleMod { public class ExampleMod : Mod { // Other methods and fields here... public override void AddRecipes() { // Here is an example of a recipe. Recipe recipe = CreateRecipe(ItemID.Wood, 999); recipe.AddIngredient<Content.Items.ExampleItem>(); recipe.Register(); // Here we reuse 'recipe', meaning we don't need to re-declare that it is a ModRecipe recipe = CreateRecipe(ItemID.PumpkinPie, 2); recipe.AddIngredient(ItemID.BlueBerries, 20); recipe.AddTile(TileID.WorkBenches); recipe.Register(); } } } ``` ## Common Errors ### Error CS0117 'ItemID' (or TileID) does not contain a definition for 'MyModItem' You tried to use the vanilla item syntax for adding a ModItem, read this tutorial again. ### Error CS0103 The name 'recipe' does not exist in the current context You forgot to declare your first recipe as `Recipe`. Make sure the first recipe in your code starts with `Recipe recipe = ...` ### Error CS0128 A local variable named 'recipe' is already defined in this scope Read `Multiple Recipes` above. ### My recipes aren't in game Check that your AddRecipes method has override not virtual. ### No suitable method to override Make sure you are only overriding AddRecipes in Mod, ModSystem, or ModItem. ## Relevant References * [Vanilla ItemIDs](https://github.com/tModLoader/tModLoader/wiki/Vanilla-Item-IDs) * [Vanilla TileIDs](https://github.com/tModLoader/tModLoader/wiki/Vanilla-Tile-IDs) * [ModRecipe Documentation](http://tmodloader.github.io/tModLoader/html/class_terraria_1_1_mod_loader_1_1_mod_recipe.html) * [Mod Documentation](http://tmodloader.github.io/tModLoader/html/class_terraria_1_1_mod_loader_1_1_mod.html) ## Not covered in Basic level There are other aspects of Recipes that will be covered in more advanced guides: * [RecipeGroups](https://github.com/tModLoader/tModLoader/wiki/Intermediate-Recipes#recipegroups) -- Intermediate -- Allows a single ingredient to be 1 of a large group, like how most recipes involving wood can take Boreal Wood or Pearl Wood. ("any wood") * Editing Recipes * Deleteing Recipes * Ordering Recipes * OnCraftCallback * ConsumeItemCallback * RecipeAvailable * [RecipeFinder/RecipeEditor](https://github.com/tModLoader/tModLoader/wiki/Intermediate-Recipes#editing-vanilla-recipes) -- Intermediate -- Allows you to modify and delete vanilla recipes. * [Cross-Mod Content](https://github.com/tModLoader/tModLoader/wiki/Intermediate-Recipes#cross-mod-recipes) -- Intermediate -- Use Items or Tiles from other mods in your Recipe.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully