1 using Microsoft.Xna.Framework;
2 using Microsoft.Xna.Framework.Graphics;
4 using System.Collections.Generic;
5 using System.Collections.ObjectModel;
7 using System.Text.RegularExpressions;
69 public virtual string Texture => (GetType().Namespace +
"." + Name).Replace(
'.',
'/');
71 [Obsolete(
"override ModItem.OnlyShootOnSwing property",
true)]
74 [Obsolete(
"override ModItem.BossBagNPC property",
true)]
78 private bool ProjOnSwing_Obsolete {
80 set => projOnSwing = value;
84 private int BossBagNPC_Obsolete {
86 set => bossBagNPC = value;
90 item =
new Item { modItem =
this };
99 public virtual bool Autoload(ref
string name) {
100 return mod.Properties.Autoload;
107 public virtual bool CloneNewInstances =>
false;
127 public virtual ModItem Clone(Item item) => NewInstance(item);
136 if (CloneNewInstances) {
138 clone.item = itemClone;
142 var copy = (
ModItem)Activator.CreateInstance(GetType());
143 copy.item = itemClone;
146 copy.ProjOnSwing_Obsolete = ProjOnSwing_Obsolete;
147 copy.BossBagNPC_Obsolete = BossBagNPC_Obsolete;
178 var flameTexture = Texture +
"_Flame";
181 Main.itemFlameLoaded[item.type] =
true;
184 if (DisplayName.IsDefault())
185 DisplayName.SetDefault(Regex.Replace(Name,
"([A-Z])",
" $1").Trim());
192 public virtual int ChoosePrefix(UnifiedRandom rand) => -1;
207 public virtual bool? PrefixChance(
int pre, UnifiedRandom rand) => null;
212 public virtual bool AllowPrefix(
int pre) =>
true;
267 public virtual void GetHealLife(Player player,
bool quickHeal, ref
int healValue) {
276 public virtual void GetHealMana(Player player,
bool quickHeal, ref
int healValue) {
285 public virtual void ModifyManaCost(Player player, ref
float reduce, ref
float mult) {
315 [Obsolete(
"Use ModifyWeaponDamage",
true)]
325 [Obsolete(
"Use ModifyWeaponDamage overload with the additional flat parameter")]
336 public virtual void ModifyWeaponDamage(Player player, ref
float add, ref
float mult, ref
float flat) {
373 public virtual void PickAmmo(Item weapon, Player player, ref
int type, ref
float speed, ref
int damage, ref
float knockback) {
376 [Obsolete(
"PickAmmo now has a weapon parameter that represents the item using the ammo.")]
377 public virtual void PickAmmo(Player player, ref
int type, ref
float speed, ref
int damage, ref
float knockback) {
409 public virtual bool Shoot(Player player, ref Vector2 position, ref
float speedX, ref
float speedY, ref
int type, ref
int damage, ref
float knockBack) {
419 public virtual void UseItemHitbox(Player player, ref Rectangle hitbox, ref
bool noHitbox) {
436 public virtual bool?
CanHitNPC(Player player, NPC target) {
448 public virtual void ModifyHitNPC(Player player, NPC target, ref
int damage, ref
float knockBack, ref
bool crit) {
459 public virtual void OnHitNPC(Player player, NPC target,
int damage,
float knockBack,
bool crit) {
470 public virtual bool CanHitPvp(Player player, Player target) {
481 public virtual void ModifyHitPvp(Player player, Player target, ref
int damage, ref
bool crit) {
491 public virtual void OnHitPvp(Player player, Player target,
int damage,
bool crit) {
585 public virtual bool IsArmorSet(Item head, Item body, Item legs) {
605 headItem.SetDefaults(
Item.headType[head],
true);
609 bodyItem.SetDefaults(
Item.bodyType[body],
true);
613 legItem.SetDefaults(
Item.legType[legs],
true);
615 return IsArmorSet(headItem, bodyItem, legItem);
648 public virtual void SetMatch(
bool male, ref
int equipSlot, ref
bool robes) {
677 public virtual bool ReforgePrice(ref
int reforgePrice, ref
bool canApplyDiscount) {
691 [method: Obsolete(
"PreReforge now returns a bool to control whether the reforge takes place. For now, use NewPreReforge")]
693 item.modItem?.NewPreReforge();
708 public virtual void DrawHands(ref
bool drawHands, ref
bool drawArms) {
716 public virtual void DrawHair(ref
bool drawHair, ref
bool drawAltHair) {
751 public virtual void DrawArmorColor(Player drawPlayer,
float shadow, ref Color color, ref
int glowMask, ref Color glowMaskColor) {
761 public virtual void ArmorArmGlowMask(Player drawPlayer,
float shadow, ref
int glowMask, ref Color color) {
773 public virtual void VerticalWingSpeeds(Player player, ref
float ascentWhenFalling, ref
float ascentWhenRising,
774 ref
float maxCanAscendMultiplier, ref
float maxAscentMultiplier, ref
float constantAscend) {
801 public virtual void Update(ref
float gravity, ref
float maxFallSpeed) {
823 public virtual void GrabRange(Player player, ref
int grabRange) {
880 public virtual bool PreDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref
float rotation, ref
float scale,
int whoAmI) {
893 public virtual void PostDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor,
float rotation,
float scale,
int whoAmI) {
907 public virtual bool PreDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor,
908 Color itemColor, Vector2 origin,
float scale) {
922 public virtual void PostDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor,
923 Color itemColor, Vector2 origin,
float scale) {
965 public virtual void AutoLightSelect(ref
bool dryTorch, ref
bool wetTorch, ref
bool glowstick) {
994 public virtual void AnglerQuestChat(ref
string description, ref
string catchLocation) {
1000 public virtual bool OnlyShootOnSwing => ProjOnSwing_Obsolete;
1005 public virtual int BossBagNPC => BossBagNPC_Obsolete;
1010 public virtual bool IgnoreDamageModifiers =>
false;
1068 public virtual bool PreDrawTooltip(ReadOnlyCollection<TooltipLine> lines, ref
int x, ref
int y) {
virtual void ModifyWeaponDamage(Player player, ref float add, ref float mult, ref float flat)
Allows you to temporarily modify this weapon's damage based on player buffs, etc. This is useful for ...
virtual bool CanEquipAccessory(Player player, int slot)
Allows you to disallow the player from equipping this accessory. Return false to disallow equipping t...
virtual void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
Allows you to create special effects when this melee weapon hits an NPC (for example how the Pumpkin ...
virtual void SetStaticDefaults()
This is where you set all your item's static properties, such as names/translations and the arrays in...
virtual void PostDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, float rotation, float scale, int whoAmI)
Allows you to draw things in front of this item. This method is called even if PreDrawInWorld returns...
virtual bool IsAnglerQuestAvailable()
Whether or not specific conditions have been satisfied for the Angler to be able to request this item...
virtual void PostDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale)
Allows you to draw things in front of this item in the inventory. This method is called even if PreDr...
virtual void AddRecipes()
This is essentially the same as Mod.AddRecipes. Do note that this will be called for every instance o...
virtual void AutoDefaults()
Automatically sets certain defaults. Override this if you do not want the properties to be set for yo...
virtual void MeleeEffects(Player player, Rectangle hitbox)
Allows you to give this melee weapon special effects, such as creating light or dust.
virtual void HoldStyle(Player player)
Allows you to modify the location and rotation of this item when the player is holding it...
virtual void OnConsumeMana(Player player, int manaConsumed)
Allows you to make stuff happen when a player consumes mana on use of this item.
virtual void UpdateArmorSet(Player 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.
virtual ModItem NewInstance(Item itemClone)
Create a new instance of this ModItem 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
virtual bool PreDrawTooltip(ReadOnlyCollection< TooltipLine > lines, ref int x, ref int y)
Allows you to do things before this item's tooltip is drawn.
virtual bool UseItem(Player player)
Allows you to make things happen when this item is used. Return true if using this item actually does...
virtual bool CanPickup(Player player)
Allows you to determine whether or not the item can be picked up
static Texture2D GetTexture(string name)
Gets the texture with the specified name. The name is in the format of "ModFolder/OtherFolders/FileNa...
virtual void OnCraft(Recipe recipe)
Allows you to make anything happen when the player crafts this item using the given recipe...
virtual bool OnPickup(Player player)
Allows you to make special things happen when the player picks up this item. Return false to stop the...
virtual bool ConsumeAmmo(Player player)
Whether or not ammo will be consumed upon usage. Called both by the gun and by the ammo; if at least ...
virtual void GetWeaponCrit(Player player, ref int crit)
Allows you to temporarily modify this weapon's crit chance based on player buffs, etc...
virtual bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
This is called before the weapon creates a projectile. You can use it to create special effects...
virtual Vector2 HoldoutOffset()
Allows you to determine the offset of this item's sprite when used by the player. This is only used f...
virtual void LoadLegacy(BinaryReader reader)
Allows you to load pre-v0.9 custom data that you have saved for this item.
virtual Color GetAlpha(Color lightColor)
Allows you to determine the color and transparency in which this item is drawn. Return null to use th...
virtual void AutoLightSelect(ref bool dryTorch, ref bool wetTorch, ref bool glowstick)
Allows you to tell the game whether this item is a torch that cannot be placed in liquid...
virtual void PreReforge()
virtual void UpdateAccessory(Player player, bool hideVisual)
Allows you to give effects to this accessory. The hideVisual parameter is whether the player has mark...
virtual void AutoStaticDefaults()
Automatically sets certain static defaults. Override this if you do not want the properties to be set...
virtual void PreUpdateVanitySet(Player player)
Allows you to create special effects (such as the necro armor's hurt noise) when the player wears thi...
virtual float MeleeSpeedMultiplier(Player player)
Allows you to change the effective useAnimation of this item.
virtual void VerticalWingSpeeds(Player player, ref float ascentWhenFalling, ref float ascentWhenRising, ref float maxCanAscendMultiplier, ref float maxAscentMultiplier, ref float constantAscend)
Allows you to modify the speeds at which you rise and fall when these wings are equipped.
virtual bool ItemSpace(Player player)
Return true to specify that the item can be picked up despite not having enough room in inventory...
virtual void PickAmmo(Player player, ref int type, ref float speed, ref int damage, ref float knockback)
virtual void ModifyManaCost(Player player, ref float reduce, ref float mult)
Allows you to temporarily modify the amount of mana this item will consume on use, based on player buffs, accessories, etc. This is only called for items with a mana value.
virtual void UpdateInventory(Player player)
Allows you to make things happen when this item is in the player's inventory (for example...
virtual void OnConsumeItem(Player player)
Allows you to make things happen when this item is consumed. Called before the item stack is reduced...
This serves as a central place to store equipment slots and their corresponding textures. You will use this to obtain the IDs for your equipment textures.
virtual bool AltFunctionUse(Player player)
Allows you to make this item usable by right-clicking. Returns false by default. When this item is us...
Manages content added by mods. Liasons between mod content and Terraria's arrays and oversees the Loa...
virtual bool CanHitNPC(Player player, NPC target)
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.
virtual void ModifyHitPvp(Player player, Player target, ref int damage, ref bool crit)
Allows you to modify the damage, etc., that this melee weapon does to a player.
static bool TextureExists(string name)
Returns whether or not a texture with the specified name exists.
EquipType
This is an enum of all the types of equipment that exist. An equipment type is defined as a type or l...
virtual void OnHitPvp(Player player, Player target, int damage, bool crit)
Allows you to create special effects when this melee weapon hits a player.
virtual bool DrawHead()
Return false to hide the player's head when this head armor is worn. Returns true by default...
virtual void NetSend(BinaryWriter writer)
Allows you to send custom data for this item between client and server.
virtual bool UseItemFrame(Player player)
Allows you to modify the player's animation when this item is being used. Return true if you modify t...
virtual void UpdateEquip(Player player)
Allows you to give effects to this armor or accessory, such as increased damage.
virtual void DrawArmorColor(Player drawPlayer, float shadow, ref Color color, ref int glowMask, ref Color glowMaskColor)
Allows you to modify the colors in which this armor and surrounding accessories are drawn...
virtual bool Autoload(ref string name)
Allows you to automatically load an item instead of using Mod.AddItem. Return true to allow autoloadi...
virtual void UpdateVanitySet(Player player)
Allows you to create special effects (such as dust) when the player wears this item's vanity set...
virtual bool PreDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref float rotation, ref float scale, int whoAmI)
Allows you to draw things behind this item, or to modify the way this item is drawn in the world...
virtual void SetMatch(bool male, ref int equipSlot, ref bool robes)
Allows you to modify the equipment that the player appears to be wearing. This hook will only be call...
virtual void ModifyWeaponDamage(Player player, ref float add, ref float mult)
Allows you to temporarily modify this weapon's damage based on player buffs, etc. This is useful for ...
virtual bool PreDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale)
Allows you to draw things behind this item in the inventory. Return false to stop the game from drawi...
virtual void ExtractinatorUse(ref int resultType, ref int resultStack)
Allows you to modify what item, and in what quantity, is obtained when this item is fed into the Extr...
virtual bool DrawBody()
Return false to hide the player's body when this body armor is worn. Returns true by default...
virtual void HorizontalWingSpeeds(Player player, ref float speed, ref float acceleration)
Allows you to modify these wing's horizontal flight speed and acceleration.
virtual void ArmorSetShadows(Player player)
Allows you to determine special visual effects this vanity set has on the player without having to co...
virtual void HoldItem(Player 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).
virtual void NetRecieve(BinaryReader reader)
Receives the custom data sent in the NetSend hook.
virtual void GetHealMana(Player player, bool quickHeal, ref int healValue)
Allows you to temporarily modify the amount of mana a mana healing item will heal for...
virtual void AnglerQuestChat(ref string description, ref string catchLocation)
Allows you to set what the Angler says when he requests for this item. The description parameter is h...
virtual bool IsQuestFish()
Whether or not the Angler can ever randomly request this type of item for his daily quest...
virtual bool CanBurnInLava()
Returns whether or not this item burns when it is thrown into lava despite item.rare not being 0...
virtual bool IsArmorSet(Item head, Item body, Item legs)
Returns whether or not the head armor, body armor, and leg armor make up a set. If this returns true...
virtual bool 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.
virtual void 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.
virtual void GetWeaponKnockback(Player player, ref float knockback)
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.
virtual void 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.
virtual void PickAmmo(Item weapon, Player player, ref int type, ref float speed, ref int damage, ref float knockback)
Allows you to modify the projectile created by a weapon based on the ammo it is using. This hook is called on the ammo.
virtual bool ReforgePrice(ref int reforgePrice, ref bool canApplyDiscount)
Returns if the normal reforge pricing is applied. If true or false is returned and the price is alter...
virtual bool PreDrawTooltipLine(DrawableTooltipLine line, ref int yOffset)
Allows you to do things before a tooltip line of this item is drawn. The line contains draw info...
virtual bool GrabStyle(Player player)
Allows you to modify the way this item moves towards the player. Return true if you override this hoo...
virtual void PostDrawTooltip(ReadOnlyCollection< DrawableTooltipLine > lines)
Allows you to do things after this item's tooltip is drawn. The lines contain draw information as thi...
virtual bool WingUpdate(Player player, bool inUse)
Allows for Wings to do various things while in use. "inUse" is whether or not the jump button is curr...
virtual void ArmorArmGlowMask(Player drawPlayer, float shadow, ref int glowMask, ref Color 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.
virtual bool CanUseItem(Player player)
Returns whether or not this item can be used. By default returns true.
virtual void GrabRange(Player player, ref int grabRange)
Allows you to modify how close this item must be to the player in order to move towards the player...
virtual void UseStyle(Player player)
Allows you to modify the location and rotation of this item in its use animation. ...
virtual void UpdateVanity(Player player, EquipType type)
Allows you to create special effects (such as dust) when this item's equipment texture of the given e...
virtual bool CanHitPvp(Player player, Player target)
Allows you to determine whether this melee weapon can hit the given opponent player when swung...
virtual void OpenBossBag(Player player)
Allows you to give items to the given player when this item is right-clicked in the inventory if the ...
Mod is an abstract class that you will override. It serves as a central place from which the mod's co...
virtual void DrawHair(ref bool drawHair, ref bool drawAltHair)
Allows you to determine whether the player's hair or alt (hat) hair draws when this head armor is wor...
virtual void GetWeaponDamage(Player player, ref int damage)
Allows you to temporarily modify this weapon's damage based on player buffs, etc. This is useful for ...
virtual void UseItemHitbox(Player player, ref Rectangle hitbox, ref bool noHitbox)
Changes the hitbox of this melee weapon when it is used.
virtual TagCompound Save()
Allows you to save custom data for this item. Returns null by default.
This class serves as a place for you to place all your properties and hooks for each item...
virtual bool NewPreReforge()
This hook gets called when the player clicks on the reforge button and can afford the reforge...
virtual void ModifyTooltips(List< TooltipLine > tooltips)
Allows you to modify all the tooltips that display for this item. See here for information about Tool...
virtual void ModifyHitNPC(Player player, NPC target, ref int damage, ref float knockBack, ref bool crit)
Allows you to modify the damage, knockback, etc., that this melee weapon does to an NPC...
virtual void DrawHands(ref bool drawHands, ref bool drawArms)
Allows you to determine whether the skin/shirt on the player's arms and hands are drawn when this bod...
virtual bool HoldItemFrame(Player player)
Allows you to modify the player's animation when the player is holding this item. Return true if you ...
virtual void RightClick(Player player)
Allows you to make things happen when this item is right-clicked in the inventory. Useful for goodie bags.
virtual bool ConsumeItem(Player player)
If this item is consumable and this returns true, then this item will be consumed upon usage...
virtual bool CanRightClick()
Returns whether or not this item does something when it is right-clicked in the inventory. Returns false by default.
virtual void Update(ref float gravity, ref float maxFallSpeed)
Allows you to customize this item's movement when lying in the world. Note that this will not be call...
virtual float UseTimeMultiplier(Player player)
Allows you to change the effective useTime of this item.
virtual void OnConsumeAmmo(Player player)
Allows you to makes things happen when ammo is consumed. Called both by the gun and by the ammo...
virtual void CaughtFishStack(ref int stack)
Allows you to determine how many of this item a player obtains when the player fishes this item...
virtual void OnMissingMana(Player player, int neededMana)
Allows you to make stuff happen when a player doesn't have enough mana for the item they are trying t...
virtual void PostDrawTooltipLine(DrawableTooltipLine line)
Allows you to do things after a tooltip line of this item is drawn. The line contains draw info...
virtual void PostUpdate()
Allows you to make things happen when this item is lying in the world. This will always be called...
virtual Vector2 HoldoutOrigin()
Allows you to determine the point on this item's sprite that the player holds onto when using this it...
virtual void GetHealLife(Player player, bool quickHeal, ref int healValue)
Allows you to temporarily modify the amount of life a life healing item will heal for...
virtual void Load(TagCompound tag)
Allows you to load custom data that you have saved for this item.
virtual bool IsVanitySet(int head, int body, int legs)
Returns whether or not the head armor, body armor, and leg armor textures make up a set...