Creating Items
Learn how to create custom items, weapons, and accessories using the ModItem API. Make sure you've completed the development setup first.
Basic Item Example
Here's a simple example of creating a custom sword:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace YourModName.Items
{
public class ExampleSword : ModItem
{
public override void SetDefaults()
{
Item.damage = 50;
Item.DamageType = DamageClass.Melee;
Item.width = 40;
Item.height = 40;
Item.useTime = 20;
Item.useAnimation = 20;
Item.useStyle = ItemUseStyleID.Swing;
Item.knockBack = 6;
Item.value = 10000;
Item.rare = ItemRarityID.Blue;
}
public override void AddRecipes()
{
Recipe recipe = CreateRecipe();
recipe.AddIngredient(ItemID.DirtBlock, 10);
recipe.AddTile(TileID.WorkBenches);
recipe.Register();
}
}
}
Item Properties Explained
Complete reference for all common item properties:
damage
Base damage value before modifiers
Item.damage = 50;
DamageType
Melee, Ranged, Magic, Summon, Throwing
Item.DamageType = DamageClass.Melee;
useTime
Frames between uses (lower = faster)
Item.useTime = 20;
useAnimation
Animation duration (usually = useTime)
Item.useAnimation = 20;
rare
Rarity tier (-1 to 11, affects color)
Item.rare = ItemRarityID.Blue;
knockBack
Knockback strength (0-20 typical)
Item.knockBack = 6;
width / height
Hitbox size in pixels
Item.width = 40; Item.height = 40;
value
Sell value in copper (100 = 1 silver)
Item.value = Item.sellPrice(gold: 1);
More Item Examples
Creating a Ranged Weapon
public class ExampleGun : ModItem
{
public override void SetDefaults()
{
Item.damage = 25;
Item.DamageType = DamageClass.Ranged;
Item.width = 44;
Item.height = 24;
Item.useTime = 10;
Item.useAnimation = 10;
Item.useStyle = ItemUseStyleID.Shoot;
Item.noMelee = true; // Important for guns
Item.knockBack = 2;
Item.value = Item.sellPrice(silver: 50);
Item.rare = ItemRarityID.Green;
Item.UseSound = SoundID.Item11;
Item.autoReuse = true;
Item.shoot = ProjectileID.Bullet;
Item.shootSpeed = 16f;
Item.useAmmo = AmmoID.Bullet;
}
}
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; // Makes it an accessory
}
public override void UpdateAccessory(Player player, bool hideVisual)
{
player.moveSpeed += 0.1f; // +10% movement speed
player.maxRunSpeed += 1f;
player.GetDamage(DamageClass.Generic) += 0.05f; // +5% all damage
}
}