tModLoader v2023.01
A mod to make and play Terraria mods
Terraria.ModLoader.ModPlayer Class Reference

A ModPlayer instance represents an extension of a Player instance. You can store fields in the ModPlayer classes, much like how the Player class abuses field usage, to keep track of mod-specific information on the player that a ModPlayer instance represents. It also contains hooks to insert your code into the Player class. More...

Inherits Terraria.ModLoader.ModType< Player, ModPlayer >, and Terraria.ModLoader.IIndexed.

Inherited by Terraria.ModLoader.Default.ConsumedStatIncreasesPlayer, Terraria.ModLoader.Default.Developer.Jofairden.JofairdenArmorEffectPlayer, Terraria.ModLoader.Default.ModAccessorySlotPlayer, Terraria.ModLoader.Default.Patreon.GuildpackSetEffectPlayer, Terraria.ModLoader.Default.Patreon.OrianSetEffectPlayer, and Terraria.ModLoader.Default.UnloadedPlayer.

Public Member Functions

virtual IEnumerable< ItemAddStartingItems (bool mediumCoreDeath)
 Called when the player is created in the menu. You can use this method to add items to the player's starting inventory, as well as their inventory when they respawn in mediumcore. More...
 
virtual void AnglerQuestReward (float rareMultiplier, List< Item > rewardItems)
 Allows you to add to, change, or remove from the items the player earns when finishing an Angler quest. The rareMultiplier is a number between 0.15 and 1 inclusively; the lower it is the higher chance there should be for the player to earn rare items. More...
 
virtual ? bool CanAutoReuseItem (Item item)
 Allows you to modify the autoswing (auto-reuse) behavior of any item without having to mess with Item.autoReuse.
Useful to create effects like the Feral Claws which makes melee weapons and whips auto-reusable.
Return true to enable autoswing (if not already enabled through autoReuse), return false to prevent autoswing. Returns null by default, which applies vanilla behavior. More...
 
virtual bool CanBeHitByNPC (NPC npc, ref int cooldownSlot)
 Allows you to determine whether the given NPC can hit this player. Return false to block this player from being hit by the NPC. Returns true by default. CooldownSlot determines which of the player's cooldown counters to use (-1, 0, or 1), and defaults to -1. More...
 
virtual bool CanBeHitByProjectile (Projectile proj)
 Allows you to determine whether the given hostile projectile can hit this player. Return false to block this player from being hit. Returns true by default. More...
 
virtual bool CanBuyItem (NPC vendor, Item[] shopInventory, Item item)
 Return false to prevent a transaction. Called before the transaction. More...
 
virtual ? bool CanCatchNPC (NPC target, Item item)
 Allows you to determine whether the given item can catch the given NPC.
Return true or false to say the target can or cannot be caught, respectively, regardless of vanilla rules.
Returns null by default, which allows vanilla's NPC catching rules to decide the target's fate.
If this returns false, CombinedHooks.OnCatchNPC is never called.

NOTE: this does not classify the given item as a catch tool, which is necessary for catching NPCs in the first place.
To do that, you will need to use the "CatchingTool" set in ItemID.Sets. More...
 
virtual bool CanConsumeAmmo (Item weapon, Item ammo)
 Whether or not the given ammo item will be consumed by this weapon.
By default, returns true; return false to prevent ammo consumption.
If false is returned, the OnConsumeAmmo hook is never called. More...
 
virtual ? bool CanConsumeBait (Item bait)
 Choose if this bait will be consumed or not when used for fishing. return null for vanilla behaviour. Not consuming will always take priority over forced consumption More...
 
virtual ? bool CanHitNPC (Item item, NPC target)
 Allows you to determine whether a player can hit the given NPC by swinging a melee weapon. Return true to allow hitting the target, return false to block this player from hitting the target, and return null to use the vanilla code for whether the target can be hit. Returns null by default. More...
 
virtual ? bool CanHitNPCWithProj (Projectile proj, NPC target)
 Allows you to determine whether a projectile created by this player can hit the given NPC. Return true to allow hitting the target, return false to block this projectile from hitting the target, and return null to use the vanilla code for whether the target can be hit. Returns null by default. More...
 
virtual bool CanHitPvp (Item item, Player target)
 Allows you to determine whether a melee weapon swung by this player can hit the given opponent player. Return false to block this weapon from hitting the target. Returns true by default. More...
 
virtual bool CanHitPvpWithProj (Projectile proj, Player target)
 Allows you to determine whether a projectile created by this player can hit the given opponent player. Return false to block the projectile from hitting the target. Returns true by default. More...
 
virtual bool CanSellItem (NPC vendor, Item[] shopInventory, Item item)
 Return false to prevent a transaction. Called before the transaction. More...
 
virtual bool CanShoot (Item item)
 Allows you to prevent an item from shooting a projectile on use. Returns true by default. More...
 
virtual bool CanUseItem (Item item)
 Return false to prevent an item from being used. By default returns true. More...
 
virtual void CatchFish (FishingAttempt attempt, ref int itemDrop, ref int npcSpawn, ref AdvancedPopupRequest sonar, ref Vector2 sonarPosition)
 Allows you to change the item or enemy the player gets when sucessfully catching an item or NPC. The Fishing Attempt structure contains most information about the vanilla event, including the Item Rod and Bait used by the player, the liquid it is being fished on, and so on. The Sonar and Sonar position fields allow you to change the text, color, velocity and position of the catch's name (be it item or NPC) freely More...
 
virtual void clientClone (ModPlayer clientClone)
 Allows you to copy information about this player to the clientClone parameter. You should copy information that you intend to sync between server and client. This hook is called in the Player.clientClone method. See SendClientChanges for more info. More...
 
virtual void DrawEffects (PlayerDrawSet drawInfo, ref float r, ref float g, ref float b, ref float a, ref bool fullBright)
 Allows you to create special effects when this player is drawn, such as creating dust, modifying the color the player is drawn in, etc. The fullBright parameter makes it so that the drawn player ignores the modified color and lighting. Note that the fullBright parameter only works if r, g, b, and/or a is not equal to 1. Make sure to add the indexes of any dusts you create to drawInfo.DustCache, and the indexes of any gore you create to drawInfo.GoreCache.
This will be called multiple times a frame if a player afterimage is being drawn. Check More...
 
virtual void FrameEffects ()
 Allows you to modify the armor and accessories that visually appear on the player. In addition, you can create special effects around this character, such as creating dust.
 
virtual void GetDyeTraderReward (List< int > rewardPool)
 Allows you to modify what items are possible for the player to earn when giving a Strange Plant to the Dye Trader. More...
 
virtual void GetFishingLevel (Item fishingRod, Item bait, ref float fishingLevel)
 Allows you to modify the player's fishing power. As an example of the type of stuff that should go here, the phase of the moon can influence fishing power. More...
 
virtual void GetHealLife (Item item, bool quickHeal, ref int healValue)
 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. More...
 
virtual void GetHealMana (Item item, bool quickHeal, ref int healValue)
 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. More...
 
virtual void HideDrawLayers (PlayerDrawSet drawInfo)
 Allows you to modify the visibility of layers about to be drawn More...
 
virtual bool HoverSlot (Item[] inventory, int context, int slot)
 Called whenever the player hovers over an item slot. This can be used to override Main.cursorOverride
See ID.CursorOverrideID for cursor override style IDs More...
 
virtual void Hurt (bool pvp, bool quiet, double damage, int hitDirection, bool crit)
 
virtual void Hurt (bool pvp, bool quiet, double damage, int hitDirection, bool crit, int cooldownCounter)
 Allows you to make anything happen right before damage is subtracted from the player's health. More...
 
virtual void Initialize ()
 Called whenever the player is loaded (on the player selection screen). This can be used to initialize data structures, etc. More...
 
virtual void Kill (double damage, int hitDirection, bool pvp, PlayerDeathReason damageSource)
 Allows you to make anything happen when the player dies. More...
 
virtual void LoadData (TagCompound tag)
 Allows you to load custom data that you have saved for this player.
Try to write defensive loading code that won't crash if something's missing. More...
 
virtual void MeleeEffects (Item item, Rectangle hitbox)
 Allows you to give this player's melee weapon special effects, such as creating light or dust. More...
 
virtual void ModifyCaughtFish (Item fish)
 Allows you to modify the item caught by the fishing player, including stack More...
 
