ModItem Class

Base class for creating custom items, weapons, tools, and accessories.

Overview

The ModItem class is used to define custom items in tModLoader. By extending this class, you can create weapons, accessories, consumables, and any other item type. See practical examples in our Creating Items tutorial.

Namespace

Terraria.ModLoader

Common Methods

SetDefaults()

Set item properties like damage, size, use time, etc.

public override void SetDefaults()
{
    Item.damage = 50;
    Item.width = 40;
    Item.height = 40;
    Item.useTime = 20;
}

AddRecipes()

Define crafting recipes for your item.

public override void AddRecipes()
{
    Recipe recipe = CreateRecipe();
    recipe.AddIngredient(ItemID.Wood, 10);
    recipe.AddTile(TileID.WorkBenches);
    recipe.Register();
}

Advanced Item Examples

Creating a Ranged Weapon

public class ExampleBow : ModItem
{
    public override void SetDefaults()
    {
        Item.damage = 30;
        Item.DamageType = DamageClass.Ranged;
        Item.width = 16;
        Item.height = 32;
        Item.useTime = 25;
        Item.useAnimation = 25;
        Item.useStyle = ItemUseStyleID.Shoot;
        Item.noMelee = true; // Don't deal melee damage
        Item.knockBack = 2;
        Item.value = Item.sellPrice(silver: 30);
        Item.rare = ItemRarityID.Green;
        Item.UseSound = SoundID.Item5;
        Item.autoReuse = true;
        Item.shoot = ProjectileID.WoodenArrowFriendly;
        Item.shootSpeed = 10f;
        Item.useAmmo = AmmoID.Arrow; // Uses arrows as ammo
    }
}

Creating a Consumable Item

public class ExamplePotion : ModItem
{
    public override void SetDefaults()
    {
        Item.width = 20;
        Item.height = 26;
        Item.useStyle = ItemUseStyleID.DrinkLiquid;
        Item.useAnimation = 15;
        Item.useTime = 15;
        Item.useTurn = true;
        Item.UseSound = SoundID.Item3;
        Item.maxStack = 30;
        Item.consumable = true; // Item is consumed on use
        Item.rare = ItemRarityID.Orange;
        Item.value = Item.buyPrice(gold: 1);
        Item.buffType = BuffID.Ironskin; // Grants buff
        Item.buffTime = 5 * 60 * 60; // 5 minutes
    }
}

Creating an Accessory

public class ExampleAccessory : ModItem
{
    public override void SetDefaults()
    {
        Item.width = 24;
        Item.height = 24;
        Item.value = Item.sellPrice(gold: 1);
        Item.rare = ItemRarityID.Orange;
        Item.accessory = true; // Mark as accessory
    }

    public override void UpdateAccessory(Player player, bool hideVisual)
    {
        player.moveSpeed += 0.15f; // +15% movement speed
        player.jumpSpeedBoost += 1.5f; // Better jumps
        player.GetDamage(DamageClass.Generic) += 0.08f; // +8% all damage
    }
}

Complete Properties Reference

Property Type Description Example
damage int Base damage value 50
useTime int Frames between uses 20
knockBack float Knockback strength 6.5f
autoReuse bool Auto-swing when held true
maxStack int Max stack size 999
consumable bool Used on consumption true

External Resources