tModLoader Tutorial: [2] Recipes

How do i use an item (MeowZium) from my mod to craft another item from my mod? when i type MeowZium into the ingredient spot on the sword im trying to craft, it says ItemID.Meowzium not found
 
How do i use an item (MeowZium) from my mod to craft another item from my mod? when i type MeowZium into the ingredient spot on the sword im trying to craft, it says ItemID.Meowzium not found
the ItemID space only holds vanilla items, for your own items you can use either mod.ItemType<MeowZium>() or mod.ItemType("MeowZium")
it takes the class name as argument.
 
the ItemID space only holds vanilla items, for your own items you can use either mod.ItemType<MeowZium>() or mod.ItemType("MeowZium")
it takes the class name as argument.

i ended up going into the weapon MeowZium and just making the recipe there and instead of ItemID i used null and it worked so yeah thanks anyway ill probly come across another error soon and ask for more help haha
 
As a note to anyone who subscribed to this thread, tML now also has mod calls using constraints. This means you can do
Code:
mod.GetItem<MyItemClass>()
instead of
Code:
mod.GetItem("MyItemClass")
, which is preferred, as IDEs will usually automatically change pointers if the class is changed.
 
So I have been trying to add a moditem to a recipe (recipe.AddIngredient(mod.GetItem("StartingSword"));), but when I go in game after having build the mod I can't make the item as if the recipe doesn't even exist.

Also how do I add more ingredients to a recipe? does this work:
recipe.AddIngredient(mod.GetItem("StartingSword"));
recipe.AddIngredient(ItemID.DirtBlock);
Just adding a new recipe.AddIngredient() after the one before?

And how can I do so that the item doesn't require any workstation to be made?
 
So I have been trying to add a moditem to a recipe (recipe.AddIngredient(mod.GetItem("StartingSword"));), but when I go in game after having build the mod I can't make the item as if the recipe doesn't even exist.
When you want to add a ModItem as ingredient, you first have to specify which mod it is from. If it is your own mod, you can usually pass the embedded 'mod' variable, otherwise you can simply pass 'null'. Also, you are using the 'GetItem' call which will return the object as an Item type. It's better to use the .ItemType call, although both should be supported recipe.AddIngredient(mod.GetItem("StartingSword")); will become:
Code:
recipe.AddIngredient(null, mod.ItemType("StartingSword"));
or
Code:
recipe.AddIngredient(mod, mod.ItemType("StartingSword"));
Also I recommend you use the generic constraint version of 'Get' calls, aka your call becomes:
Code:
recipe.AddIngredient(null, mod.ItemType<StartingSword>());
or
Code:
recipe.AddIngredient(mod, mod.ItemType<StartingSword>());
There is no real difference, but they're considered cleaner.

Also how do I add more ingredients to a recipe? does this work:
recipe.AddIngredient(mod.GetItem("StartingSword"));
recipe.AddIngredient(ItemID.DirtBlock);
Just adding a new recipe.AddIngredient() after the one before?
Yes, this is how you add multiple ingredients.

And how can I do so that the item doesn't require any workstation to be made?
Simply do not call recipe.AddTile, then no tile will be required for crafting the recipe.
 
When you want to add a ModItem as ingredient, you first have to specify which mod it is from. If it is your own mod, you can usually pass the embedded 'mod' variable, otherwise you can simply pass 'null'. Also, you are using the 'GetItem' call which will return the object as an Item type. It's better to use the .ItemType call, although both should be supported recipe.AddIngredient(mod.GetItem("StartingSword")); will become:
Code:
recipe.AddIngredient(null, mod.ItemType("StartingSword"));
or
Code:
recipe.AddIngredient(mod, mod.ItemType("StartingSword"));
Also I recommend you use the generic constraint version of 'Get' calls, aka your call becomes:
Code:
recipe.AddIngredient(null, mod.ItemType<StartingSword>());
or
Code:
recipe.AddIngredient(mod, mod.ItemType<StartingSword>());
There is no real difference, but they're considered cleaner.


Yes, this is how you add multiple ingredients.


