tModLoader v2024.10
A mod to make and play Terraria mods
ModPlayer Class Reference

A ModPlayer instance represents an extension of a Player instance.
To use it, simply create a new class deriving from this one. Implementations will be registered automatically.
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 ModType< Player, ModPlayer >, and IIndexed.

Inherited by ConsumedStatIncreasesPlayer, GuildpackSetEffectPlayer, JofairdenArmorEffectPlayer, ModAccessorySlotPlayer, OrianSetEffectPlayer, SaetharSetEffectPlayer, Terraria.ModLoader.Default.Patreon.FrostyPlayer, Terraria.ModLoader.Default.Patreon.HER0zeroPlayer, Terraria.ModLoader.Default.Patreon.xAqultPlayer, and UnloadedPlayer.

Public Member Functions

virtual IEnumerable< ItemAddMaterialsForCrafting (out ItemConsumedCallback itemConsumedCallback)
 Called when Recipe.FindRecipes is called or the player is crafting an item You can use this method to add items as the materials that may be used for crafting items More...
 
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 void ArmorSetBonusActivated ()
 This is called when the player activates their armor set bonus by double tapping down (or up if Main.ReversedUpDownArmorSetBonuses is true). As an example, the Vortex armor uses this to toggle stealth mode. More...
 
virtual void ArmorSetBonusHeld (int holdTime)
 This is called when the player activates their armor set bonus by holding down (or up if Main.ReversedUpDownArmorSetBonuses is true) for some amount of time. The holdTime parameter indicates how many ticks the key has been held down for. As an example, the Stardust armor prior to 1.4.4 used to use this to set the location of the Stardust Guardian if holdTime was greater than 60. 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 (ImmunityCooldownID) to use, and defaults to -1 (ImmunityCooldownID.General). 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 behavior. Not consuming will always take priority over forced consumption More...
 
virtual bool CanHitNPC (NPC target)
 Allows you to determine whether a player can hit the given NPC. Returns true by default. More...
 
virtual ? bool CanHitNPCWithItem (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 CanMeleeAttackCollideWithNPC (Item item, Rectangle meleeAttackHitbox, NPC target)
 Allows you to determine whether a player melee attack can collide the given NPC by swinging a melee weapon.
Use CanHitNPCWithItem(Item, NPC) instead for Guide Voodoo Doll-type effects. 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 CanShowExtraJumpVisuals (ExtraJump jump)
 Return false to prevent ExtraJump.ShowVisuals(Player) from executing on jump .
By default, this hook returns whether the player is moving upwards with respect to Player.gravDir More...
 
virtual bool CanStartExtraJump (ExtraJump jump)
 An extra condition for whether an extra jump can be started. 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 successfully 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 bool ConsumableDodge (Player.HurtInfo info)
 Allows you to dodge damage for a player.
Vanilla examples include hallowed armor shadow dodge, and brain of confusion.
For dodges which are 'free' and should be used before triggering consumables, use FreeDodge instead.

Only runs on the local client of the player receiving the damage.
If dodge is determined on the local player, the hit will not be sent across the network.
You may need to send your own packet to synchronize the consumption of the effect, or application of the cooldown in multiplayer. More...
 
virtual void CopyClientState (ModPlayer targetCopy)
 
Allows you to copy information that you intend to sync between server and client to the targetCopy parameter.
You would then use the SendClientChanges hook to compare against that data and decide what needs synchronizing.
This hook is called with every call of the Player.clientClone method.

NOTE: For performance reasons, avoid deep cloning or copying any excessive information.
NOTE: Using Item.CopyNetStateTo is the recommended way of creating item snapshots. 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 EmitEnchantmentVisualsAt (Projectile projectile, Vector2 boxPosition, int boxWidth, int boxHeight)
 
virtual void ExtraJumpVisuals (ExtraJump jump)
 Effects that should appear while the player is performing an extra jump should happen here.
For example, the Sandstorm in a Bottle's dusts are spawned here.
 
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 bool FreeDodge (Player.HurtInfo info)
 Allows you to dodge damage for a player. Intended for guaranteed 'free' or random dodges.
Vanilla example is black belt.
For dodges which consume a stack/buff or have a cooldown, use ConsumableDodge instead.

Only runs on the local client of the player receiving the damage.
If dodge is determined on the local player, the hit will not be sent across the network.
If visual indication of the dodge is required on remote clients, you will need to send your own packet. More...
 
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 Item.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 Item.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 bool ImmuneTo (PlayerDeathReason damageSource, int cooldownCounter, bool dodgeable)
 Allows you to make a player immune to damage from a certain source, or at a certain time.
Vanilla examples include shimmer and journey god mode.

Runs before dodges are used, or any damage calculations are performed.
Runs on all players, on all clients, so checking Player == Main.LocalPlayer is advisable.
If immunity is determined on the local player, the hit will not be sent across the network.

In pvp the hit will be sent regardless, and all clients will determine immunity independently, though it only really matters for the receiving player. 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...
 
delegate void ItemConsumedCallback (Item item, int index)
 An action to be invoked when an item is partially or fully consumed 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. This is typically used to implement a weapon enchantment, similar to flasks, frost armor, or magma stone effects. If implementing a weapon enchantment, also implement EmitEnchantmentVisualsAt(Projectile, Vector2, int, int) to support enchantment visuals for projectiles as well. 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 ModifyExtraJumpDurationMultiplier (ExtraJump jump, ref float duration)
 Use this hook to modify the jump duration from an extra jump.
Vanilla's extra jumps use the following values: More...
 
virtual void ModifyFishingAttempt (ref FishingAttempt attempt)
 Allows you to change information about the ongoing fishing attempt before caught 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 Player.HurtModifiers modifiers)
 Allows you to modify the damage, etc., that an NPC does to this player.
