Item Class Documentation - tModLoader/tModLoader GitHub Wiki
This page lists methods and fields pertaining to the Item class. This page is useful for understanding what to use in ModItem.SetDefaults.
Index |
---|
Fields |
Methods |
You can assign these fields to give your ModItem various values. Typically you'll want to refer to this page when writing code for ModItem.SetDefaults. Be sure to visit Vanilla Item Field Values to see what values vanilla items use for these fields. All fields listed are public unless otherwise noted.
Field | Type | Default Value | Description |
---|---|---|---|
value | int | 0 | Value is the number of copper coins the item is worth (aka, cost to buy from a merchant). Setting it to 10462 would mean the item cost 1 gold, 4 silver, and 62 copper. The sell price of an item is one fifth of its value. Value also influences reforge costs with the goblin tinkerer. For convenience, you can also use the Item.buyPrice() method for setting values: item.value = Item.buyPrice(0, 1, 4, 62); You can also use the Item.sellPrice() method if you would rather think about an items value the other way. Both Item.buyPrice(0, 0, 10, 55) and Item.sellPrice(0, 0, 2, 11) would set the value to 1055. |
useStyle | int | 0 | The use style of your item: 1 for swinging, 2 for drinking, 3 act like shortsword, 4 for use like life crystal, 5 for use staffs or guns |
useTurn | bool | false | Whether the player can turn around while the using animation is happening. |
autoReuse | bool | false | Whether the item is in continuous use while the mouse button is held down. |
holdStyle | int | 0 | The hold style of your item: 1 for holding out (torches and glowsticks) 2 for holding up (Breathing Reed) 3 for a different version of holding out (Magical Harp) |
useAnimation | int | 100 | The time span of the using animation for the item. Recommended to be the same at useTime as this is only the animation. Blocks use 15. Default value is 100. Terraria runs at 60 frames per second, so 15 is 1/4th of a second. |
useTime | int | 100 | The time span of using the item in frames. Blocks use 10. Default value is 100. Weapons usually have equal useAnimation and useTime, unequal values for these two results in multiple attacks per click. See ExampleGun.cs's Clockwork Assault Rifle example. |
reuseDelay | int | 0 | A delay in frames added at the end of the using animation for the item, during which the player wont be able to use any items. |
consumable | bool | false | Whether the item is consumed after use. |
rare | int | 0 | Range from -1 to 13. Check wiki link for respective colors: https://terraria.wiki.gg/wiki/Rarity. You can use ItemRarityID for convenience: ItemRarityID.cs, Sample Usage
|
maxStack | int | 1 | The maximum number of items that can be contained within a single stack. |
width | int | 0 | The width of the dropped item's hitbox in pixels. |
height | int | 0 | The height of the dropped item's hitbox in pixels. |
scale | float | 1f | The size multiplier of the item's sprite while the item is being used. Also increases range for melee weapons. |
createTile | int | -1 | The ID of the tile this item places on use. |
placeStyle | int | 0 | The style of the tile being placed. Used for tiles that have a different look depending on the item used to place them. |
createWall | int | -1 | The ID of the wall this item places on use. |
UseSound | LegacySoundStyle | null | The sound that your item makes when used. Ex: item.UseSound = SoundID.Item1;
|
damage | int | -1 | The base damage inflicted by the item. |
knockBack | float | 0f | The force of the knock back. Max value is 20. |
shoot | int | 0 | The ID of the projectile that is fired by the item on use. If this weapon uses useAmmo, then this value is ignored as the projectile will be decided by the ammo item, but shoot should still be 10 by convention. |
shootSpeed | float | 0f | The velocity in pixels the projectile fired by the item will have. Actual velocity depends on the projectile being fired. If your weapon is shooting projectiles and they are stationary, change this to something like 10f. Throwing Knife uses 10f. Held projectiles like Vortex Beater use shootSpeed to determine how far away from the player to hold the projectile. |
noMelee | bool | false | If true, the item's using animation will not deal damage. Set to true on most weapons that aren't swords. |
accessory | bool | false | Whether the item is an accessory. |
melee magic ranged thrown summon |
bool | false | The type of damage this item deals, if it is a weapon. |
axe pick hammer |
int | 0 | These 3 correspond to the power, but axe power is multiplied by 5, so adjust accordingly. |
defense | int | 0 | The amount of defense this item provides when equipped, either as an accessory or armor. |
crit | int | 0 | The base critical chance for this item. Remember that the player has a base crit chance of 4. |
noUseGraphic | bool | false | If true, the item's sprite will not be visible while the item is in use. |
useAmmo | int | AmmoID.None (0) | The ID of the ammo used by this item. See Ammo Guide |
ammo | int | AmmoID.None (0) | The ID of the ammo class this item is part of. See Ammo Guide |
notAmmo | bool | false | If true and the item is ammo, the item will not count as ammo for certain ammo-specific behavior, such as the tooltip mentioning the item is ammo, or ammo items going into ammo slots first when picked up. Used for the Coin items, Ale, and Wire. |
mana | int | 0 | The amount of mana this item consumes on use. |
channel | bool | false | Used for items that have special behavior when the attack button is held. |
potion | bool | false | If true, this item will inflict potion sickness on use. Also determines whether the item cannot be used when the player has potion sickness, and if the item can be used with the Quick Heal key. |
healLife | int | 0 | The amount of life this item heals on use. |
healMana | int | 0 | The amount of mana this item heals on use. |
buffType | int | 0 | The ID of the buff given by this item on use. To have a potion give multiple buffs, assign one buff here and in ModItem.UseItem , call player.AddBuff(buffID, time) for the remaining buffs you wish to give. Make sure to set buffTime as well or the buff will instantly disappear. |
buffTime | int | 0 | The duration in ticks of the buff given by this item on use. |
expert | bool | false | Signifies that this item is an expert mode item. |
bait fishingPole |
int | 0 | Correspond to fishing power of bait or poles respectively. |
questItem | bool | false | Whether this item's tooltip will mention it is a quest item. |
mech | bool | false | Whether this item will show wires when held. |
material | bool | false | If this item is a an ingredient in any recipe. Automatically assigned. |
backSlot balloonSlot bodySlot faceSlot frontSlot handOffSlot handOnSlot headSlot legSlot neckSlot shieldSlot shoeSlot waistSlot wingSlot |
sbyte | -1 | These values indicate which equipment slots the accessory or armor will show. These slots correspond the the textures that are shown while equipped. tModLoader automatically will assign your item the correct values based on the AutoloadEquip attribute. |
Field | Type | Default Value | Description |
---|---|---|---|
DD2Summon | bool | false | |
ToolTip | ItemTooltip | null | |
active | bool | true | If false, this item is empty regardless of other values set. |
alpha | int | 0 | |
buy | bool | false | |
cartTrack | bool | false | |
color | Color | Transparent | Draws the item sprite with a colored tint. Gel and Sharkfin use this to spawn different colored items from the same ItemID. NetMessage.SendData(88, ... needs to be used to sync this if not done in SetDefaults. |
dye | byte | 0 | |
expertOnly | bool | false | If true, the accessory won't give any effects unless the world is in Expert mode. |
favorited | bool | false | If the item has been marked as favorited in the inventory. |
flame | bool | false | |
glowMask | short | -1 | |
hairDye | short | -1 | |
instanced | bool | false | |
lavaWet | bool | false | |
lifeRegen | int | 0 | |
makeNPC | short | 0 | Spawns the specified NPCID. |
manaIncrease | int | 0 | |
mountType | int | -1 | Specifies which mount to equip when the item is used. See ExampleMountItem |
netID | int | 0 | Don't use. |
noWet | bool | false | |
paint | byte | 0 | |
prefix | byte | 0 | |
release | int | 0 | |
sentry | bool | false | |
shopCustomPrice | int? | null | Use in ModNPC/GlobalNPC.SetupShop to assign a custom price for an item regardless of the value field. Use with shopSpecialCurrency to use a custom currency rather than coins. See ExampleNPCShop.SetupShop
|
shopSpecialCurrency | int | -1 | Used in conjunction with shopCustomPrice to specify a custom currency. See ExampleMod.Load and ExampleCustomCurrency |
stack | int | 1 | Current stack of the Item. |
tileBoost | int | -1 | Specifies the use range of a Tool |
tileWand | int | 0 | |
type | int | 0 | This is the ItemID, automatically set. |
uniqueStack | bool | false | |
vanity | bool | false | Specifies that an armor is a vanity item. |
wet | bool | false | |
wetCount | int | 0 | |
Static fields are accessed by the classname, not the instance. For example, we write Item.staff[item.type]
to check if an item is marked as a staff. Set these values in ModItem.SetStaticDefaults
.
Field | Type | Default Value | Description |
---|---|---|---|
staff | bool[] | false | Indexed by ItemID. This makes the useStyle animate as a staff instead of as a gun. See ExampleStaff. If the staff doesn't rotate, make sure Item.shootSpeed is not 0. |
Field | Type | Default Value | Description |
---|---|---|---|
modItem | ModItem | null | The ModItem instance that controls the behavior of this item. This property is null if this is not a modded item. |
globalItems | internal GlobalItem[] | new GlobalItem[0] | Do not touch. Use Item.GetGlobalItem
|
Remember that static methods are called by writing the classname and non-static methods use the instance name. Item.NewItem(...)
vs item.CloneDefaults(...)
public static int NewItem(int X, int Y, int Width, int Height, int Type, int Stack = 1, bool noBroadcast = false, int pfix = 0, bool noGrabDelay = false, bool reverseLookup = false)
Spawns an item in the world. Commonly seen used in ModNPC.NPCLoot. X, Y, Width, and Height are commonly derived from the npc. This method should not be called on multiplayer clients. If you need to spawn items from client code, use player.QuickSpawnItem
, it handles the multiplayer syncing code needed.
Example: Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ModContent.ItemType<ExampleItem>());
public static int NewItem(Rectangle rectangle, int Type, int Stack = 1, bool noBroadcast = false, int prefixGiven = 0, bool noGrabDelay = false, bool reverseLookup = false)
This alternate method signature can simplify code.
Example: Item.NewItem(npc.getRect(), ModContent.ItemType<ExampleItem>());
Gets the GlobalItem instance (with the given name and added by the given mod) associated with this item instance.
Same as the other GetGlobalItem, but assumes that the class name and internal name are the same.
Same as the other GetGlobalItem, but assumes that the class name and internal name are the same, as well as the Mod. This is the one you should use 99% of the time.
Allows you to copy the defaults of a different type of item.