Terraria.ModLoader.ModItem

This class serves as a place for you to place all your properties and hooks for each item. Create instances of ModItem (preferably overriding this class) to pass as parameters to Mod.AddItem.

Methods

Autoload(System.String@)()
Allows you to automatically load an item instead of using Mod.AddItem. Return true to allow autoloading; by default returns the mod's autoload property. Use this method to force or stop an autoload or change the internal name.
Clone()
Returns a clone of this ModItem. Allows you to decide which fields of your ModItem class are copied over when an item stack is split or something similar happens. By default this will return a memberwise clone; you will want to override this if your GlobalItem contains object references. Only called if CloneNewInstances is set to true. Since several ModItem class fields are also set by the default implementation of this method, you'll most likely want to call base.Clone() as the first statement of your override.
Clone(Terraria.Item)()
Create a copy of this instanced GlobalItem. Called when an item is cloned. Defaults to NewInstance(item)
NewInstance(Terraria.Item)()
Create a new instance of this GlobalItem for an Item instance. Called at the end of Item.SetDefaults. If CloneNewInstances is true, just calls Clone() Otherwise calls the default constructor and copies fields
SetDefaults()
This is where you set all your item's properties, such as width, damage, shootSpeed, defense, etc. For those that are familiar with tAPI, this has the same function as .json files.
AutoDefaults()
Automatically sets certain defaults. Override this if you do not want the properties to be set for you.
SetStaticDefaults()
This is where you set all your item's static properties, such as names/translations and the arrays in ItemID.Sets. This is called after SetDefaults on the initial ModItem
AutoStaticDefaults()
Automatically sets certain static defaults. Override this if you do not want the properties to be set for you.
ChoosePrefix(Terraria.Utilities.UnifiedRandom)()
Allows you to manually choose what prefix an item will get.
CanUseItem(Terraria.Player)()
Returns whether or not this item can be used. By default returns true.
UseStyle(Terraria.Player)()
Allows you to modify the location and rotation of this item in its use animation.
HoldStyle(Terraria.Player)()
Allows you to modify the location and rotation of this item when the player is holding it.
HoldItem(Terraria.Player)()
Allows you to make things happen when the player is holding this item (for example, torches make light and water candles increase spawn rate).
UseTimeMultiplier(Terraria.Player)()
Allows you to change the effective useTime of this item.
MeleeSpeedMultiplier(Terraria.Player)()
Allows you to change the effective useAnimation of this item.
GetHealLife(Terraria.Player,System.Boolean,System.Int32@)()
Allows you to temporarily modify the amount of life a life healing item will heal for, based on player buffs, accessories, etc. This is only called for items with a healLife value.
GetHealMana(Terraria.Player,System.Boolean,System.Int32@)()
Allows you to temporarily modify the amount of mana a mana healing item will heal for, based on player buffs, accessories, etc. This is only called for items with a healMana value.
GetWeaponDamage(Terraria.Player,System.Int32@)()
Allows you to temporarily modify this weapon's damage based on player buffs, etc. This is useful for creating new classes of damage, or for making subclasses of damage (for example, Shroomite armor set boosts). Note that tModLoader follows vanilla principle of only allowing one effective damage class at a time. This means that if you want your own custom damage class, all vanilla damage classes must be set to false. Vanilla checks classes in this order: melee, ranged, magic, thrown, summon So if you set both melee class and another class to true, only the melee damage will actually be used.
GetWeaponKnockback(Terraria.Player,System.Single@)()
Allows you to temporarily modify this weapon's knockback based on player buffs, etc. This allows you to customize knockback beyond the Player class's limited fields. Note that tModLoader follows vanilla principle of only allowing one effective damage class at a time. This means that if you want your own custom damage class, all vanilla damage classes must be set to false. Vanilla checks classes in this order: melee, ranged, magic, thrown, summon So if you set both melee class and another class to true, only the melee knockback will actually be used.
GetWeaponCrit(Terraria.Player,System.Int32@)()
Allows you to temporarily modify this weapon's crit chance based on player buffs, etc. Note that tModLoader follows vanilla principle of only allowing one effective damage class at a time. This means that if you want your own custom damage class, all vanilla damage classes must be set to false. If you use a custom damage class, the crit value will equal item.crit Vanilla checks classes in this order: melee, ranged, magic, thrown, and summon cannot crit. So if you set both melee class and another class to true, only the melee crit will actually be used.
PickAmmo(Terraria.Player,System.Int32@,System.Single@,System.Int32@,System.Single@)()
Allows you to modify the projectile created by a weapon based on the ammo it is using. This hook is called on the ammo.
ConsumeAmmo(Terraria.Player)()
Whether or not ammo will be consumed upon usage. Called both by the gun and by the ammo; if at least one returns false then the ammo will not be used. By default returns true. If false is returned, the OnConsumeAmmo hook is never called.
OnConsumeAmmo(Terraria.Player)()
Allows you to makes things happen when ammo is consumed. Called both by the gun and by the ammo. Called before the ammo stack is reduced.
Shoot(Terraria.Player,Microsoft.Xna.Framework.Vector2@,System.Single@,System.Single@,System.Int32@,System.Int32@,System.Single@)()
This is called before the weapon creates a projectile. You can use it to create special effects, such as changing the speed, changing the initial position, and/or firing multiple projectiles. Return false to stop the game from shooting the default projectile (do this if you manually spawn your own projectile). Returns true by default.
UseItemHitbox(Terraria.Player,Microsoft.Xna.Framework.Rectangle@,System.Boolean@)()
Changes the hitbox of this melee weapon when it is used.
MeleeEffects(Terraria.Player,Microsoft.Xna.Framework.Rectangle)()
Allows you to give this melee weapon special effects, such as creating light or dust.
CanHitNPC(Terraria.Player,Terraria.NPC)()
Allows you to determine whether this melee weapon can hit the given NPC when swung. Return true to allow hitting the target, return false to block this weapon from hitting the target, and return null to use the vanilla code for whether the target can be hit. Returns null by default.
ModifyHitNPC(Terraria.Player,Terraria.NPC,System.Int32@,System.Single@,System.Boolean@)()
Allows you to modify the damage, knockback, etc., that this melee weapon does to an NPC.
OnHitNPC(Terraria.Player,Terraria.NPC,System.Int32,System.Single,System.Boolean)()
Allows you to create special effects when this melee weapon hits an NPC (for example how the Pumpkin Sword creates pumpkin heads).
CanHitPvp(Terraria.Player,Terraria.Player)()
Allows you to determine whether this melee weapon can hit the given opponent player when swung. Return false to block this weapon from hitting the target. Returns true by default.
ModifyHitPvp(Terraria.Player,Terraria.Player,System.Int32@,System.Boolean@)()
Allows you to modify the damage, etc., that this melee weapon does to a player.
OnHitPvp(Terraria.Player,Terraria.Player,System.Int32,System.Boolean)()
Allows you to create special effects when this melee weapon hits a player.
UseItem(Terraria.Player)()
Allows you to make things happen when this item is used. Return true if using this item actually does stuff. Returns false by default. Runs on all clients and server. Use
ConsumeItem(Terraria.Player)()
If this item is consumable and this returns true, then this item will be consumed upon usage. Returns true by default. If false is returned, the OnConsumeItem hook is never called.
OnConsumeItem(Terraria.Player)()
Allows you to make things happen when this item is consumed. Called before the item stack is reduced.
UseItemFrame(Terraria.Player)()
Allows you to modify the player's animation when this item is being used. Return true if you modify the player's animation. Returns false by default.
HoldItemFrame(Terraria.Player)()
Allows you to modify the player's animation when the player is holding this item. Return true if you modify the player's animation. Returns false by default.
AltFunctionUse(Terraria.Player)()
Allows you to make this item usable by right-clicking. Returns false by default. When this item is used by right-clicking, player.altFunctionUse will be set to 2.
UpdateInventory(Terraria.Player)()
Allows you to make things happen when this item is in the player's inventory (for example, how the cell phone makes information display).
UpdateEquip(Terraria.Player)()
Allows you to give effects to this armor or accessory, such as increased damage.
UpdateAccessory(Terraria.Player,System.Boolean)()
Allows you to give effects to this accessory. The hideVisual parameter is whether the player has marked the accessory slot to be hidden from being drawn on the player.
UpdateVanity(Terraria.Player,Terraria.ModLoader.EquipType)()
Allows you to create special effects (such as dust) when this item's equipment texture of the given equipment type is displayed on the player. Note that this hook is only ever called through this item's associated equipment texture.
IsArmorSet(Terraria.Item,Terraria.Item,Terraria.Item)()
Returns whether or not the head armor, body armor, and leg armor make up a set. If this returns true, then this item's UpdateArmorSet method will be called. Returns false by default.
UpdateArmorSet(Terraria.Player)()
Allows you to give set bonuses to the armor set that this armor is in. Set player.setBonus to a string for the bonus description.
IsVanitySet(System.Int32,System.Int32,System.Int32)()
Returns whether or not the head armor, body armor, and leg armor textures make up a set. This hook is used for the PreUpdateVanitySet, UpdateVanitySet, and ArmorSetShadow hooks. By default, this will return the same value as the IsArmorSet hook (passing the equipment textures' associated items as parameters), so you will not have to use this hook unless you want vanity effects to be entirely separate from armor sets. Note that this hook is only ever called through this item's associated equipment texture.
PreUpdateVanitySet(Terraria.Player)()
Allows you to create special effects (such as the necro armor's hurt noise) when the player wears this item's vanity set. This hook is called regardless of whether the player is frozen in any way. Note that this hook is only ever called through this item's associated equipment texture.
UpdateVanitySet(Terraria.Player)()
Allows you to create special effects (such as dust) when the player wears this item's vanity set. This hook will only be called if the player is not frozen in any way. Note that this hook is only ever called through this item's associated equipment texture.
ArmorSetShadows(Terraria.Player)()
Allows you to determine special visual effects this vanity set has on the player without having to code them yourself. Note that this hook is only ever called through this item's associated equipment texture. Use the player.armorEffectDraw bools to activate the desired effects.
SetMatch(System.Boolean,System.Int32@,System.Boolean@)()
Allows you to modify the equipment that the player appears to be wearing. This hook will only be called for body armor and leg armor. Note that equipSlot is not the same as the item type of the armor the player will appear to be wearing. Worn equipment has a separate set of IDs. You can find the vanilla equipment IDs by looking at the headSlot, bodySlot, and legSlot fields for items, and modded equipment IDs by looking at EquipLoader. If this hook is called on body armor, equipSlot allows you to modify the leg armor the player appears to be wearing. If you modify it, make sure to set robes to true. If this hook is called on leg armor, equipSlot allows you to modify the leg armor the player appears to be wearing, and the robes parameter is useless. Note that this hook is only ever called through this item's associated equipment texture.
CanRightClick()
Returns whether or not this item does something when it is right-clicked in the inventory. Returns false by default.
RightClick(Terraria.Player)()
Allows you to make things happen when this item is right-clicked in the inventory. Useful for goodie bags.
OpenBossBag(Terraria.Player)()
Allows you to give items to the given player when this item is right-clicked in the inventory if the bossBagNPC field has been set to a positive number. This ignores the CanRightClick and RightClick hooks.
ReforgePrice(System.Int32@,System.Boolean@)()
Returns if the normal reforge pricing is applied. If true or false is returned and the price is altered, the price will equal the altered price. The passed reforge price equals the item.value. Vanilla pricing will apply 20% discount if applicable and then price the reforge at a third of that value.
PostReforge()
This hook gets called immediately after an item gets reforged by the Goblin Tinkerer. Useful for modifying modded data based on the reforge result.
DrawHands(System.Boolean@,System.Boolean@)()
Allows you to determine whether the skin/shirt on the player's arms and hands are drawn when this body armor is worn. By default both flags will be false. Note that if drawHands is false, the arms will not be drawn either. Also note that this hook is only ever called through this item's associated equipment texture.
DrawHair(System.Boolean@,System.Boolean@)()
Allows you to determine whether the player's hair or alt (hat) hair draws when this head armor is worn. By default both flags will be false. Note that this hook is only ever called through this item's associated equipment texture.
DrawHead()
Return false to hide the player's head when this head armor is worn. Returns true by default. Note that this hook is only ever called through this item's associated equipment texture.
DrawBody()
Return false to hide the player's body when this body armor is worn. Returns true by default. Note that this hook is only ever called through this item's associated equipment texture.
DrawLegs()
Return false to hide the player's legs when this leg armor or shoe accessory is worn. Returns true by default. Note that this hook is only ever called through this item's associated equipment texture.
DrawArmorColor(Terraria.Player,System.Single,Microsoft.Xna.Framework.Color@,System.Int32@,Microsoft.Xna.Framework.Color@)()
Allows you to modify the colors in which this armor and surrounding accessories are drawn, in addition to which glow mask and in what color is drawn. Note that this hook is only ever called through this item's associated equipment texture.
ArmorArmGlowMask(Terraria.Player,System.Single,System.Int32@,Microsoft.Xna.Framework.Color@)()
Allows you to modify which glow mask and in what color is drawn on the player's arms. Note that this is only called for body armor. Also note that this hook is only ever called through this item's associated equipment texture.
VerticalWingSpeeds(Terraria.Player,System.Single@,System.Single@,System.Single@,System.Single@,System.Single@)()
Allows you to modify the speeds at which you rise and fall when these wings are equipped.
HorizontalWingSpeeds(Terraria.Player,System.Single@,System.Single@)()
Allows you to modify these wing's horizontal flight speed and acceleration.
WingUpdate(Terraria.Player,System.Boolean)()
Allows for Wings to do various things while in use. "inUse" is whether or not the jump button is currently pressed. Called when these wings visually appear on the player. Use to animate wings, create dusts, invoke sounds, and create lights. Note that this hook is only ever called through this item's associated equipment texture. False will keep everything the same. True, you need to handle all animations in your own code.
Update(System.Single@,System.Single@)()
Allows you to customize this item's movement when lying in the world. Note that this will not be called if this item is currently being grabbed by a player.
PostUpdate()
Allows you to make things happen when this item is lying in the world. This will always be called, even when it is being grabbed by a player. This hook should be used for adding light, or for increasing the age of less valuable items.
GrabRange(Terraria.Player,System.Int32@)()
Allows you to modify how close this item must be to the player in order to move towards the player.
GrabStyle(Terraria.Player)()
Allows you to modify the way this item moves towards the player. Return true if you override this hook; returning false will allow the vanilla grab style to take place. Returns false by default.
CanPickup(Terraria.Player)()
Allows you to determine whether or not the item can be picked up
OnPickup(Terraria.Player)()
Allows you to make special things happen when the player picks up this item. Return false to stop the item from being added to the player's inventory; returns true by default.
ItemSpace(Terraria.Player)()
Return true to specify that the item can be picked up despite not having enough room in inventory. Useful for something like hearts or experience items. Use in conjunction with OnPickup to actually consume the item and handle it.
GetAlpha(Microsoft.Xna.Framework.Color)()
Allows you to determine the color and transparency in which this item is drawn. Return null to use the default color (normally light color). Returns null by default.
PreDrawInWorld(Microsoft.Xna.Framework.Graphics.SpriteBatch,Microsoft.Xna.Framework.Color,Microsoft.Xna.Framework.Color,System.Single@,System.Single@,System.Int32)()
Allows you to draw things behind this item, or to modify the way this item is drawn in the world. Return false to stop the game from drawing the item (useful if you're manually drawing the item). Returns true by default.
PostDrawInWorld(Microsoft.Xna.Framework.Graphics.SpriteBatch,Microsoft.Xna.Framework.Color,Microsoft.Xna.Framework.Color,System.Single,System.Single,System.Int32)()
Allows you to draw things in front of this item. This method is called even if PreDrawInWorld returns false.
PreDrawInInventory(Microsoft.Xna.Framework.Graphics.SpriteBatch,Microsoft.Xna.Framework.Vector2,Microsoft.Xna.Framework.Rectangle,Microsoft.Xna.Framework.Color,Microsoft.Xna.Framework.Color,Microsoft.Xna.Framework.Vector2,System.Single)()
Allows you to draw things behind this item in the inventory. Return false to stop the game from drawing the item (useful if you're manually drawing the item). Returns true by default.
PostDrawInInventory(Microsoft.Xna.Framework.Graphics.SpriteBatch,Microsoft.Xna.Framework.Vector2,Microsoft.Xna.Framework.Rectangle,Microsoft.Xna.Framework.Color,Microsoft.Xna.Framework.Color,Microsoft.Xna.Framework.Vector2,System.Single)()
Allows you to draw things in front of this item in the inventory. This method is called even if PreDrawInInventory returns false.
HoldoutOffset()
Allows you to determine the offset of this item's sprite when used by the player. This is only used for items with a useStyle of 5 that aren't staves. Return null to use the vanilla holdout offset; returns null by default.
HoldoutOrigin()
Allows you to determine the point on this item's sprite that the player holds onto when using this item. The origin is from the bottom left corner of the sprite. This is only used for staves with a useStyle of 5. Return null to use the vanilla holdout origin (zero); returns null by default.
CanEquipAccessory(Terraria.Player,System.Int32)()
Allows you to disallow the player from equipping this accessory. Return false to disallow equipping this accessory. Returns true by default.
ExtractinatorUse(System.Int32@,System.Int32@)()
Allows you to modify what item, and in what quantity, is obtained when this item is fed into the Extractinator. By default the parameters will be set to the output of feeding Silt/Slush into the Extractinator.
AutoLightSelect(System.Boolean@,System.Boolean@,System.Boolean@)()
Allows you to tell the game whether this item is a torch that cannot be placed in liquid, a torch that can be placed in liquid, or a glowstick. This information is used for when the player is holding down the auto-select hotkey.
CaughtFishStack(System.Int32@)()
Allows you to determine how many of this item a player obtains when the player fishes this item.
IsQuestFish()
Whether or not the Angler can ever randomly request this type of item for his daily quest. Returns false by default.
IsAnglerQuestAvailable()
Whether or not specific conditions have been satisfied for the Angler to be able to request this item. (For example, Hardmode.) Returns true by default.
AnglerQuestChat(System.String@,System.String@)()
Allows you to set what the Angler says when he requests for this item. The description parameter is his dialogue, and catchLocation should be set to "\n(Caught at [location])".
Save()
Allows you to save custom data for this item. Returns null by default.
Load(Terraria.ModLoader.IO.TagCompound)()
Allows you to load custom data that you have saved for this item.
LoadLegacy(System.IO.BinaryReader)()
Allows you to load pre-v0.9 custom data that you have saved for this item.
NetSend(System.IO.BinaryWriter)()
Allows you to send custom data for this item between client and server.
NetRecieve(System.IO.BinaryReader)()
Receives the custom data sent in the NetSend hook.
AddRecipes()
This is essentially the same as Mod.AddRecipes. Do note that this will be called for every instance of the overriding ModItem class that is added to the game. This allows you to avoid clutter in your overriding Mod class by adding recipes for which this item is the result.
OnCraft(Terraria.Recipe)()
Allows you to make anything happen when the player crafts this item using the given recipe.
PreDrawTooltip(System.Collections.ObjectModel.ReadOnlyCollection{Terraria.ModLoader.TooltipLine},System.Int32@,System.Int32@)()
Allows you to do things before this item's tooltip is drawn.
PostDrawTooltip(System.Collections.ObjectModel.ReadOnlyCollection{Terraria.ModLoader.DrawableTooltipLine})()
Allows you to do things after this item's tooltip is drawn. The lines contain draw information as this is ran after drawing the tooltip.
PreDrawTooltipLine(Terraria.ModLoader.DrawableTooltipLine,System.Int32@)()
Allows you to do things before a tooltip line of this item is drawn. The line contains draw info.
PostDrawTooltipLine(Terraria.ModLoader.DrawableTooltipLine)()
Allows you to do things after a tooltip line of this item is drawn. The line contains draw info.
ModifyTooltips(System.Collections.Generic.List{Terraria.ModLoader.TooltipLine})()
Allows you to modify all the tooltips that display for this item. See here for information about TooltipLine.