virtual void ModifyDrawInfo (ref PlayerDrawSet drawInfo)
 Allows you to modify the drawing parameters of the player before drawing begins. More...
 
virtual void ModifyDrawLayerOrdering (IDictionary< PlayerDrawLayer, PlayerDrawLayer.Position > positions)
 Allows you to reorder the player draw layers. This is called once at the end of mod loading, not during the game. Use with extreme caution, or risk breaking other mods. More...
 
virtual void ModifyFishingAttempt (ref FishingAttempt attempt)
 Allows you to change information about the ongoing fishing attempt before cought items/NPCs are decided, after all vanilla information has been gathered.
Will not be called if various conditions for getting a catch aren't met, meaning you can't modify those.
Setting FishingAttempt.rolledItemDrop or FishingAttempt.rolledEnemySpawn is not allowed and will be reset, use CatchFish for that. More...
 
virtual void ModifyHitByNPC (NPC npc, ref int damage, ref bool crit)
 Allows you to modify the damage, etc., that an NPC does to this player. More...
 
virtual void ModifyHitByProjectile (Projectile proj, ref int damage, ref bool crit)
 Allows you to modify the damage, etc., that a hostile projectile does to this player. More...
 
virtual void ModifyHitNPC (Item item, NPC target, ref int damage, ref float knockback, ref bool crit)
 Allows you to modify the damage, knockback, etc., that this player does to an NPC by swinging a melee weapon. More...
 
virtual void ModifyHitNPCWithProj (Projectile proj, NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection)
 Allows you to modify the damage, knockback, etc., that a projectile created by this player does to an NPC. More...
 
virtual void ModifyHitPvp (Item item, Player target, ref int damage, ref bool crit)
 Allows you to modify the damage, etc., that a melee weapon swung by this player does to an opponent player. More...
 
virtual void ModifyHitPvpWithProj (Projectile proj, Player target, ref int damage, ref bool crit)
 Allows you to modify the damage, etc., that a projectile created by this player does to an opponent player. More...
 
virtual void ModifyItemScale (Item item, ref float scale)
 Allows you to dynamically modify the given item's size for this player, similarly to the effect of the Titan Glove. More...
 
virtual void ModifyLuck (ref float luck)
 Allows you to modify a player's luck amount. More...
 
virtual void ModifyManaCost (Item item, ref float reduce, ref float mult)
 Allows you to temporarily modify the amount of mana an item will consume on use, based on player buffs, accessories, etc. This is only called for items with a mana value. More...
 
virtual void ModifyMaxStats (out StatModifier health, out StatModifier mana)
 Allows you to modify the player's max stats. This hook runs after vanilla increases from the Life Crystal, Life Fruit and Mana Crystal are applied
NOTE: You should NOT modify Player.statLifeMax nor Player.statManaMax here. Use the health and mana parameters. More...
 
virtual bool ModifyNurseHeal (NPC nurse, ref int health, ref bool removeDebuffs, ref string chatText)
 Called on the Client while the nurse chat is displayed. Return false to prevent the player from healing. If you return false, you need to set chatText so the user knows why they can't heal. More...
 
virtual void ModifyNursePrice (NPC nurse, int health, bool removeDebuffs, ref int price)
 Called on the Client while the nurse chat is displayed and after ModifyNurseHeal. Allows custom pricing for Nurse services. See https://terraria.gamepedia.com/Nurse for the default pricing. More...
 
virtual void ModifyScreenPosition ()
 Use this hook to modify Main.screenPosition after weapon zoom and camera lerp have taken place.
 
virtual void ModifyShootStats (Item item, ref Vector2 position, ref Vector2 velocity, ref int type, ref int damage, ref float knockback)
 Allows you to modify the position, velocity, type, damage and/or knockback of a projectile being shot by an item. More...
 
virtual void ModifyStartingInventory (IReadOnlyDictionary< string, List< Item > > itemsByMod, bool mediumCoreDeath)
 Allows you to modify the items that will be added to the player's inventory. Useful if you want to stop vanilla or other mods from adding an item. You can access a mod's items by using the mod's internal name as the indexer, such as: additions["ModName"]. To access vanilla items you can use "Terraria" as the index. More...
 
virtual void ModifyWeaponCrit (Item item, ref float crit)
 Allows you to dynamically modify a weapon's crit chance based on player and item conditions. Can be utilized to modify damage beyond the tools that DamageClass has to offer. More...
 
virtual void ModifyWeaponDamage (Item item, ref StatModifier damage)
 Allows you to dynamically modify a weapon's damage based on player and item conditions. Can be utilized to modify damage beyond the tools that DamageClass has to offer. More...
 
virtual void ModifyWeaponKnockback (Item item, ref StatModifier knockback)
 Allows you to dynamically modify a weapon's knockback based on player and item conditions. Can be utilized to modify damage beyond the tools that DamageClass has to offer. More...
 
virtual void ModifyZoom (ref float zoom)
 Use this to modify the zoom factor for the player. The zoom correlates to the percentage of half the screen size the zoom can reach. A value of -1 passed in means no vanilla scope is in effect. A value of 1.0 means the scope can zoom half a screen width/height away, putting the player on the edge of the game screen. Vanilla values include .8, .6666, and .5. More...
 
virtual void NaturalLifeRegen (ref float regen)
 Allows you to modify the power of the player's natural life regeneration. This can be done by multiplying the regen parameter by any number. For example, campfires multiply it by 1.1, while walking multiplies it by 0.5. More...
 
override ModPlayer NewInstance (Player entity)
 
virtual void OnCatchNPC (NPC npc, Item item, bool failed)
 Allows you to make things happen when the given item attempts to catch the given NPC. More...
 
virtual void OnConsumeAmmo (Item weapon, Item ammo)
 Allows you to make things happen when the given ammo is consumed by the given weapon.
Called before the ammo stack is reduced, and is never called if the ammo isn't consumed in the first place. More...
 
virtual void OnConsumeMana (Item item, int manaConsumed)
 Allows you to make stuff happen when a player consumes mana on use of an item. More...
 
virtual void OnEnterWorld (Player player)
 Called on the LocalPlayer when that player enters the world. SP and Client. Only called on the player who is entering. A possible use is ensuring that UI elements are reset to the configuration specified in data saved to the ModPlayer. Can also be used for informational messages. More...
 
virtual void OnHitAnything (float x, float y, Entity victim)
 This hook is called when a player damages anything, whether it be an NPC or another player, using anything, whether it be a melee weapon or a projectile. The x and y parameters are the coordinates of the victim parameter's center. More...
 
virtual void OnHitByNPC (NPC npc, int damage, bool crit)
 Allows you to create special effects when an NPC hits this player (for example, inflicting debuffs). More...
 
virtual void OnHitByProjectile (Projectile proj, int damage, bool crit)
 Allows you to create special effects when a hostile projectile hits this player. More...
 
virtual void OnHitNPC (Item item, NPC target, int damage, float knockback, bool crit)
 Allows you to create special effects when this player hits an NPC by swinging a melee weapon (for example how the Pumpkin Sword creates pumpkin heads). More...
 
virtual void OnHitNPCWithProj (Projectile proj, NPC target, int damage, float knockback, bool crit)
 Allows you to create special effects when a projectile created by this player hits an NPC (for example, inflicting debuffs). More...
 
virtual void OnHitPvp (Item item, Player target, int damage, bool crit)
 Allows you to create special effects when this player's melee weapon hits an opponent player. More...
 
virtual void OnHitPvpWithProj (Projectile proj, Player target, int damage, bool crit)
 Allows you to create special effects when a projectile created by this player hits an opponent player. More...
 
virtual void OnMissingMana (Item item, int neededMana)
 Allows you to make stuff happen when a player doesn't have enough mana for the item they are trying to use. If the player has high enough mana after this hook runs, mana consumption will happen normally. Only runs once per item use. More...
 
virtual void OnRespawn (Player player)
 Called when a player respawns in the world. More...
 
virtual void PlayerConnect (Player player)
 Called on clients when a player connects. More...
 
virtual void PlayerDisconnect (Player player)
 Called when a player disconnects. More...
 
virtual void PostBuyItem (NPC vendor, Item[] shopInventory, Item item)
 Called whenever the player buys an item from an NPC. More...
 
