tModLoader Modding Help, need code.

Tavras

Terrarian
I'm trying to make a mod that adds just one helmet to the game (Felwinter's helm from Destiny 2) , but I don't know a thing about coding and all example code I've found hasn't worked. I've got the sprite done, just need code to add it in.
 
If you want just the helmet, here is the code. Make sure that your helmet sprite, spritesheet, and .cs file are in a folder named Armor, inside of a folder named Items.
C#:
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;

namespace YourModName.Items.Armor  //Replace YourModName with your mod's name
{
    [AutoloadEquip(EquipType.Head)]
    public class ExampleHelmet : ModItem  //Replace ExampleHelmet with your helmet's name
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Example Helmet"); //Item Display Name
            Tooltip.SetDefault("Put tooltip here"); //Item tooltip
        }

        public override void SetDefaults()
        {
            item.width = 22;      //Make this match to the width of the helmet sprite
            item.height = 20;  //Same as above
            item.value = 500; //The item's value, 1 = 1 copper
            item.rare = 5;      //The item's text color/rarity, you can check these on the wiki
            item.defense = 25;  //The Item's defense
        }
        
        public override void AddRecipes()  //Adds a recipe for the item. You can remove this line and everything in the brackets below it if you don't want a recipe.
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.Wood, 25);  //The ingredient and number of ingredients. You can repeat this line to add more ingredients.
            recipe.AddTile(TileID.MythrilAnvil); // The table/tile that you craft the item at.
            recipe.SetResult(this);  //If you want more than 1 of this item when crafted then you can add a comma and a number after "this"
            recipe.AddRecipe();
        }
    }
}
Also make sure your spritesheet is named ExampleHelmet_Head . You can change the name, but leave the _Head part.
 
I tried that but got this when building
1590535977011.png


edit: got it working
 
Last edited:
If you want just the helmet, here is the code. Make sure that your helmet sprite, spritesheet, and .cs file are in a folder named Armor, inside of a folder named Items.
C#:
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;

namespace YourModName.Items.Armor  //Replace YourModName with your mod's name
{
    [AutoloadEquip(EquipType.Head)]
    public class ExampleHelmet : ModItem  //Replace ExampleHelmet with your helmet's name
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Example Helmet"); //Item Display Name
            Tooltip.SetDefault("Put tooltip here"); //Item tooltip
        }

        public override void SetDefaults()
        {
            item.width = 22;      //Make this match to the width of the helmet sprite
            item.height = 20;  //Same as above
            item.value = 500; //The item's value, 1 = 1 copper
            item.rare = 5;      //The item's text color/rarity, you can check these on the wiki
            item.defense = 25;  //The Item's defense
        }
       
        public override void AddRecipes()  //Adds a recipe for the item. You can remove this line and everything in the brackets below it if you don't want a recipe.
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.Wood, 25);  //The ingredient and number of ingredients. You can repeat this line to add more ingredients.
            recipe.AddTile(TileID.MythrilAnvil); // The table/tile that you craft the item at.
            recipe.SetResult(this);  //If you want more than 1 of this item when crafted then you can add a comma and a number after "this"
            recipe.AddRecipe();
        }
    }
}
Also make sure your spritesheet is named ExampleHelmet_Head . You can change the name, but leave the _Head part.
My microsoft visual studio 2022 doesnt recognize "item" "ModRecipe" or "(mod)" as existing in the current context
 
Back
Top Bottom