Runs on the local client.

 
virtual void ModifyHitByProjectile (Projectile proj, ref Player.HurtModifiers modifiers)
 Allows you to modify the damage, etc., that a hostile projectile does to this player.
Runs on the local client.

 
virtual void ModifyHitNPC (NPC target, ref NPC.HitModifiers modifiers)
 Allows you to modify the damage, knockback, etc that this player does to an NPC.
This method is only called on the on the local client.
More...
 
virtual void ModifyHitNPCWithItem (Item item, NPC target, ref NPC.HitModifiers modifiers)
 Allows you to modify the damage, knockback, etc., that this player does to an NPC by swinging a melee weapon.
This method is only called on the on the client of the player holding the weapon.
More...
 
virtual void ModifyHitNPCWithProj (Projectile proj, NPC target, ref NPC.HitModifiers modifiers)
 Allows you to modify the damage, knockback, etc., that a projectile created by this player does to an NPC. More...
 
virtual void ModifyHurt (ref Player.HurtModifiers modifiers)
 Allows you to adjust an instance of player taking damage.
Called on local, server and remote clients.
Only use this hook if you need to modify the hurt parameters in some way, eg consuming a buff which reduces the damage of the next hit.
Use OnHurt or PostHurt instead where possible.
The player will always take at least 1 damage. To prevent damage use ImmuneTo or FreeDodge

 
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. Also note that unlike many other tModLoader hooks, the default implementation of this hook has code that will assign health and mana to StatModifier.Default. Take care to place base.ModifyMaxStats(out health, out mana); before any other code you add to this hook to avoid issues, if you use it. 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 the Nurse wiki pagefor the default pricing. More...
 
virtual void ModifyScreenPosition ()
 Use this hook to modify Main.screenPosition after weapon zoom and camera lerp have taken place.
Also consider using Main.instance.CameraModifiers.Add(CameraModifier); as shown in ExampleMods MinionBossBody for screen shakes.
 
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 ()
 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 OnExtraJumpCleared (ExtraJump jump)
 This hook runs before the ExtraJumpState.Available flag for an extra jump is set to false in Player.Update(int) due to the jump being unavailable or when calling Player.ConsumeAllExtraJumps (vanilla calls it when a mount that blocks jumps is active) More...
 
virtual void OnExtraJumpEnded (ExtraJump jump)
 This hook runs before the ExtraJumpState.Active flag for an extra jump is set from true to false when the extra jump's duration has expired
This occurs when a grappling hook is thrown, the player grabs onto a rope, the jump's duration has finished and when the player's frozen, turned to stone or webbed. More...
 