virtual void PostHurt (bool pvp, bool quiet, double damage, int hitDirection, bool crit)
 
virtual void PostHurt (bool pvp, bool quiet, double damage, int hitDirection, bool crit, int cooldownCounter)
 Allows you to make anything happen when the player takes damage. More...
 
virtual void PostItemCheck ()
 Allows you to do anything after the update code for the player's held item is run. Hooks for the middle of the held item update code have more specific names in ModItem and ModPlayer.
 
virtual void PostNurseHeal (NPC nurse, int health, bool removeDebuffs, int price)
 Called on the Client after the player heals themselves with the Nurse NPC. More...
 
virtual void PostSavePlayer ()
 PreSavePlayer and PostSavePlayer wrap the vanilla player saving code (both are before the ModPlayer.Save). Useful for advanced situations where a save might be corrupted or rendered unusable by the values that normally would save.
 
virtual void PostSellItem (NPC vendor, Item[] shopInventory, Item item)
 Called whenever the player sells an item to an NPC. More...
 
virtual void PostUpdate ()
 This is called at the very end of the Player.Update method. Final general update tasks can be placed here.
 
virtual void PostUpdateBuffs ()
 This is called right after all of this player's buffs update on the player. This can be used to modify the effects that the buff updates had on this player, and can also be used for general update tasks.
 
virtual void PostUpdateEquips ()
 This is called right after all of this player's equipment and armor sets update on the player, which is sometime after PostUpdateBuffs is called. This can be used to modify the effects that the equipment had on this player, and can also be used for general update tasks.
 
virtual void PostUpdateMiscEffects ()
 This is called after miscellaneous update code is called in Player.Update, which is sometime after PostUpdateEquips is called. This can be used for general update tasks.
 
virtual void PostUpdateRunSpeeds ()
 This is called after the player's horizontal speeds are modified, which is sometime after PostUpdateMiscEffects is called, and right before the player's horizontal position is updated. Use this to modify maxRunSpeed, accRunSpeed, runAcceleration, and similar variables before the player moves forwards/backwards.
 
virtual bool PreHurt (bool pvp, bool quiet, ref int damage, ref int hitDirection, ref bool crit, ref bool customDamage, ref bool playSound, ref bool genGore, ref PlayerDeathReason damageSource)
 