Simply do not call recipe.AddTile, then no tile will be required for crafting the recipe.
If I understand correctly this code:
Code:
recipe.AddIngredient(mod, mod.ItemType<StartingSword>());
could be this:
Code:
recipe.AddIngredient(TestMod, mod.ItemType<StartingSword>());
If the mod name, assemblyname (in the csproj file) and root folder name was "TestMod"?
Just so I know how I can use other mods items if I get that far.

Thanks for the help :D
 
I got this error:
c:\Users\Gyderian\Documents\My Games\Terraria\ModLoader\Mod Sources\MyFirstMod\Items\ScasiumBar.cs(30,1) : error CS1022: Type or namespace definition, or end-of-file expected

And I don't know what to do.

Here's my code, if it helps:
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace MyFirstMod.Items
{
public class ScasiumBar : ModItem
{
public override void SetDefaults()
{
item.name = "Scasium Bar";
item.damage = 0;
item.melee = true;
item.width = 30;
item.height = 24;
item.toolTip = "A strong alloy naturally formed within Zuswio.";
item.useTime = 1;
item.useAnimation = 1;
item.useStyle = 1;
item.knockBack = 0;
item.value = 10000;
item.rare = 7;
item.UseSound = SoundID.Item1;
item.autoReuse = true;
}

}
}
}

Wat do?

Edit: Never mind, I fixed it.
 
Last edited:
Well now there's this error:
c:\Users\Gyderian\Documents\My Games\Terraria\ModLoader\Mod Sources\MyFirstMod\Items\TheBeeHorde.cs(32,4) : error CS1502: The best overloaded method match for 'Terraria.ModLoader.ModRecipe.AddIngredient(Terraria.ModLoader.Mod, string, int)' has some invalid arguments

c:\Users\Gyderian\Documents\My Games\Terraria\ModLoader\Mod Sources\MyFirstMod\Items\TheBeeHorde.cs(32,25) : error CS1503: Argument 1: cannot convert from 'MyFirstMod.Items.TheBeeHorde' to 'Terraria.ModLoader.Mod'

And here's my code:
Code:
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace MyFirstMod.Items
{
    public class TheBeeHorde : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "The Bee Horde";
            item.damage = 90;
            item.melee = true;
            item.width = 40;
            item.height = 40;
            item.toolTip = "Release the horde!";
            item.useTime = 21;
            item.useAnimation = 21;
            item.useStyle = 1;
            item.knockBack = 6;
            item.value = 10000;
            item.rare = 8;
            item.UseSound = SoundID.Item1;
            item.autoReuse = true;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.BeeKeeper);
            recipe.AddIngredient(this, "Scasium Bar", 15);
            recipe.AddTile(TileID.Anvils);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}

What is going wrong?
 
I've got problems man... here's my code, but the recipe doesn't work on my worlds

usingg Terraria.ID;
using Terraria.ModLoader;

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(this);
recipe.AddIngredient(ItemID.DirtBlock, 10);
recipe.AddTile(TileID.WorkBenches);
recipe.SetResult(ItemID.Diamond);
recipe.AddRecipe();
}



I also made a folder to put my recipes in called Recipes, so that might be it but just in case...
 
I've got problems man... here's my code, but the recipe doesn't work on my worlds

usingg Terraria.ID;
using Terraria.ModLoader;

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(this);
recipe.AddIngredient(ItemID.DirtBlock, 10);
recipe.AddTile(TileID.WorkBenches);
recipe.SetResult(ItemID.Diamond);
recipe.AddRecipe();
}



I also made a folder to put my recipes in called Recipes, so that might be it but just in case...
Your method is not in any class. It should be in your mod class.
 
I get this error message upon starting up the game:

Items/AdminArk
at Terraria.ModLoader.Mod.GetTexture(String name)
at Terraria.ModLoader.ModLoader.GetTexture(String name)
at Terraria.ModLoader.Mod.SetupContent()
at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)
 
ok, say in theory, if i copied all of your final code, what would I have to change if my mod name was OddModd, and what would I just have to change in general. Please answer at your earliest convienience
 
Back
Top Bottom