virtual void OnExtraJumpRefreshed (ExtraJump jump)
 This hook runs before the ExtraJumpState.Available flag for an extra jump is set to true in Player.RefreshDoubleJumps
This occurs at the start of the grounded jump and while the player is grounded. More...
 
virtual void OnExtraJumpStarted (ExtraJump jump, ref bool playSound)
 Effects that should appear when the extra jump starts should happen here.
For example, the Cloud in a Bottle's initial puff of smoke is spawned here. 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.
Called on the local client.
More...
 
virtual void OnHitByNPC (NPC npc, Player.HurtInfo hurtInfo)
 Allows you to create special effects when an NPC hits this player (for example, inflicting debuffs).
Runs on the local client.

 
virtual void OnHitByProjectile (Projectile proj, Player.HurtInfo hurtInfo)
 Allows you to create special effects when a hostile projectile hits this player.
Runs on the local client.

 
virtual void OnHitNPC (NPC target, NPC.HitInfo hit, int damageDone)
 Allows you to create special effects when this player hits an NPC. More...
 
virtual void OnHitNPCWithItem (Item item, NPC target, NPC.HitInfo hit, int damageDone)
 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, NPC.HitInfo hit, int damageDone)
 Allows you to create special effects when a projectile created by this player hits an NPC (for example, inflicting debuffs). More...
 
virtual void OnHurt (Player.HurtInfo info)
 Allows you to make anything happen when the player takes damage.
Called on local, server and remote clients.
Called right before health is reduced.
 
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 bool OnPickup (Item item)
 Allows you to make special things happen when this player picks up an item. Return false to stop the item from being added to the player's inventory; returns true by default. More...
 
virtual void OnRespawn ()
 Called when a player respawns in the world.
 
virtual void PlayerConnect ()
 Called on clients when a player connects.
 
virtual void PlayerDisconnect ()
 Called when a player disconnects.
 
virtual void PostBuyItem (NPC vendor, Item[] shopInventory, Item item)
 Called whenever the player buys an item from an NPC. More...
 
virtual void PostHurt (Player.HurtInfo info)
 Allows you to make anything happen when the player takes damage.
Called on local, server and remote clients.
Only called if the player survives the hit.
 
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. Note that item might be an item sold by the NPC, not an item to buy back. Check Item.buyOnce if relevant to your logic. 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 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 genDust, 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 genDust parameter to false to stop the dust from being created. These are useful for creating your own sound or dust to replace the normal death effects, such as how the Frost armor set spawns DustID.IceTorch instead of DustID.Blood. For mod compatibility, it is recommended to check if these values are true before setting them to true and spawning dust or playing sounds to avoid overlapping sounds and dust effects.

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.
This can be used to adjust timers and cooldowns.
 
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. Read ExampleKeybindPlayer.csfor examples and information on using this hook. More...
 
virtual void RefreshInfoAccessoriesFromTeamPlayers (Player otherPlayer)
 This is where you set any fields related to INFORMATION accessories based on the passed in player argument. Note that this hook is only called if all of the requirements for a "nearby teammate" is met, which is when the other player is on the same team and within a certain distance, determined by the following code: 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 ResetInfoAccessories ()
 This is where you reset any fields related to INFORMATION accessories to their "default" states. This is identical to ResetEffects(); but should ONLY be used to reset info accessories. It will cause unintended side-effects if used with other fields. More...
 
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 ResetEffects, 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.
 
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 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...
 
string PrettyPrintName ()
 
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 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 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 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 IIndexed
ushort Index [get]
 

Detailed Description

A ModPlayer instance represents an extension of a Player instance.
To use it, simply create a new class deriving from this one. Implementations will be registered automatically.
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

◆ AddMaterialsForCrafting()

virtual IEnumerable< Item > ModPlayer.AddMaterialsForCrafting ( out ItemConsumedCallback  itemConsumedCallback)
virtual

Called when Recipe.FindRecipes is called or the player is crafting an item You can use this method to add items as the materials that may be used for crafting items

Parameters
itemConsumedCallbackThe action that gets invoked when the item is consumed
Returns
A list of the items that may be used as crafting materials or null if none are available.

◆ AddStartingItems()

virtual IEnumerable< Item > 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>().