virtual bool PreHurt (bool pvp, bool quiet, ref int damage, ref int hitDirection, ref bool crit, ref bool customDamage, ref bool playSound, ref bool genGore, ref PlayerDeathReason damageSource, ref int cooldownCounter)
 This hook is called before every time the player takes damage. The pvp parameter is whether the damage was from another player. The quiet parameter determines whether the damage will be communicated to the server. The damage, hitDirection, and crit parameters can be modified. Set the customDamage parameter to true if you want to use your own damage formula (this parameter will disable automatically subtracting the player's defense from the damage). Set the playSound parameter to false to disable the player's hurt sound, and the genGore parameter to false to disable the dust particles that spawn. (These are useful for creating your own sound or gore.) The deathText parameter can be modified to change the player's death message if the player dies. Return false to stop the player from taking damage. Returns true by default. More...
 
virtual bool PreItemCheck ()
 Allows you to do anything before the update code for the player's held item is run. Return false to stop the held item update code from being run (for example, if the player is frozen). Returns true by default. More...
 
virtual bool PreKill (double damage, int hitDirection, bool pvp, ref bool playSound, ref bool genGore, ref PlayerDeathReason damageSource)
 This hook is called whenever the player is about to be killed after reaching 0 health. Set the playSound parameter to false to stop the death sound from playing. Set the genGore parameter to false to stop the gore and dust from being created. (These are useful for creating your own sound or gore.) Return false to stop the player from being killed. Only return false if you know what you are doing! Returns true by default. More...
 
virtual bool PreModifyLuck (ref float luck)
 Called before vanilla makes any luck calculations. Return false to prevent vanilla from making their luck calculations. Returns true by default. More...
 
virtual void PreSaveCustomData ()
 Currently never gets called, so this is useless.
 
virtual void PreSavePlayer ()
 PreSavePlayer and PostSavePlayer wrap the vanilla player saving code (both are before the ModPlayer.Save). Useful for advanced situations where a save might be corrupted or rendered unusable by the values that normally would save.
 
virtual void PreUpdate ()
 This is called at the beginning of every tick update for this player, after checking whether the player exists.
 
virtual void PreUpdateBuffs ()
 This is called sometime after SetControls is called, and right before all the buffs update on this player. This hook can be used to add buffs to the player based on the player's state (for example, the Campfire buff is added if the player is near a Campfire).
 
virtual void PreUpdateMovement ()
 This is called right before modifying the player's position based on velocity. Use this to make direct changes to the velocity.
 
virtual void ProcessTriggers (TriggersSet triggersSet)
 Use this to check on keybinds you have registered. While SetControls is set even while in text entry mode, this hook is only called during gameplay. More...
 
virtual void ResetEffects ()
 This is where you reset any fields you add to your ModPlayer subclass to their default states. This is necessary in order to reset your fields if they are conditionally set by a tick update but the condition is no longer satisfied.
 
virtual void SaveData (TagCompound tag)
 Allows you to save custom data for this player.

NOTE: The provided tag is always empty by default, and is provided as an argument only for the sake of convenience and optimization.
NOTE: Try to only save data that isn't default values. More...
 
virtual void SendClientChanges (ModPlayer clientPlayer)
 Allows you to sync any information that has changed between the server and client. Here, you should check the information you have copied in the clientClone parameter; if they differ between this player and the clientPlayer parameter, then you should send that information using NetMessage.SendData or ModPacket.Send. More...
 
virtual void SetControls ()
 Use this to modify the control inputs that the player receives. For example, the Confused debuff swaps the values of Player.controlLeft and Player.controlRight. This is called sometime after PreUpdate is called.
 
sealed override void SetupContent ()
 If you make a new ModType, seal this override, and call SetStaticDefaults in it. More...
 
virtual bool ShiftClickSlot (Item[] inventory, int context, int slot)
 Called whenever the player shift-clicks an item slot. This can be used to override default clicking behavior (ie. selling, trashing, moving items). More...
 
virtual bool Shoot (Item item, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
 Allows you to modify an item's shooting mechanism. Return false to prevent vanilla's shooting code from running. Returns true by default. More...
 
virtual void SyncPlayer (int toWho, int fromWho, bool newPlayer)
 Allows you to sync information about this player between server and client. The toWho and fromWho parameters correspond to the remoteClient/toClient and ignoreClient arguments, respectively, of NetMessage.SendData/ModPacket.Send. The newPlayer parameter is whether or not the player is joining the server (it is true on the joining client). More...
 
bool TypeEquals (ModPlayer other)
 
virtual void UpdateAutopause ()
 Allows you to modify the player's stats while the game is paused due to the autopause setting being on. This is called in single player only, some time before the player's tick update would happen when the game isn't paused.
 
virtual void UpdateBadLifeRegen ()
 Allows you to give the player a negative life regeneration based on its state (for example, the "On Fire!" debuff makes the player take damage-over-time). This is typically done by setting Player.lifeRegen to 0 if it is positive, setting Player.lifeRegenTime to 0, and subtracting a number from Player.lifeRegen. The player will take damage at a rate of half the number you subtract per second.
 
virtual void UpdateDead ()
 Similar to UpdateDead, except this is only called when the player is dead. If this is called, then ResetEffects will not be called.
 
virtual void UpdateDyes ()
 Is called in Player.UpdateDyes(), including selection screen. Player Instance sensitive. More...
 
virtual void UpdateEquips ()
 Called after Update Accessories. More...
 
virtual void UpdateLifeRegen ()
 Allows you to increase the player's life regeneration based on its state. This can be done by incrementing Player.lifeRegen by a certain number. The player will recover life at a rate of half the number you add per second. You can also increment Player.lifeRegenTime to increase the speed at which the player reaches its maximum natural life regeneration.
 
virtual void UpdateVisibleAccessories ()
 Is called in Player.Frame() after vanilla functional slots are evaluated, including selection screen to prepare and denote visible accessories. Player Instance sensitive. More...
 
virtual void UpdateVisibleVanityAccessories ()
 Is called in Player.Frame() after vanilla vanity slots are evaluated, including selection screen to prepare and denote visible accessories. Player Instance sensitive. More...
 
virtual float UseAnimationMultiplier (Item item)
 Allows you to change the effective useAnimation of an item.
Note that this hook may cause items' actions to run less or more times than they should per a single use. More...
 
virtual float UseSpeedMultiplier (Item item)
 Allows you to safely change both useTime and useAnimation while keeping the values relative to each other.
Useful for status effects. More...
 
virtual float UseTimeMultiplier (Item item)
 Allows you to change the effective useTime of an item.
Note that this hook may cause items' actions to run less or more times than they should per a single use. More...
 
- Public Member Functions inherited from Terraria.ModLoader.ModType< Player, ModPlayer >
virtual TModType Clone (TEntity newEntity)
 Create a copy of this instanced global. Called when an entity is cloned. More...
 
virtual bool IsLoadingEnabled (Mod mod)
 Allows you to stop Mod.AddContent from actually adding this content. Useful for items that can be disabled by a config. More...
 
virtual void Load ()
 Allows you to perform one-time loading tasks. Beware that mod content has not finished loading here, things like ModContent lookup tables or ID Sets are not fully populated. More...
 
virtual TModType NewInstance (TEntity entity)
 Create a new instance of this ModType for a specific entity More...
 
virtual void SetStaticDefaults ()
 Allows you to modify the properties after initial loading has completed.
 
virtual void SetupContent ()
 If you make a new ModType, seal this override, and call SetStaticDefaults in it. More...
 
virtual void Unload ()
 Allows you to safely unload things you added in Load. More...
 
virtual bool IsLoadingEnabled (Mod mod)
 Whether or not this type should be loaded when it's told to. Returning false disables Mod.AddContent from actually loading this type. More...
 
abstract void Load (Mod mod)
 Called when loading the type. More...
 
abstract void Unload ()
 Called during unloading when needed. More...
 

Protected Member Functions

override Player CreateTemplateEntity ()
 
sealed override void Register ()
 If you make a new ModType, seal this override. More...
 
override void ValidateType ()
 Check for the correct overrides of different hook methods and fields and properties More...
 
- Protected Member Functions inherited from Terraria.ModLoader.ModType< Player, ModPlayer >
abstract TEntity CreateTemplateEntity ()
 
virtual void InitTemplateInstance ()
 Create dummy objects for instanced mod-types
 
override void InitTemplateInstance ()
 Create dummy objects for instanced mod-types
 
abstract void Register ()
 If you make a new ModType, seal this override. More...
 
virtual void ValidateType ()
 Check for the correct overrides of different hook methods and fields and properties More...
 

Properties

ushort Index [get, set]
 
Player Player [get]
 The Player instance that this ModPlayer instance is attached to.
 
- Properties inherited from Terraria.ModLoader.ModType< Player, ModPlayer >
virtual bool CloneNewInstances [get]
 Whether to create new instances of this mod type via Clone(TEntity) or via the default constructor Defaults to false (default constructor).
 
TEntity Entity [get, set]
 
string FullName [get]
 The internal name of this, including the mod it is from. More...
 
virtual bool IsCloneable [get]
 Whether or not this type is cloneable. Cloning is supported if
all reference typed fields in each sub-class which doesn't override Clone are marked with [CloneByReference]
 
Mod Mod [get, set]
 The mod this belongs to. More...
 
virtual string Name [get]
 The internal name of this. More...
 
- Properties inherited from Terraria.ModLoader.IModType
string FullName [get]
 => $"{Mod.Name}/{Name}" More...
 
Mod Mod [get]
 The mod this belongs to. More...
 
string Name [get]
 The internal name of this instance. More...
 
- Properties inherited from Terraria.ModLoader.IIndexed
ushort Index [get]
 

Detailed Description

A ModPlayer instance represents an extension of a Player instance. You can store fields in the ModPlayer classes, much like how the Player class abuses field usage, to keep track of mod-specific information on the player that a ModPlayer instance represents. It also contains hooks to insert your code into the Player class.

Member Function Documentation

◆ AddStartingItems()

virtual IEnumerable< Item > Terraria.ModLoader.ModPlayer.AddStartingItems ( bool  mediumCoreDeath)
virtual

Called when the player is created in the menu. You can use this method to add items to the player's starting inventory, as well as their inventory when they respawn in mediumcore.

Parameters
mediumCoreDeathWhether you are setting up a mediumcore player's inventory after their death.
Returns
An enumerable of the items you want to add. If you want to add nothing, return Enumerable.Empty<Item>().

Reimplemented in Terraria.ModLoader.Default.UnloadedPlayer.

◆ AnglerQuestReward()

virtual void Terraria.ModLoader.ModPlayer.AnglerQuestReward ( float  rareMultiplier,
List< Item rewardItems 
)
virtual

Allows you to add to, change, or remove from the items the player earns when finishing an Angler quest. The rareMultiplier is a number between 0.15 and 1 inclusively; the lower it is the higher chance there should be for the player to earn rare items.

Parameters
rareMultiplier
rewardItems

◆ CanAutoReuseItem()

virtual ? bool Terraria.ModLoader.ModPlayer.CanAutoReuseItem ( Item  item)
virtual

Allows you to modify the autoswing (auto-reuse) behavior of any item without having to mess with Item.autoReuse.
Useful to create effects like the Feral Claws which makes melee weapons and whips auto-reusable.
Return true to enable autoswing (if not already enabled through autoReuse), return false to prevent autoswing. Returns null by default, which applies vanilla behavior.

Parameters
itemThe item.

◆ CanBeHitByNPC()

virtual bool Terraria.ModLoader.ModPlayer.CanBeHitByNPC ( NPC  npc,
ref int  cooldownSlot 
)
virtual

Allows you to determine whether the given NPC can hit this player. Return false to block this player from being hit by the NPC. Returns true by default. CooldownSlot determines which of the player's cooldown counters to use (-1, 0, or 1), and defaults to -1.

Parameters
npc
cooldownSlot
Returns

◆ CanBeHitByProjectile()

virtual bool Terraria.ModLoader.ModPlayer.CanBeHitByProjectile ( Projectile  proj)
virtual

Allows you to determine whether the given hostile projectile can hit this player. Return false to block this player from being hit. Returns true by default.

Parameters
proj
Returns

◆ CanBuyItem()

virtual bool Terraria.ModLoader.ModPlayer.CanBuyItem ( NPC  vendor,
Item[]  shopInventory,
Item  item 
)
virtual

Return false to prevent a transaction. Called before the transaction.

Parameters
vendorThe NPC vendor.
shopInventoryThe current inventory of the NPC shop.
itemThe item the player is attempting to buy.
Returns

◆ CanCatchNPC()

virtual ? bool Terraria.ModLoader.ModPlayer.CanCatchNPC ( NPC  target,
Item  item 
)
virtual

Allows you to determine whether the given item can catch the given NPC.
Return true or false to say the target can or cannot be caught, respectively, regardless of vanilla rules.
Returns null by default, which allows vanilla's NPC catching rules to decide the target's fate.
If this returns false, CombinedHooks.OnCatchNPC is never called.

NOTE: this does not classify the given item as a catch tool, which is necessary for catching NPCs in the first place.
To do that, you will need to use the "CatchingTool" set in ItemID.Sets.

Parameters
targetThe NPC the player is trying to catch.
itemThe item with which the player is trying to catch the target NPC.

◆ CanConsumeAmmo()

virtual bool Terraria.ModLoader.ModPlayer.CanConsumeAmmo ( Item  weapon,
Item  ammo 
)
virtual

Whether or not the given ammo item will be consumed by this weapon.
By default, returns true; return false to prevent ammo consumption.
If false is returned, the OnConsumeAmmo hook is never called.

Parameters
weaponThe weapon that this player is attempting to use.
ammoThe ammo that the give nweapon is attempting to consume.
Returns

◆ CanConsumeBait()

virtual ? bool Terraria.ModLoader.ModPlayer.CanConsumeBait ( Item  bait)
virtual

Choose if this bait will be consumed or not when used for fishing. return null for vanilla behaviour. Not consuming will always take priority over forced consumption

Parameters
baitThe item (bait) that would be consumed

◆ CanHitNPC()

virtual ? bool Terraria.ModLoader.ModPlayer.CanHitNPC ( Item  item,
NPC  target 
)
virtual

Allows you to determine whether a player can hit the given NPC by swinging a melee weapon. Return true to allow hitting the target, return false to block this player from hitting the target, and return null to use the vanilla code for whether the target can be hit. Returns null by default.

Parameters
item
target
Returns

◆ CanHitNPCWithProj()

virtual ? bool Terraria.ModLoader.ModPlayer.CanHitNPCWithProj ( Projectile  proj,
NPC  target 
)
virtual

Allows you to determine whether a projectile created by this player can hit the given NPC. Return true to allow hitting the target, return false to block this projectile from hitting the target, and return null to use the vanilla code for whether the target can be hit. Returns null by default.

Parameters
proj
target
Returns

◆ CanHitPvp()

virtual bool Terraria.ModLoader.ModPlayer.CanHitPvp ( Item  item,
Player  target 
)
virtual

Allows you to determine whether a melee weapon swung by this player can hit the given opponent player. Return false to block this weapon from hitting the target. Returns true by default.

Parameters
item
target
Returns

◆ CanHitPvpWithProj()

virtual bool Terraria.ModLoader.ModPlayer.CanHitPvpWithProj ( Projectile  proj,
Player  target 
)
virtual

Allows you to determine whether a projectile created by this player can hit the given opponent player. Return false to block the projectile from hitting the target. Returns true by default.

Parameters
proj
target
Returns

◆ CanSellItem()

virtual bool Terraria.ModLoader.ModPlayer.CanSellItem ( NPC  vendor,
Item[]  shopInventory,
Item  item 
)
virtual

Return false to prevent a transaction. Called before the transaction.

Parameters
vendorThe NPC vendor.
shopInventoryThe current inventory of the NPC shop.
itemThe item the player is attempting to sell.
Returns

◆ CanShoot()

virtual bool Terraria.ModLoader.ModPlayer.CanShoot ( Item  item)
virtual

Allows you to prevent an item from shooting a projectile on use. Returns true by default.

Parameters
itemThe item being used.
Returns

◆ CanUseItem()

virtual bool Terraria.ModLoader.ModPlayer.CanUseItem ( Item  item)
virtual

Return false to prevent an item from being used. By default returns true.

Parameters
itemThe item the player is attempting to use.

◆ CatchFish()

virtual void Terraria.ModLoader.ModPlayer.CatchFish ( FishingAttempt  attempt,
ref int  itemDrop,
ref int  npcSpawn,
ref AdvancedPopupRequest  sonar,
ref Vector2  sonarPosition 
)
virtual

Allows you to change the item or enemy the player gets when sucessfully catching an item or NPC. The Fishing Attempt structure contains most information about the vanilla event, including the Item Rod and Bait used by the player, the liquid it is being fished on, and so on. The Sonar and Sonar position fields allow you to change the text, color, velocity and position of the catch's name (be it item or NPC) freely

Parameters
attemptThe structure containing most data from the vanilla fishing attempt
itemDropThe item that will be created when this fishing attempt succeeds. leave <0 for no item
npcSpawnThe enemy that will be spawned if there is no item caught. leave <0 for no NPC spawn
sonarFill all of this structure's fields to override the sonar text, or make sonar.Text null to disable custom sonar
sonarPositionThe position the Sonar text will spawn. Bobber location by default.

◆ clientClone()

virtual void Terraria.ModLoader.ModPlayer.clientClone ( ModPlayer  clientClone)
virtual

Allows you to copy information about this player to the clientClone parameter. You should copy information that you intend to sync between server and client. This hook is called in the Player.clientClone method. See SendClientChanges for more info.

Parameters
clientClone

Reimplemented in Terraria.ModLoader.Default.ModAccessorySlotPlayer.

◆ CreateTemplateEntity()

override Player Terraria.ModLoader.ModPlayer.CreateTemplateEntity ( )
protectedvirtual

◆ DrawEffects()

virtual void Terraria.ModLoader.ModPlayer.DrawEffects ( PlayerDrawSet  drawInfo,
ref float  r,
ref float  g,
ref float  b,
ref float  a,
ref bool  fullBright 
)
virtual

Allows you to create special effects when this player is drawn, such as creating dust, modifying the color the player is drawn in, etc. The fullBright parameter makes it so that the drawn player ignores the modified color and lighting. Note that the fullBright parameter only works if r, g, b, and/or a is not equal to 1. Make sure to add the indexes of any dusts you create to drawInfo.DustCache, and the indexes of any gore you create to drawInfo.GoreCache.
This will be called multiple times a frame if a player afterimage is being drawn. Check

if(drawinfo.shadow == 0f) to do some logic only when drawing the original player image. For example, spawning dust only for the original player image is commonly the desired behavior.

Parameters
drawInfo
r
g
b
a
fullBright

◆ GetDyeTraderReward()

virtual void Terraria.ModLoader.ModPlayer.GetDyeTraderReward ( List< int >  rewardPool)
virtual

Allows you to modify what items are possible for the player to earn when giving a Strange Plant to the Dye Trader.

Parameters
rewardPool

◆ GetFishingLevel()

virtual void Terraria.ModLoader.ModPlayer.GetFishingLevel ( Item  fishingRod,
Item  bait,
ref float  fishingLevel 
)
virtual

Allows you to modify the player's fishing power. As an example of the type of stuff that should go here, the phase of the moon can influence fishing power.

Parameters
fishingRod
bait
fishingLevel

◆ GetHealLife()

virtual void Terraria.ModLoader.ModPlayer.GetHealLife ( Item  item,
bool  quickHeal,
ref int  healValue 
)
virtual

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.

Parameters
itemThe item.
quickHealWhether the item is being used through quick heal or not.
healValueThe amount of life being healed.

◆ GetHealMana()

virtual void Terraria.ModLoader.ModPlayer.GetHealMana ( Item  item,
bool  quickHeal,
ref int  healValue 
)
virtual

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.

Parameters
itemThe item.
quickHealWhether the item is being used through quick heal or not.
healValueThe amount of mana being healed.

◆ HideDrawLayers()

virtual void Terraria.ModLoader.ModPlayer.HideDrawLayers ( PlayerDrawSet  drawInfo)
virtual

Allows you to modify the visibility of layers about to be drawn

Parameters
drawInfo

◆ HoverSlot()

virtual bool Terraria.ModLoader.ModPlayer.HoverSlot ( Item[]  inventory,
int  context,
int  slot 
)
virtual

Called whenever the player hovers over an item slot. This can be used to override Main.cursorOverride
See ID.CursorOverrideID for cursor override style IDs

Parameters
inventoryThe array of items the slot is part of.
contextThe Terraria.UI.ItemSlot.Context of the inventory.
slotThe index in the inventory of the hover slot.
Returns
Whether or not to block the default code that modifies Main.cursorOverride from running. Returns false by default.

◆ Hurt()

virtual void Terraria.ModLoader.ModPlayer.Hurt ( bool  pvp,
bool  quiet,
double  damage,
int  hitDirection,
bool  crit,
int  cooldownCounter 
)
virtual

Allows you to make anything happen right before damage is subtracted from the player's health.

Parameters
pvp
quiet
damage
hitDirection
crit
cooldownCounter

◆ Initialize()

virtual void Terraria.ModLoader.ModPlayer.Initialize ( )
virtual

Called whenever the player is loaded (on the player selection screen). This can be used to initialize data structures, etc.

Reimplemented in Terraria.ModLoader.Default.UnloadedPlayer.

◆ Kill()

virtual void Terraria.ModLoader.ModPlayer.Kill ( double  damage,
int  hitDirection,
bool  pvp,
PlayerDeathReason  damageSource 
)
virtual

Allows you to make anything happen when the player dies.

Parameters
damage
hitDirection
pvp
damageSource

◆ LoadData()

virtual void Terraria.ModLoader.ModPlayer.LoadData ( TagCompound  tag)
virtual

Allows you to load custom data that you have saved for this player.
Try to write defensive loading code that won't crash if something's missing.

Parameters
tagThe TagCompound to load data from.

Reimplemented in Terraria.ModLoader.Default.ModAccessorySlotPlayer, and Terraria.ModLoader.Default.UnloadedPlayer.

◆ MeleeEffects()

virtual void Terraria.ModLoader.ModPlayer.MeleeEffects ( Item  item,
Rectangle  hitbox 
)
virtual

Allows you to give this player's melee weapon special effects, such as creating light or dust.

Parameters
item
hitbox

◆ ModifyCaughtFish()

virtual void Terraria.ModLoader.ModPlayer.ModifyCaughtFish ( Item  fish)
virtual

Allows you to modify the item caught by the fishing player, including stack

Parameters
fishThe item (Fish) to modify

◆ ModifyDrawInfo()

virtual void Terraria.ModLoader.ModPlayer.ModifyDrawInfo ( ref PlayerDrawSet  drawInfo)
virtual

Allows you to modify the drawing parameters of the player before drawing begins.

Parameters
drawInfo

◆ ModifyDrawLayerOrdering()

virtual void Terraria.ModLoader.ModPlayer.ModifyDrawLayerOrdering ( IDictionary< PlayerDrawLayer, PlayerDrawLayer.Position positions)
virtual

Allows you to reorder the player draw layers. This is called once at the end of mod loading, not during the game. Use with extreme caution, or risk breaking other mods.

Parameters
positionsAdd/remove/change the positions applied to each layer here

◆ ModifyFishingAttempt()

virtual void Terraria.ModLoader.ModPlayer.ModifyFishingAttempt ( ref FishingAttempt  attempt)
virtual

Allows you to change information about the ongoing fishing attempt before cought items/NPCs are decided, after all vanilla information has been gathered.
Will not be called if various conditions for getting a catch aren't met, meaning you can't modify those.
Setting FishingAttempt.rolledItemDrop or FishingAttempt.rolledEnemySpawn is not allowed and will be reset, use CatchFish for that.

Parameters
attemptThe structure containing most data from the vanilla fishing attempt

◆ ModifyHitByNPC()

virtual void Terraria.ModLoader.ModPlayer.ModifyHitByNPC ( NPC  npc,
ref int  damage,
ref bool  crit 
)
virtual

Allows you to modify the damage, etc., that an NPC does to this player.

Parameters
npc
damage
crit

◆ ModifyHitByProjectile()

virtual void Terraria.ModLoader.ModPlayer.ModifyHitByProjectile ( Projectile  proj,
ref int  damage,
ref bool  crit 
)
virtual

Allows you to modify the damage, etc., that a hostile projectile does to this player.

Parameters
proj
damage
crit

◆ ModifyHitNPC()

virtual void Terraria.ModLoader.ModPlayer.ModifyHitNPC ( Item  item,
NPC  target,
ref int  damage,
ref float  knockback,
ref bool  crit 
)
virtual

Allows you to modify the damage, knockback, etc., that this player does to an NPC by swinging a melee weapon.

Parameters
item
target
damage
knockback
crit

◆ ModifyHitNPCWithProj()

virtual void Terraria.ModLoader.ModPlayer.ModifyHitNPCWithProj ( Projectile  proj,
NPC  target,
ref int  damage,
ref float  knockback,
ref bool  crit,
ref int  hitDirection 
)
virtual

Allows you to modify the damage, knockback, etc., that a projectile created by this player does to an NPC.

Parameters
proj
target
damage
knockback
crit
hitDirection

◆ ModifyHitPvp()

virtual void Terraria.ModLoader.ModPlayer.ModifyHitPvp ( Item  item,
Player  target,
ref int  damage,
ref bool  crit 
)
virtual

Allows you to modify the damage, etc., that a melee weapon swung by this player does to an opponent player.

Parameters
item
target
damage
crit

◆ ModifyHitPvpWithProj()

virtual void Terraria.ModLoader.ModPlayer.ModifyHitPvpWithProj ( Projectile  proj,
Player  target,
ref int  damage,
ref bool  crit 
)
virtual

Allows you to modify the damage, etc., that a projectile created by this player does to an opponent player.

Parameters
proj
target
damage
crit

◆ ModifyItemScale()

virtual void Terraria.ModLoader.ModPlayer.ModifyItemScale ( Item  item,
ref float  scale 
)
virtual

Allows you to dynamically modify the given item's size for this player, similarly to the effect of the Titan Glove.

Parameters
itemThe item to modify the scale of.
scaleThe scale multiplier to be applied to the given item.
Will be 1.1 if the Titan Glove is equipped, and 1 otherwise.

◆ ModifyLuck()

virtual void Terraria.ModLoader.ModPlayer.ModifyLuck ( ref float  luck)
virtual

Allows you to modify a player's luck amount.

Parameters
luck

◆ ModifyManaCost()

virtual void Terraria.ModLoader.ModPlayer.ModifyManaCost ( Item  item,
ref float  reduce,
ref float  mult 
)
virtual

Allows you to temporarily modify the amount of mana an item will consume on use, based on player buffs, accessories, etc. This is only called for items with a mana value.

Parameters
itemThe item being used.
reduceUsed for decreasingly stacking buffs (most common). Only ever use -= on this field.
multUse to directly multiply the item's effective mana cost. Good for debuffs, or things which should stack separately (eg meteor armor set bonus).

◆ ModifyMaxStats()

virtual void Terraria.ModLoader.ModPlayer.ModifyMaxStats ( out StatModifier  health,
out StatModifier  mana 
)
virtual

Allows you to modify the player's max stats. This hook runs after vanilla increases from the Life Crystal, Life Fruit and Mana Crystal are applied
NOTE: You should NOT modify Player.statLifeMax nor Player.statManaMax here. Use the health and mana parameters.

Parameters
healthThe modifier to the player's maximum health
manaThe modifier to the player's maximum mana

◆ ModifyNurseHeal()

virtual bool Terraria.ModLoader.ModPlayer.ModifyNurseHeal ( NPC  nurse,
ref int  health,
ref bool  removeDebuffs,
ref string  chatText 
)
virtual

Called on the Client while the nurse chat is displayed. Return false to prevent the player from healing. If you return false, you need to set chatText so the user knows why they can't heal.

Parameters
nurseThe Nurse NPC instance.
healthHow much health the player gains.
removeDebuffsIf set to false, debuffs will not be healed.
chatTextSet this to the Nurse chat text that will display if healing is prevented.
Returns
True by default. False to prevent nurse services.

◆ ModifyNursePrice()

virtual void Terraria.ModLoader.ModPlayer.ModifyNursePrice ( NPC  nurse,
int  health,
bool  removeDebuffs,
ref int  price 
)
virtual

Called on the Client while the nurse chat is displayed and after ModifyNurseHeal. Allows custom pricing for Nurse services. See https://terraria.gamepedia.com/Nurse for the default pricing.

Parameters
nurseThe Nurse NPC instance.
healthHow much health the player gains.
removeDebuffsWhether or not debuffs will be healed.
price

◆ ModifyShootStats()

virtual void Terraria.ModLoader.ModPlayer.ModifyShootStats ( Item  item,
ref Vector2  position,
ref Vector2  velocity,
ref int  type,
ref int  damage,
ref float  knockback 
)
virtual

Allows you to modify the position, velocity, type, damage and/or knockback of a projectile being shot by an item.

Parameters
itemThe item being used.
positionThe center position of the projectile.
velocityThe velocity of the projectile.
typeThe ID of the projectile.
damageThe damage of the projectile.
knockbackThe knockback of the projectile.

◆ ModifyStartingInventory()

virtual void Terraria.ModLoader.ModPlayer.ModifyStartingInventory ( IReadOnlyDictionary< string, List< Item > >  itemsByMod,
bool  mediumCoreDeath 
)
virtual

Allows you to modify the items that will be added to the player's inventory. Useful if you want to stop vanilla or other mods from adding an item. You can access a mod's items by using the mod's internal name as the indexer, such as: additions["ModName"]. To access vanilla items you can use "Terraria" as the index.

Parameters
itemsByModThe items that will be added. Each key is the internal mod name of the mod adding the items. Vanilla items use the "Terraria" key.
mediumCoreDeathWhether you are setting up a mediumcore player's inventory after their death.

◆ ModifyWeaponCrit()

virtual void Terraria.ModLoader.ModPlayer.ModifyWeaponCrit ( Item  item,
ref float  crit 
)
virtual

Allows you to dynamically modify a weapon's crit chance based on player and item conditions. Can be utilized to modify damage beyond the tools that DamageClass has to offer.

Parameters
itemThe item.
critThe total crit chance of the item after all normal crit chance calculations.

◆ ModifyWeaponDamage()

virtual void Terraria.ModLoader.ModPlayer.ModifyWeaponDamage ( Item  item,
ref StatModifier  damage 
)
virtual

Allows you to dynamically modify a weapon's damage based on player and item conditions. Can be utilized to modify damage beyond the tools that DamageClass has to offer.

Parameters
itemThe item being used.
damageThe StatModifier object representing the totality of the various modifiers to be applied to the item's base damage.

◆ ModifyWeaponKnockback()

virtual void Terraria.ModLoader.ModPlayer.ModifyWeaponKnockback ( Item  item,
ref StatModifier  knockback 
)
virtual

Allows you to dynamically modify a weapon's knockback based on player and item conditions. Can be utilized to modify damage beyond the tools that DamageClass has to offer.

Parameters
itemThe item being used.
knockbackThe StatModifier object representing the totality of the various modifiers to be applied to the item's base knockback.

◆ ModifyZoom()

virtual void Terraria.ModLoader.ModPlayer.ModifyZoom ( ref float  zoom)
virtual

Use this to modify the zoom factor for the player. The zoom correlates to the percentage of half the screen size the zoom can reach. A value of -1 passed in means no vanilla scope is in effect. A value of 1.0 means the scope can zoom half a screen width/height away, putting the player on the edge of the game screen. Vanilla values include .8, .6666, and .5.

Parameters
zoom

◆ NaturalLifeRegen()

virtual void Terraria.ModLoader.ModPlayer.NaturalLifeRegen ( ref float  regen)
virtual

Allows you to modify the power of the player's natural life regeneration. This can be done by multiplying the regen parameter by any number. For example, campfires multiply it by 1.1, while walking multiplies it by 0.5.

Parameters
regen

◆ OnCatchNPC()

virtual void Terraria.ModLoader.ModPlayer.OnCatchNPC ( NPC  npc,
Item  item,
bool  failed 
)
virtual

Allows you to make things happen when the given item attempts to catch the given NPC.

Parameters
npcThe NPC which the player attempted to catch.
itemThe item used to catch the given NPC.
failedWhether or not the given NPC has been successfully caught.

◆ OnConsumeAmmo()

virtual void Terraria.ModLoader.ModPlayer.OnConsumeAmmo ( Item  weapon,
Item  ammo 
)
virtual

Allows you to make things happen when the given ammo is consumed by the given weapon.
Called before the ammo stack is reduced, and is never called if the ammo isn't consumed in the first place.

Parameters
weaponThe weapon that is currently using the given ammo.
ammoThe ammo that the given weapon is currently using.

◆ OnConsumeMana()

virtual void Terraria.ModLoader.ModPlayer.OnConsumeMana ( Item  item,
int  manaConsumed 
)
virtual

Allows you to make stuff happen when a player consumes mana on use of an item.

Parameters
itemThe item being used.
manaConsumedThe mana consumed from the player.

◆ OnEnterWorld()

virtual void Terraria.ModLoader.ModPlayer.OnEnterWorld ( Player  player)
virtual

Called on the LocalPlayer when that player enters the world. SP and Client. Only called on the player who is entering. A possible use is ensuring that UI elements are reset to the configuration specified in data saved to the ModPlayer. Can also be used for informational messages.

Parameters
playerThe player that entered the world.

◆ OnHitAnything()

virtual void Terraria.ModLoader.ModPlayer.OnHitAnything ( float  x,
float  y,
Entity  victim 
)
virtual

This hook is called when a player damages anything, whether it be an NPC or another player, using anything, whether it be a melee weapon or a projectile. The x and y parameters are the coordinates of the victim parameter's center.

Parameters
x
y
victim

◆ OnHitByNPC()

virtual void Terraria.ModLoader.ModPlayer.OnHitByNPC ( NPC  npc,
int  damage,
bool  crit 
)
virtual

Allows you to create special effects when an NPC hits this player (for example, inflicting debuffs).

Parameters
npc
damage
crit

◆ OnHitByProjectile()

virtual void Terraria.ModLoader.ModPlayer.OnHitByProjectile ( Projectile  proj,
int  damage,
bool  crit 
)
virtual

Allows you to create special effects when a hostile projectile hits this player.

Parameters
proj
damage
crit

◆ OnHitNPC()

virtual void Terraria.ModLoader.ModPlayer.OnHitNPC ( Item  item,
NPC  target,
int  damage,
float  knockback,
bool  crit 
)
virtual

Allows you to create special effects when this player hits an NPC by swinging a melee weapon (for example how the Pumpkin Sword creates pumpkin heads).

Parameters
item
target
damage
knockback
crit

◆ OnHitNPCWithProj()

virtual void Terraria.ModLoader.ModPlayer.OnHitNPCWithProj ( Projectile  proj,
NPC  target,
int  damage,
float  knockback,
bool  crit 
)
virtual

Allows you to create special effects when a projectile created by this player hits an NPC (for example, inflicting debuffs).

Parameters
proj
target
damage
knockback
crit

◆ OnHitPvp()

virtual void Terraria.ModLoader.ModPlayer.OnHitPvp ( Item  item,
Player  target,
int  damage,
bool  crit 
)
virtual

Allows you to create special effects when this player's melee weapon hits an opponent player.

Parameters
item
target
damage
crit

◆ OnHitPvpWithProj()

virtual void Terraria.ModLoader.ModPlayer.OnHitPvpWithProj ( Projectile  proj,
Player  target,
int  damage,
bool  crit 
)
virtual

Allows you to create special effects when a projectile created by this player hits an opponent player.

Parameters
proj
target
damage
crit

◆ OnMissingMana()

virtual void Terraria.ModLoader.ModPlayer.OnMissingMana ( Item  item,
int  neededMana 
)
virtual

Allows you to make stuff happen when a player doesn't have enough mana for the item they are trying to use. If the player has high enough mana after this hook runs, mana consumption will happen normally. Only runs once per item use.

Parameters
itemThe item being used.
neededManaThe mana needed to use the item.

◆ OnRespawn()

virtual void Terraria.ModLoader.ModPlayer.OnRespawn ( Player  player)
virtual

Called when a player respawns in the world.

Parameters
playerThe player that respawns

◆ PlayerConnect()

virtual void Terraria.ModLoader.ModPlayer.PlayerConnect ( Player  player)
virtual

Called on clients when a player connects.

Parameters
playerThe player that connected.

◆ PlayerDisconnect()

virtual void Terraria.ModLoader.ModPlayer.PlayerDisconnect ( Player  player)
virtual

Called when a player disconnects.

Parameters
playerThe player that disconnected.

◆ PostBuyItem()

virtual void Terraria.ModLoader.ModPlayer.PostBuyItem ( NPC  vendor,
Item[]  shopInventory,
Item  item 
)
virtual

Called whenever the player buys an item from an NPC.

Parameters
vendorThe NPC vendor.
shopInventoryThe current inventory of the NPC shop.
itemThe item the player just purchased.

◆ PostHurt()

virtual void Terraria.ModLoader.ModPlayer.PostHurt ( bool  pvp,
bool  quiet,
double  damage,
int  hitDirection,
bool  crit,
int  cooldownCounter 
)
virtual

Allows you to make anything happen when the player takes damage.

Parameters
pvp
quiet
damage
hitDirection
crit
cooldownCounter

◆ PostNurseHeal()

virtual void Terraria.ModLoader.ModPlayer.PostNurseHeal ( NPC  nurse,
int  health,
bool  removeDebuffs,
int  price 
)
virtual

Called on the Client after the player heals themselves with the Nurse NPC.

Parameters
nurseThe Nurse npc providing the heal.
healthHow much health the player gained.

///

Parameters
removeDebuffsWhether or not debuffs were healed.
priceThe price the player paid in copper coins.

◆ PostSellItem()

virtual void Terraria.ModLoader.ModPlayer.PostSellItem ( NPC  vendor,
Item[]  shopInventory,
Item  item 
)
virtual

Called whenever the player sells an item to an NPC.

Parameters
vendorThe NPC vendor.
shopInventoryThe current inventory of the NPC shop.
itemThe item the player just sold.

◆ PreHurt()

virtual bool Terraria.ModLoader.ModPlayer.PreHurt ( bool  pvp,
bool  quiet,
ref int  damage,
ref int  hitDirection,
ref bool  crit,
ref bool  customDamage,
ref bool  playSound,
ref bool  genGore,
ref PlayerDeathReason  damageSource,
ref int  cooldownCounter 
)
virtual

This hook is called before every time the player takes damage. The pvp parameter is whether the damage was from another player. The quiet parameter determines whether the damage will be communicated to the server. The damage, hitDirection, and crit parameters can be modified. Set the customDamage parameter to true if you want to use your own damage formula (this parameter will disable automatically subtracting the player's defense from the damage). Set the playSound parameter to false to disable the player's hurt sound, and the genGore parameter to false to disable the dust particles that spawn. (These are useful for creating your own sound or gore.) The deathText parameter can be modified to change the player's death message if the player dies. Return false to stop the player from taking damage. Returns true by default.

Parameters
pvp
quiet
damage
hitDirection
crit
customDamage
playSound
genGore
damageSource
cooldownCounter
Returns

◆ PreItemCheck()

virtual bool Terraria.ModLoader.ModPlayer.PreItemCheck ( )
virtual

Allows you to do anything before the update code for the player's held item is run. Return false to stop the held item update code from being run (for example, if the player is frozen). Returns true by default.

Returns

◆ PreKill()

virtual bool Terraria.ModLoader.ModPlayer.PreKill ( double  damage,
int  hitDirection,
bool  pvp,
ref bool  playSound,
ref bool  genGore,
ref PlayerDeathReason  damageSource 
)
virtual

This hook is called whenever the player is about to be killed after reaching 0 health. Set the playSound parameter to false to stop the death sound from playing. Set the genGore parameter to false to stop the gore and dust from being created. (These are useful for creating your own sound or gore.) Return false to stop the player from being killed. Only return false if you know what you are doing! Returns true by default.

Parameters
damage
hitDirection
pvp
playSound
genGore
damageSource
Returns

◆ PreModifyLuck()

virtual bool Terraria.ModLoader.ModPlayer.PreModifyLuck ( ref float  luck)
virtual

Called before vanilla makes any luck calculations. Return false to prevent vanilla from making their luck calculations. Returns true by default.

Parameters
luck

◆ ProcessTriggers()

virtual void Terraria.ModLoader.ModPlayer.ProcessTriggers ( TriggersSet  triggersSet)
virtual

Use this to check on keybinds you have registered. While SetControls is set even while in text entry mode, this hook is only called during gameplay.

Parameters
triggersSet

◆ Register()

sealed override void Terraria.ModLoader.ModPlayer.Register ( )
protectedvirtual

If you make a new ModType, seal this override.

Implements Terraria.ModLoader.ModType< Player, ModPlayer >.

◆ SaveData()

virtual void Terraria.ModLoader.ModPlayer.SaveData ( TagCompound  tag)
virtual

Allows you to save custom data for this player.

NOTE: The provided tag is always empty by default, and is provided as an argument only for the sake of convenience and optimization.
NOTE: Try to only save data that isn't default values.

Parameters
tagThe TagCompound to save data into. Note that this is always empty by default, and is provided as an argument only for the sake of convenience and optimization.

Reimplemented in Terraria.ModLoader.Default.ModAccessorySlotPlayer, and Terraria.ModLoader.Default.UnloadedPlayer.

◆ SendClientChanges()

virtual void Terraria.ModLoader.ModPlayer.SendClientChanges ( ModPlayer  clientPlayer)
virtual

Allows you to sync any information that has changed between the server and client. Here, you should check the information you have copied in the clientClone parameter; if they differ between this player and the clientPlayer parameter, then you should send that information using NetMessage.SendData or ModPacket.Send.

Parameters
clientPlayer

Reimplemented in Terraria.ModLoader.Default.ModAccessorySlotPlayer.

◆ SetupContent()

sealed override void Terraria.ModLoader.ModPlayer.SetupContent ( )
virtual

If you make a new ModType, seal this override, and call SetStaticDefaults in it.

Reimplemented from Terraria.ModLoader.ModType< Player, ModPlayer >.

◆ ShiftClickSlot()

virtual bool Terraria.ModLoader.ModPlayer.ShiftClickSlot ( Item[]  inventory,
int  context,
int  slot 
)
virtual

Called whenever the player shift-clicks an item slot. This can be used to override default clicking behavior (ie. selling, trashing, moving items).

Parameters
inventoryThe array of items the slot is part of.
contextThe Terraria.UI.ItemSlot.Context of the inventory.
slotThe index in the inventory of the clicked slot.
Returns
Whether or not to block the default code (sell, trash, move, etc) from running. Returns false by default.

◆ Shoot()

virtual bool Terraria.ModLoader.ModPlayer.Shoot ( Item  item,
EntitySource_ItemUse_WithAmmo  source,
Vector2  position,
Vector2  velocity,
int  type,
int  damage,
float  knockback 
)
virtual

Allows you to modify an item's shooting mechanism. Return false to prevent vanilla's shooting code from running. Returns true by default.

Parameters
itemThe item being used.
sourceThe projectile source's information.
positionThe center position of the projectile.
velocityThe velocity of the projectile.
typeThe ID of the projectile.
damageThe damage of the projectile.
knockbackThe knockback of the projectile.

◆ SyncPlayer()

virtual void Terraria.ModLoader.ModPlayer.SyncPlayer ( int  toWho,
int  fromWho,
bool  newPlayer 
)
virtual

Allows you to sync information about this player between server and client. The toWho and fromWho parameters correspond to the remoteClient/toClient and ignoreClient arguments, respectively, of NetMessage.SendData/ModPacket.Send. The newPlayer parameter is whether or not the player is joining the server (it is true on the joining client).

Parameters
toWho
fromWho
newPlayer

Reimplemented in Terraria.ModLoader.Default.ModAccessorySlotPlayer.

◆ UpdateDyes()

virtual void Terraria.ModLoader.ModPlayer.UpdateDyes ( )
virtual

Is called in Player.UpdateDyes(), including selection screen. Player Instance sensitive.

Reimplemented in Terraria.ModLoader.Default.ModAccessorySlotPlayer.

◆ UpdateEquips()

virtual void Terraria.ModLoader.ModPlayer.UpdateEquips ( )
virtual

Called after Update Accessories.

Reimplemented in Terraria.ModLoader.Default.ModAccessorySlotPlayer.

◆ UpdateVisibleAccessories()

virtual void Terraria.ModLoader.ModPlayer.UpdateVisibleAccessories ( )
virtual

Is called in Player.Frame() after vanilla functional slots are evaluated, including selection screen to prepare and denote visible accessories. Player Instance sensitive.

Reimplemented in Terraria.ModLoader.Default.ModAccessorySlotPlayer.

◆ UpdateVisibleVanityAccessories()

virtual void Terraria.ModLoader.ModPlayer.UpdateVisibleVanityAccessories ( )
virtual

Is called in Player.Frame() after vanilla vanity slots are evaluated, including selection screen to prepare and denote visible accessories. Player Instance sensitive.

Reimplemented in Terraria.ModLoader.Default.ModAccessorySlotPlayer.

◆ UseAnimationMultiplier()

virtual float Terraria.ModLoader.ModPlayer.UseAnimationMultiplier ( Item  item)
virtual

Allows you to change the effective useAnimation of an item.
Note that this hook may cause items' actions to run less or more times than they should per a single use.

Returns
The multiplier on the animation time. 1f by default. Values greater than 1 increase the item animation's length.

◆ UseSpeedMultiplier()

virtual float Terraria.ModLoader.ModPlayer.UseSpeedMultiplier ( Item  item)
virtual

Allows you to safely change both useTime and useAnimation while keeping the values relative to each other.
Useful for status effects.

Returns
The multiplier on the use speed. 1f by default. Values greater than 1 increase the overall item speed.

◆ UseTimeMultiplier()

virtual float Terraria.ModLoader.ModPlayer.UseTimeMultiplier ( Item  item)
virtual

Allows you to change the effective useTime of an item.
Note that this hook may cause items' actions to run less or more times than they should per a single use.

Returns
The multiplier on the usage time. 1f by default. Values greater than 1 increase the item use's length.

◆ ValidateType()

override void Terraria.ModLoader.ModPlayer.ValidateType ( )
protectedvirtual

Check for the correct overrides of different hook methods and fields and properties

Reimplemented from Terraria.ModLoader.ModType< Player, ModPlayer >.

Property Documentation

◆ Index

ushort Terraria.ModLoader.ModPlayer.Index
getset