◆ AnglerQuestReward()

virtual void 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

◆ ArmorSetBonusActivated()

virtual void ModPlayer.ArmorSetBonusActivated ( )
virtual

This is called when the player activates their armor set bonus by double tapping down (or up if Main.ReversedUpDownArmorSetBonuses is true). As an example, the Vortex armor uses this to toggle stealth mode.

Use this to implement armor set bonuses that need to be activated by the player.

Don't forget to check if your armor set is active.

While this technically can be used for other effects, it will likely be frustrating for your players if non-armor set effects are being triggered in tandem with armor set bonus effects. Modders can use Player.holdDownCardinalTimer and Player.doubleTapCardinalTimer directly in other hooks for similar effects if needed.

◆ ArmorSetBonusHeld()

virtual void ModPlayer.ArmorSetBonusHeld ( int  holdTime)
virtual

This is called when the player activates their armor set bonus by holding down (or up if Main.ReversedUpDownArmorSetBonuses is true) for some amount of time. The holdTime parameter indicates how many ticks the key has been held down for. As an example, the Stardust armor prior to 1.4.4 used to use this to set the location of the Stardust Guardian if holdTime was greater than 60.

Use this to implement armor set bonuses that need to be activated by the player.

Don't forget to check if your armor set is active.

While this technically can be used for other effects, it will likely be frustrating for your players if non-armor set effects are being triggered in tandem with armor set bonus effects. Modders can use Player.holdDownCardinalTimer and Player.doubleTapCardinalTimer directly in other hooks for similar effects if needed.

◆ CanAutoReuseItem()

virtual ? bool 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 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 (ImmunityCooldownID) to use, and defaults to -1 (ImmunityCooldownID.General).

Parameters
npc
cooldownSlot
Returns

◆ CanBeHitByProjectile()

virtual bool 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 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 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 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 given weapon is attempting to consume.
Returns

◆ CanConsumeBait()

virtual ? bool ModPlayer.CanConsumeBait ( Item  bait)
virtual

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

Parameters
baitThe item (bait) that would be consumed

◆ CanHitNPC()

virtual bool ModPlayer.CanHitNPC ( NPC  target)
virtual

Allows you to determine whether a player can hit the given NPC. Returns true by default.

Parameters
target
Returns
True by default

◆ CanHitNPCWithItem()

virtual ? bool ModPlayer.CanHitNPCWithItem ( 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 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 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 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

◆ CanMeleeAttackCollideWithNPC()

virtual ? bool ModPlayer.CanMeleeAttackCollideWithNPC ( Item  item,
Rectangle  meleeAttackHitbox,
NPC  target 
)
virtual

Allows you to determine whether a player melee attack can collide the given NPC by swinging a melee weapon.
Use CanHitNPCWithItem(Item, NPC) instead for Guide Voodoo Doll-type effects.

Parameters
itemThe weapon item the player is holding.
meleeAttackHitboxHitbox of melee attack.

>

Parameters
targetThe target npc.
Returns
Return true to allow colliding the target, return false to block the player weapon from colliding the target, and return null to use the vanilla code for whether the target can be colliding by melee weapon. Returns null by default.

◆ CanSellItem()

virtual bool 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 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

◆ CanShowExtraJumpVisuals()

virtual bool ModPlayer.CanShowExtraJumpVisuals ( ExtraJump  jump)
virtual

Return false to prevent ExtraJump.ShowVisuals(Player) from executing on jump .
By default, this hook returns whether the player is moving upwards with respect to Player.gravDir

Parameters
jumpThe jump instance

◆ CanStartExtraJump()

virtual bool ModPlayer.CanStartExtraJump ( ExtraJump  jump)
virtual

An extra condition for whether an extra jump can be started. Returns true by default.

Parameters
jumpThe jump that would be performed
Returns
true to let the jump be started, false otherwise.

◆ CanUseItem()

virtual bool 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 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 successfully 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.

◆ ConsumableDodge()

virtual bool ModPlayer.ConsumableDodge ( Player.HurtInfo  info)
virtual

Allows you to dodge damage for a player.
Vanilla examples include hallowed armor shadow dodge, and brain of confusion.
For dodges which are 'free' and should be used before triggering consumables, use FreeDodge instead.

Only runs on the local client of the player receiving the damage.
If dodge is determined on the local player, the hit will not be sent across the network.
You may need to send your own packet to synchronize the consumption of the effect, or application of the cooldown in multiplayer.

Returns
True to completely ignore the hit

◆ CopyClientState()

virtual void ModPlayer.CopyClientState ( ModPlayer  targetCopy)
virtual


Allows you to copy information that you intend to sync between server and client to the targetCopy parameter.
You would then use the SendClientChanges hook to compare against that data and decide what needs synchronizing.
This hook is called with every call of the Player.clientClone method.

NOTE: For performance reasons, avoid deep cloning or copying any excessive information.
NOTE: Using Item.CopyNetStateTo is the recommended way of creating item snapshots.

Parameters
targetCopy

Reimplemented in ModAccessorySlotPlayer.

◆ CreateTemplateEntity()

override Player ModPlayer.CreateTemplateEntity ( )
protectedvirtual

◆ DrawEffects()

virtual void 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

◆ FreeDodge()

virtual bool ModPlayer.FreeDodge ( Player.HurtInfo  info)
virtual

Allows you to dodge damage for a player. Intended for guaranteed 'free' or random dodges.
Vanilla example is black belt.
For dodges which consume a stack/buff or have a cooldown, use ConsumableDodge instead.

Only runs on the local client of the player receiving the damage.
If dodge is determined on the local player, the hit will not be sent across the network.
If visual indication of the dodge is required on remote clients, you will need to send your own packet.

Returns
True to completely ignore the hit

◆ GetDyeTraderReward()

virtual void 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 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 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 Item.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 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 Item.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 ModPlayer.HideDrawLayers ( PlayerDrawSet  drawInfo)
virtual

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

Parameters
drawInfo

◆ HoverSlot()

virtual bool 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.

◆ ImmuneTo()

virtual bool ModPlayer.ImmuneTo ( PlayerDeathReason  damageSource,
int  cooldownCounter,
bool  dodgeable 
)
virtual

Allows you to make a player immune to damage from a certain source, or at a certain time.
Vanilla examples include shimmer and journey god mode.

Runs before dodges are used, or any damage calculations are performed.
Runs on all players, on all clients, so checking Player == Main.LocalPlayer is advisable.
If immunity is determined on the local player, the hit will not be sent across the network.

In pvp the hit will be sent regardless, and all clients will determine immunity independently, though it only really matters for the receiving player.

Parameters
damageSourceThe source of the damage (projectile, NPC, etc)
cooldownCounterThe ImmunityCooldownID of the hit
dodgeableWhether the hit is dodgeable
Returns
True to completely ignore the hit

◆ Initialize()

virtual void 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 UnloadedPlayer.

◆ ItemConsumedCallback()

delegate void ModPlayer.ItemConsumedCallback ( Item  item,
int  index 
)

An action to be invoked when an item is partially or fully consumed

Parameters
itemThe item that has been consumed. May have been set to air if the item was fully consumed.
indexThe index of the item enumerated in IEnumerable<Item>

◆ Kill()

virtual void 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 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 ModAccessorySlotPlayer, and UnloadedPlayer.

◆ MeleeEffects()

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

Allows you to give this player's melee weapon special effects, such as creating light or dust. This is typically used to implement a weapon enchantment, similar to flasks, frost armor, or magma stone effects. If implementing a weapon enchantment, also implement EmitEnchantmentVisualsAt(Projectile, Vector2, int, int) to support enchantment visuals for projectiles as well.

Parameters
item
hitbox

◆ ModifyCaughtFish()

virtual void 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 ModPlayer.ModifyDrawInfo ( ref PlayerDrawSet  drawInfo)
virtual

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

Parameters
drawInfo

◆ ModifyDrawLayerOrdering()

virtual void 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

◆ ModifyExtraJumpDurationMultiplier()

virtual void ModPlayer.ModifyExtraJumpDurationMultiplier ( ExtraJump  jump,
ref float  duration 
)
virtual

Use this hook to modify the jump duration from an extra jump.
Vanilla's extra jumps use the following values:

Basilisk mount: 0.75
Blizzard in a Bottle: 1.5
Cloud in a Bottle: 0.75
Fart in a Jar: 2
Goat mount: 2
Sandstorm in a Bottle: 3
Santank mount: 2
Tsunami in a Bottle: 1.25
Unicorn mount: 2

Parameters
jumpThe jump being performed
durationA modifier to the player's jump height, which when combined effectively acts as the duration for the extra jump

◆ ModifyFishingAttempt()

virtual void ModPlayer.ModifyFishingAttempt ( ref FishingAttempt  attempt)
virtual

Allows you to change information about the ongoing fishing attempt before caught 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

◆ ModifyHitNPC()

virtual void ModPlayer.ModifyHitNPC ( NPC  target,
ref NPC.HitModifiers  modifiers 
)
virtual

Allows you to modify the damage, knockback, etc that this player does to an NPC.
This method is only called on the on the local client.

Parameters
target
modifiers

◆ ModifyHitNPCWithItem()

virtual void ModPlayer.ModifyHitNPCWithItem ( Item  item,
NPC  target,
ref NPC.HitModifiers  modifiers 
)
virtual

Allows you to modify the damage, knockback, etc., that this player does to an NPC by swinging a melee weapon.
This method is only called on the on the client of the player holding the weapon.

Parameters
item
target
modifiers

◆ ModifyHitNPCWithProj()

virtual void ModPlayer.ModifyHitNPCWithProj ( Projectile  proj,
NPC  target,
ref NPC.HitModifiers  modifiers 
)
virtual

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

Parameters
proj
target
modifiers

◆ ModifyItemScale()

virtual void 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 ModPlayer.ModifyLuck ( ref float  luck)
virtual

Allows you to modify a player's luck amount.

Parameters
luck

◆ ModifyManaCost()

virtual void 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 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. Also note that unlike many other tModLoader hooks, the default implementation of this hook has code that will assign health and mana to StatModifier.Default. Take care to place base.ModifyMaxStats(out health, out mana); before any other code you add to this hook to avoid issues, if you use it.

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

◆ ModifyNurseHeal()

virtual bool 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 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 the Nurse wiki pagefor 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 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 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 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 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 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 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 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 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 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 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 ModPlayer.OnEnterWorld ( )
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.

Reimplemented in UnloadedPlayer.

◆ OnExtraJumpCleared()

virtual void ModPlayer.OnExtraJumpCleared ( ExtraJump  jump)
virtual

This hook runs before the ExtraJumpState.Available flag for an extra jump is set to false in Player.Update(int) due to the jump being unavailable or when calling Player.ConsumeAllExtraJumps (vanilla calls it when a mount that blocks jumps is active)

Parameters
jumpThe jump instance

◆ OnExtraJumpEnded()

virtual void ModPlayer.OnExtraJumpEnded ( ExtraJump  jump)
virtual

This hook runs before the ExtraJumpState.Active flag for an extra jump is set from true to false when the extra jump's duration has expired
This occurs when a grappling hook is thrown, the player grabs onto a rope, the jump's duration has finished and when the player's frozen, turned to stone or webbed.

Parameters
jumpThe jump that was performed

◆ OnExtraJumpRefreshed()

virtual void ModPlayer.OnExtraJumpRefreshed ( ExtraJump  jump)
virtual

This hook runs before the ExtraJumpState.Available flag for an extra jump is set to true in Player.RefreshDoubleJumps
This occurs at the start of the grounded jump and while the player is grounded.

Parameters
jumpThe jump instance

◆ OnExtraJumpStarted()

virtual void ModPlayer.OnExtraJumpStarted ( ExtraJump  jump,
ref bool  playSound 
)
virtual

Effects that should appear when the extra jump starts should happen here.
For example, the Cloud in a Bottle's initial puff of smoke is spawned here.

Parameters
jumpThe jump being performed
playSoundWhether the poof sound should play. Set this parameter to false if you want to play a different sound.

◆ OnHitAnything()

virtual void 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.
Called on the local client.

Parameters
x
y
victim

◆ OnHitNPC()

virtual void ModPlayer.OnHitNPC ( NPC  target,
NPC.HitInfo  hit,
int  damageDone 
)
virtual

Allows you to create special effects when this player hits an NPC.

Parameters
target
hit
damageDone

◆ OnHitNPCWithItem()

virtual void ModPlayer.OnHitNPCWithItem ( Item  item,
NPC  target,
NPC.HitInfo  hit,
int  damageDone 
)
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
hit
damageDone

◆ OnHitNPCWithProj()

virtual void ModPlayer.OnHitNPCWithProj ( Projectile  proj,
NPC  target,
NPC.HitInfo  hit,
int  damageDone 
)
virtual

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

Parameters
proj
target
hit
damageDone

◆ OnMissingMana()

virtual void 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.

◆ OnPickup()

virtual bool ModPlayer.OnPickup ( Item  item)
virtual

Allows you to make special things happen when this player picks up an item. Return false to stop the item from being added to the player's inventory; returns true by default.

Parameters
itemThe item being picked up
Returns

◆ PostBuyItem()

virtual void 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.

◆ PostNurseHeal()

virtual void 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 ModPlayer.PostSellItem ( NPC  vendor,
Item[]  shopInventory,
Item  item 
)
virtual

Called whenever the player sells an item to an NPC. Note that item might be an item sold by the NPC, not an item to buy back. Check Item.buyOnce if relevant to your logic.

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

◆ PreItemCheck()

virtual bool 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 ModPlayer.PreKill ( double  damage,
int  hitDirection,
bool  pvp,
ref bool  playSound,
ref bool  genDust,
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 genDust parameter to false to stop the dust from being created. These are useful for creating your own sound or dust to replace the normal death effects, such as how the Frost armor set spawns DustID.IceTorch instead of DustID.Blood. For mod compatibility, it is recommended to check if these values are true before setting them to true and spawning dust or playing sounds to avoid overlapping sounds and dust effects.

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
genDust
damageSource
Returns

◆ PreModifyLuck()

virtual bool 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 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. Read ExampleKeybindPlayer.csfor examples and information on using this hook.

Parameters
triggersSet

◆ RefreshInfoAccessoriesFromTeamPlayers()

virtual void ModPlayer.RefreshInfoAccessoriesFromTeamPlayers ( Player  otherPlayer)
virtual

This is where you set any fields related to INFORMATION accessories based on the passed in player argument. Note that this hook is only called if all of the requirements for a "nearby teammate" is met, which is when the other player is on the same team and within a certain distance, determined by the following code:

(Main.player[i].Center - base.Center).Length() < 800f

◆ Register()

sealed override void ModPlayer.Register ( )
protectedvirtual

If you make a new ModType, seal this override.

Implements ModType< Player, ModPlayer >.

◆ ResetInfoAccessories()

virtual void ModPlayer.ResetInfoAccessories ( )
virtual

This is where you reset any fields related to INFORMATION accessories to their "default" states. This is identical to ResetEffects(); but should ONLY be used to reset info accessories. It will cause unintended side-effects if used with other fields.

This method is called in tandem with

See also
ResetEffects, Player.RefreshInfoAccs

, but it also called in even when the game is paused; this allows for info accessories to keep properly updating while the game is paused, a feature/fix added in 1.4.4.

◆ SaveData()

virtual void 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 ModAccessorySlotPlayer, and UnloadedPlayer.

◆ SendClientChanges()

virtual void 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 ModAccessorySlotPlayer.

◆ SetupContent()

sealed override void ModPlayer.SetupContent ( )
virtual

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

Reimplemented from ModType< Player, ModPlayer >.

◆ ShiftClickSlot()

virtual bool 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 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 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 ModAccessorySlotPlayer.

◆ UpdateEquips()

virtual void ModPlayer.UpdateEquips ( )
virtual

Called after Update Accessories.

Reimplemented in ModAccessorySlotPlayer.

◆ UpdateVisibleAccessories()

virtual void 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 ModAccessorySlotPlayer.

◆ UpdateVisibleVanityAccessories()

virtual void 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 ModAccessorySlotPlayer.

◆ UseAnimationMultiplier()

virtual float 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 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 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 ModPlayer.ValidateType ( )
protectedvirtual

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

Reimplemented from ModType< Player, ModPlayer >.

Property Documentation

◆ Index

ushort ModPlayer.Index
getset

Implements IIndexed.