tModLoader v2024.09
A mod to make and play Terraria mods
ModNPC Class Reference

This class serves as a place for you to place all your properties and hooks for each NPC.
To use it, simply create a new class deriving from this one. Implementations will be registered automatically. The Basic NPC Guideteaches the basics of making a modded NPC. More...

Inherits ModType< NPC, ModNPC >, and ILocalizedModType.

Public Member Functions

virtual void AddShops ()
 Allows you to add shops to this NPC, similar to adding recipes for items.
Make a new NPCShop, and items to it, and call AbstractNPCShop.Register
 
virtual void AI ()
 Allows you to determine how this NPC behaves. This will only be called if PreAI returns true.
 
virtual void ApplyDifficultyAndPlayerScaling (int numPlayers, float balance, float bossAdjustment)
 Allows you to customize this NPC's stats when the difficulty is expert or higher.
This runs after NPC.value, NPC.lifeMax, NPC.damage, NPC.knockBackResist have been adjusted for the current difficulty, (expert/master/FTW)
It is common to multiply lifeMax by the balance factor, and sometimes adjust knockbackResist.

Eg:
More...
 
virtual void AutoStaticDefaults ()
 Automatically sets certain static defaults. Override this if you do not want the properties to be set for you.
 
virtual void BossHeadRotation (ref float rotation)
 Allows you to customize the rotation of this NPC's boss head icon on the map. More...
 
virtual void BossHeadSlot (ref int index)
 Allows you to customize the boss head texture used by an NPC based on its state. Set index to -1 to stop the texture from being displayed. More...
 
virtual void BossHeadSpriteEffects (ref SpriteEffects spriteEffects)
 Allows you to flip this NPC's boss head icon on the map. More...
 
virtual void BossLoot (ref string name, ref int potionType)
 Allows you to customize what happens when this boss dies, such as which name is displayed in the defeat message and what type of potion it drops. More...
 
virtual ? bool CanBeCaughtBy (Item item, Player player)
 Allows you to determine whether the given item can catch this NPC.
Return true or false to say this NPC 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 an NPC-catching 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 CanBeHitByItem (Player player, Item item)
 Allows you to determine whether this NPC can be hit by the given melee weapon when swung. Return true to allow hitting the NPC, return false to block hitting the NPC, and return null to use the vanilla code for whether the NPC can be hit. Returns null by default. More...
 
virtual bool CanBeHitByNPC (NPC attacker)
 Allows you to determine whether a friendly NPC can be hit by an NPC. Return false to block the attacker from hitting the NPC, and return true to use the vanilla code for whether the target can be hit. Returns true by default. More...
 
virtual ? bool CanBeHitByProjectile (Projectile projectile)
 Allows you to determine whether this NPC can be hit by the given projectile. Return true to allow hitting the NPC, return false to block hitting the NPC, and return null to use the vanilla code for whether the NPC can be hit. Returns null by default. More...
 
virtual bool CanChat ()
 Allows you to determine whether this NPC can talk with the player. By default, returns if the NPC is a town NPC. More...
 
virtual ? bool CanCollideWithPlayerMeleeAttack (Player player, Item item, Rectangle meleeAttackHitbox)
 Allows you to determine whether an NPC can be collided with the player melee weapon when swung.
Use CanBeHitByItem(Player, Item) instead for Guide Voodoo Doll-type effects. More...
 
virtual ? bool CanFallThroughPlatforms ()
 Allows you to determine how and when this NPC can fall through platforms and similar tiles.
Return true to allow this NPC to fall through platforms, false to prevent it. Returns null by default, applying vanilla behaviors (based on aiStyle and type).
 
virtual bool CanGoToStatue (bool toKingStatue)
 Whether this NPC can be teleported to a King or Queen statue. Returns false by default. More...
 
virtual bool CanHitNPC (NPC target)
 Allows you to determine whether this NPC can hit the given friendly NPC. Return false to block the NPC from hitting the target, and return true to use the vanilla code for whether the target can be hit. Returns true by default. More...
 
virtual bool CanHitPlayer (Player target, ref int cooldownSlot)
 Allows you to determine whether this NPC can hit the given player. Return false to block this NPC from hitting the target. 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 CanTownNPCSpawn (int numTownNPCs)
 Whether or not the conditions have been met for this town NPC to be able to move into town. For example, the Demolitionist requires that any player has an explosive. Town NPC spawn conditions typically check if specific bosses have been defeated (NPC.downedGolemBoss), the npc has been "saved" somewhere in the world, or any player has specific items in their inventory. To check for inventory items, iterate over Main.ActivePlayers and check Player.HasItem(int) or Player.CountItem(int, int), returning true if any player satisfies the requirement. To support allowing town NPC to respawn without needing to meet the original respawn requirements, a feature added in Terraria v1.4.4, store a bool in a ModSystem and check it. ExamplePerson.CanTownNPCSpawnand TownNPCRespawnSystem.csshow an example of this. Returns false by default, preventing the town NPC from spawning. More...
 
virtual void ChatBubblePosition (ref Vector2 position, ref SpriteEffects spriteEffects)
 Allows you to change the location and sprite direction of the chat bubble that shows up while hovering over a Town NPC. More...
 
virtual bool CheckActive ()
 Whether or not to run the code for checking whether this NPC will remain active. Return false to stop this NPC from being despawned and to stop this NPC from counting towards the limit for how many NPCs can exist near a player. Returns true by default. More...
 
virtual bool CheckConditions (int left, int right, int top, int bottom)
 Allows you to define special conditions required for this town NPC's house. For example, Truffle requires the house to be in an aboveground mushroom biome. The left , right , top , and bottom parameters define the bounds of the room being checked. Methods like WorldGen.Housing_GetTestedRoomBounds(out int, out int, out int, out int) and WorldGen.CountTileTypesInArea(int[], int, int, int, int) can facilitate implementing specific checks. Return false to prevent the npc from spawning due to failed condition checks.
 
virtual bool CheckDead ()
 Whether or not this NPC should be killed when it reaches 0 health. You may program extra effects in this hook (for example, how Golem's head lifts up for the second phase of its fight). Return false to stop this NPC from being killed. Returns true by default. More...
 
virtual void DrawBehind (int index)
 When used in conjunction with "NPC.hide = true", allows you to specify that this NPC should be drawn behind certain elements. Add the index to one of Main.DrawCacheNPCsMoonMoon, DrawCacheNPCsOverPlayers, DrawCacheNPCProjectiles, or DrawCacheNPCsBehindNonSolidTiles. More...
 
virtual void DrawEffects (ref Color drawColor)
 Allows you to add special visual effects to this NPC (such as creating dust), and modify the color in which the NPC is drawn. More...
 
virtual ? bool DrawHealthBar (byte hbPosition, ref float scale, ref Vector2 position)
 Allows you to control how the health bar for this NPC is drawn. The hbPosition parameter is the same as Main.hbPosition; it determines whether the health bar gets drawn above or below the NPC by default. The scale parameter is the health bar's size. By default, it will be the normal 1f; most bosses set this to 1.5f. Return null to let the normal vanilla health-bar-drawing code to run. Return false to stop the health bar from being drawn. Return true to draw the health bar in the position specified by the position parameter (note that this is the world position, not screen position). More...
 
virtual void DrawTownAttackGun (ref Texture2D item, ref Rectangle itemFrame, ref float scale, ref int horizontalHoldoutOffset)
 Allows you to customize how this town NPC's weapon is drawn when this NPC is shooting (this NPC must have an attack type (NPCID.Sets.AttackType) of 1). scale is a multiplier for the item's drawing size, item is the Texture2D instance of the item to be drawn, itemFrame is the section of the texture to draw, and horizontalHoldoutOffset is how far away the item should be drawn from the NPC.
To use an actual item sprite, use More...
 
virtual void DrawTownAttackSwing (ref Texture2D item, ref Rectangle itemFrame, ref int itemSize, ref float scale, ref Vector2 offset)
 Allows you to customize how this town NPC's weapon is drawn when this NPC is swinging it (this NPC must have an attack type (NPCID.Sets.AttackType) of 3). item is the Texture2D instance of the item to be drawn, itemFrame is the section of the texture to draw, itemSize is the width and height of the item's hitbox (the same values for TownNPCAttackSwing), scale is the multiplier for the item's drawing size, and offset is the offset from which to draw the item from its normal position. The item texture can be any texture, but if it is an item texture you can use Main.GetItemDrawFrame(int, out Texture2D, out Rectangle) to set item and itemFrame easily. More...
 
virtual void EmoteBubblePosition (ref Vector2 position, ref SpriteEffects spriteEffects)
 Allows you to change the location and sprite direction of the emote bubble when anchored to an NPC. More...
 
virtual void FindFrame (int frameHeight)
 Allows you to modify the frame from this NPC's texture that is drawn, which is necessary in order to animate NPCs. More...
 
virtual ? Color GetAlpha (Color drawColor)
 Allows you to determine the color and transparency in which this NPC is drawn. Return null to use the default color (normally light and buff color). Returns null by default. More...
 
virtual string GetChat ()
 Allows you to give this NPC a chat message when a player talks to it. By default returns something embarrassing. More...
 
virtual void HitEffect (NPC.HitInfo hit)
 Allows you to make things happen whenever this NPC is hit, such as creating dust or gores.
Called on local, server and remote clients.
Usually when something happens when an NPC dies such as item spawning, you use NPCLoot, but you can use HitEffect paired with a check for if (NPC.life <= 0) to do client-side death effects, such as spawning dust, gore, or death sounds.

 
virtual void LoadData (TagCompound tag)
 Allows you to load custom data that you have saved for this npc. More...
 
virtual void ModifyActiveShop (string shopName, Item[] items)
 Allows you to modify the contents of a shop whenever player opens it.
To create a shop, use AddShops
Note that for special shops like travelling merchant, the shopName may not correspond to a NPCShop in the NPCShopDatabase Also note that unused slots in items are null while Item.IsAir entries are entries that have a reserved slot (NPCShop.Entry.SlotReserved) but did not have their conditions met. These should not be overwritten. More...
 
virtual bool ModifyCollisionData (Rectangle victimHitbox, ref int immunityCooldownSlot, ref MultipliableFloat damageMultiplier, ref Rectangle npcHitbox)
 Allows you to modify the NPC's

See also
ImmunityCooldownID

, damage multiplier, and hitbox. Useful for implementing dynamic damage hitboxes that change in dimensions or deal extra damage. Returns false to prevent vanilla code from running. Returns true by default. More...

 
virtual void ModifyHitByItem (Player player, Item item, ref NPC.HitModifiers modifiers)
 Allows you to modify the damage, knockback, etc., that this NPC takes from a melee weapon.
Runs on the local client.
More...
 
virtual void ModifyHitByProjectile (Projectile projectile, ref NPC.HitModifiers modifiers)
 Allows you to modify the damage, knockback, etc., that this NPC takes from a projectile. This method is only called for the owner of the projectile, meaning that in multi-player, projectiles owned by a player call this method on that client, and projectiles owned by the server such as enemy projectiles call this method on the server. More...
 
virtual void ModifyHitNPC (NPC target, ref NPC.HitModifiers modifiers)
 Allows you to modify the damage, knockback, etc., that this NPC does to a friendly NPC.
Runs in single player or on the server.
More...
 
virtual void ModifyHitPlayer (Player target, ref Player.HurtModifiers modifiers)
 Allows you to modify the damage, etc., that this NPC does to a player.
Runs on the local client.
More...
 
virtual void ModifyHoverBoundingBox (ref Rectangle boundingBox)
 Allows you to modify the bounding box for hovering over this NPC (affects things like whether or not its name is displayed). More...
 
virtual void ModifyIncomingHit (ref NPC.HitModifiers modifiers)
 Allows you to use a custom damage formula for when this NPC takes damage from any source. For example, you can change the way defense works or use a different crit multiplier. More...
 
virtual void ModifyNPCLoot (NPCLoot npcLoot)
 Allows you to add and modify NPC loot tables to drop on death and to appear in the Bestiary.
The Basic NPC Drops and Loot 1.4 Guideexplains how to use this hook to modify NPC loot.
This hook only runs once during mod loading, any dynamic behavior must be contained in the rules themselves. More...
 
virtual void ModifyTypeName (ref string typeName)
 Allows you to modify the type name of this NPC dynamically.
 
virtual bool NeedSaving ()
 Makes this ModNPC save along the world even if it's not a townNPC. Defaults to false.
NOTE: A town NPC will always be saved.
NOTE: A NPC that needs saving will not despawn naturally.
 
virtual void OnCaughtBy (Player player, Item item, bool failed)
 Allows you to make things happen when the given item attempts to catch this NPC. More...
 
virtual void OnChatButtonClicked (bool firstButton, ref string shopName)
 Allows you to make something happen whenever a button is clicked on this NPC's chat window. The firstButton parameter tells whether the first button or second button (button and button2 from SetChatButtons) was clicked. Set the shopName parameter to "Shop" to open this NPC's shop. More...
 
virtual void OnGoToStatue (bool toKingStatue)
 Allows you to make things happen when this NPC teleports to a King or Queen statue. This method is only called server side. More...
 
virtual void OnHitByItem (Player player, Item item, NPC.HitInfo hit, int damageDone)
 Allows you to create special effects when this NPC is hit by a melee weapon.
Runs on the client or server doing the damage.
More...
 
virtual void OnHitByProjectile (Projectile projectile, NPC.HitInfo hit, int damageDone)
 Allows you to create special effects when this NPC is hit by a projectile. More...
 
virtual void OnHitNPC (NPC target, NPC.HitInfo hit)
 Allows you to create special effects when this NPC hits a friendly NPC.
Runs in single player or on the server.
More...
 
virtual void OnHitPlayer (Player target, Player.HurtInfo hurtInfo)
 Allows you to create special effects when this NPC hits a player (for example, inflicting debuffs).
Runs on the local client.
More...
 
virtual void OnKill ()
 Allows you to make things happen when this NPC dies (for example, dropping items manually and setting ModSystem fields). This hook runs on the server/single player. For client-side effects, such as dust, gore, and sounds, see HitEffect. Most item drops should be done via drop rules registered in ModifyNPCLoot(NPCLoot). Some dynamic NPC drops, such as additional hearts, are more suited for OnKill instead. MinionBossMinion.csshows an example of an NPC that drops additional hearts. See NPC.lastInteraction and Player who killed NPC wiki sectionas well for determining which players attacked or killed this NPC. Bosses need to set flags when they are defeated, and some bosses run world generation code such as spawning new ore. MinionBossMinion.csshows an example of these effects.
 
virtual void OnSpawn (IEntitySource source)
 Gets called when your NPC spawns in world
 
virtual void PartyHatPosition (ref Vector2 position, ref SpriteEffects spriteEffects)
 
Allows you to fully control the location of the party and sprite direction of the party while an NPC is wearing it.

See also
NPCID.Sets.HatOffsetY, NPCID.Sets.NPCFramingGroup

can be used instead of this hook for a constant Y offset.
can be additionally be used for the Y offset for the Town NPC's animations. More...

 
virtual ? int PickEmote (Player closestPlayer, List< int > emoteList, WorldUIAnchor otherAnchor)
 Allows you to change the emote that the NPC will pick More...
 
virtual void PostAI ()
 
virtual void PostDraw (SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor)
 Allows you to draw things in front of this NPC. Substract screenPos from the draw position before drawing. This method is called even if PreDraw returns false. More...
 
virtual bool PreAI ()
 Allows you to determine how this NPC behaves. Return false to stop the vanilla AI and the AI hook from being run. Returns true by default. More...
 
virtual bool PreDraw (SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor)
 Allows you to draw things behind this NPC, or to modify the way this NPC is drawn. Substract screenPos from the draw position before drawing. Return false to stop the game from drawing the NPC (useful if you're manually drawing the NPC). Returns true by default. More...
 
virtual bool PreKill ()
 Allows you to determine whether or not this NPC will do anything upon death (besides dying). Returns true by default. More...
 
virtual void ReceiveExtraAI (BinaryReader reader)
 Use this to receive information that was sent in SendExtraAI.
Called whenever MessageID.SyncNPC is successfully received.
Only called on the client. More...
 
virtual void ResetEffects ()
 This is where you reset any fields you add to your 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. (Note: This hook is only really useful for GlobalNPC, but is included in ModNPC for completion.)
 
virtual void SaveData (TagCompound tag)
 Allows you to save custom data for the given item. Allows you to save custom data for the given npc.

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.
NOTE: The npc may be saved even if NeedSaving returns false and this is not a townNPC, if another mod returns true on NeedSaving. More...
 
virtual void SendExtraAI (BinaryWriter writer)
 If you are storing AI information outside of the NPC.ai array, use this to send that AI information between clients and servers, which will be handled in ReceiveExtraAI.
Called whenever MessageID.SyncNPC is successfully sent, for example on NPC creation, on player join, or whenever NPC.netUpdate is set to true in the update loop for that tick.
Only called on the server. More...
 
virtual void SetBestiary (BestiaryDatabase database, BestiaryEntry bestiaryEntry)
 Allows you to set an NPC's information in the Bestiary. More...
 
virtual void SetChatButtons (ref string button, ref string button2)
 Allows you to set the text for the buttons that appear on this NPC's chat window. A parameter left as an empty string will not be included as a button on the chat window. More...
 
virtual void SetDefaults ()
 Allows you to set all your NPC's properties, such as width, damage, aiStyle, lifeMax, etc.
 
virtual List< string > SetNPCNameList ()
 Allows you to give a list of names this NPC can be given on spawn.
By default, returns a blank list, which means the NPC will simply use its type name as its given name when prompted. More...
 
sealed override void SetupContent ()
 If you make a new ModType, seal this override, and call SetStaticDefaults in it. More...
 
virtual float SpawnChance (NPCSpawnInfo spawnInfo)
 Whether or not this NPC can spawn with the given spawning conditions. Return the weight for the chance of this NPC to spawn compared to vanilla mobs. All vanilla mobs combined have a total weight of 1. Returns 0 by default, which disables natural spawning. Remember to always use spawnInfo.player and not Main.LocalPlayer when checking Player or ModPlayer fields, otherwise your mod won't work in Multiplayer. More...
 
virtual int SpawnNPC (int tileX, int tileY)
 Allows you to customize how this NPC is created when it naturally spawns (for example, its position or ai array). Return the return value of NPC.NewNPC. By default this method spawns this NPC on top of the tile at the given coordinates. More...
 
virtual bool SpecialOnKill ()
 Allows you to call OnKill on your own when the NPC dies, rather then letting vanilla call it on its own. Returns false by default. More...
 
virtual void TownNPCAttackCooldown (ref int cooldown, ref int randExtraCooldown)
 Allows you to determine the cooldown between each of this town NPC's attack. The cooldown will be a number greater than or equal to the first parameter, and less then the sum of the two parameters. More...
 
virtual void TownNPCAttackMagic (ref float auraLightMultiplier)
 Allows you to control the brightness of the light emitted by this town NPC's aura when it performs a magic attack. Only used when the town NPC has an attack type (NPCID.Sets.AttackType) of 2 (magic) More...
 
virtual void TownNPCAttackProj (ref int projType, ref int attackDelay)
 Allows you to determine the projectile type of this town NPC's attack, and how long it takes for the projectile to actually appear. This hook is only used when the town NPC has an attack type (NPCID.Sets.AttackType) of 0 (throwing), 1 (shooting), or 2 (magic). More...
 
virtual void TownNPCAttackProjSpeed (ref float multiplier, ref float gravityCorrection, ref float randomOffset)
 Allows you to determine the speed at which this town NPC throws a projectile when it attacks. Multiplier is the speed of the projectile, gravityCorrection is how much extra the projectile gets thrown upwards, and randomOffset allows you to randomize the projectile's velocity in a square centered around the original velocity. This hook is only used when the town NPC has an attack type (NPCID.Sets.AttackType) of 0 (throwing), 1 (shooting), or 2 (magic). More...
 
virtual void TownNPCAttackShoot (ref bool inBetweenShots)
 Allows you to tell the game that this town NPC has already created a projectile and will still create more projectiles as part of a single attack so that the game can animate the NPC's attack properly. Only used when the town NPC has an attack type (NPCID.Sets.AttackType) of 1 (shooting). More...
 
virtual void TownNPCAttackStrength (ref int damage, ref float knockback)
 Allows you to determine the damage and knockback of this town NPC's attack before the damage is scaled. (More information on scaling in GlobalNPC.BuffTownNPCs.) More...
 
virtual void TownNPCAttackSwing (ref int itemWidth, ref int itemHeight)
 Allows you to determine the width and height of the item this town NPC swings when it attacks, which controls the range of this NPC's swung weapon. Only used when the town NPC has an attack type (NPCID.Sets.AttackType) of 3 (swinging). More...
 
virtual ITownNPCProfile TownNPCProfile ()
 Allows you to set the town NPC profile that this NPC uses.
By default, returns null, meaning that the NPC doesn't use one.
 
virtual void UpdateLifeRegen (ref int damage)
 Allows you to make the NPC either regenerate health or take damage over time by setting NPC.lifeRegen. This is useful for implementing damage over time debuffs such as BuffID.Poisoned or BuffID.OnFire. Regeneration or damage will occur at a rate of half of NPC.lifeRegen per second. Essentially, modders implementing damage over time debuffs should subtract from NPC.lifeRegen a number that is twice as large as the intended damage per second. See DamageOverTimeGlobalNPC.csfor an example of this. The damage parameter is the number that appears above the NPC's head if it takes damage over time. Multiple debuffs work together by following some conventions: NPC.lifeRegen should not be assigned a number, rather it should be subtracted from. damage should only be assigned if the intended popup text is larger then its current value.
More...
 
virtual bool UsesPartyHat ()
 Allows you to determine whether this town NPC wears a party hat during a party. Returns true by default. More...
 
- Public Member Functions inherited from ModType< NPC, ModNPC >
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 NPC CreateTemplateEntity ()
 
sealed override void Register ()
 If you make a new ModType, seal this override. More...
 
- Protected Member Functions inherited from ModType< NPC, ModNPC >
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
 

Properties

int AIType [get, set]
 Determines which type of vanilla NPC this ModNPC will copy the behavior (AI) of. Leave as 0 to not copy any behavior. Defaults to 0.
 
int AnimationType [get, set]
 Determines which type of vanilla NPC this ModNPC will copy the animation/framing logic of, which includes checks to sets such as

See also
Main.npcFrameCount, NPCID.Sets.ExtraFramesCount

and , and others. For example, selecting the Guide's type will copy how many frames, extra frames, and attack frames the Guide has, and use those value for animation of this NPC. This is entirely based off of type and not the ModNPC instance itself; so be cautious if you change this NPC's type.

 
int Banner [get, set]
 The type of NPC that this NPC will be considered as when determining banner drops and banner bonuses. By default this will be 0, which means this NPC is not associated with any banner. To give your NPC its own banner, set this field to the NPC's type.
 
int BannerItem [get, set]
 The type of the item this NPC drops for every 50 times it is defeated. For any ModNPC whose banner field is set to the type of this NPC, that ModNPC will drop this banner.
 
virtual string BossHeadTexture [get]
 This file name of this NPC's boss head texture file, to be used in autoloading.
 
virtual LocalizedText DisplayName [get]
 The translations for the display name of this NPC.
 
float DrawOffsetY [get, set]
 The vertical offset used for drawing this NPC. Defaults to 0.
 
virtual string HeadTexture [get]
 The file name of this NPC's head texture file, to be used in autoloading.
 
virtual string LocalizationCategory [get]
 The category used by this modded content for use in localization keys. Localization keys follow the pattern of "Mods.{ModName}.{Category}.{ContentName}.{DataName}". The Localization wiki pageexplains how custom ModType classes can utilize this. More...
 
int Music = -1 [get, set]
 The ID of the music that plays when this NPC is on or near the screen. Defaults to -1, which means music plays normally. More...
 
NPC NPC [get]
 The NPC object that this ModNPC controls.
 
SceneEffectPriority SceneEffectPriority = SceneEffectPriority.BossLow [get, set]
 The priority of the music that plays when this NPC is on or near the screen. More...
 
int[] SpawnModBiomes = new int[0] [get, set]
 The ModBiome Types associated with this NPC spawning, if applicable. Used in Bestiary.Vanilla biomes are added to the bestiary via SetBestiary(BestiaryDatabase, BestiaryEntry) directly.
 
virtual string Texture [get]
 The file name of this type's texture file in the mod loader's file space.
The resulting Asset<Texture2D> can be retrieved using TextureAssets.Npc indexed by Type if needed.
You can use a vanilla texture by returning $"Terraria/Images/NPC_{NPCID.NPCNameHere}"

 
bool TownNPCStayingHomeless [get, set]
 Setting this to true will make the NPC not appear in the housing menu nor make it find an house.
 
int Type [get]
 Shorthand for NPC.type;
 
- Properties inherited from ModType< NPC, ModNPC >
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 ILocalizedModType
abstract string LocalizationCategory [get]
 The category used by this modded content for use in localization keys. Localization keys follow the pattern of "Mods.{ModName}.{Category}.{ContentName}.{DataName}". The Localization wiki pageexplains how custom ModType classes can utilize this. More...
 

Detailed Description

This class serves as a place for you to place all your properties and hooks for each NPC.
To use it, simply create a new class deriving from this one. Implementations will be registered automatically.

The Basic NPC Guide

teaches the basics of making a modded NPC.

Member Function Documentation

◆ ApplyDifficultyAndPlayerScaling()

virtual void ModNPC.ApplyDifficultyAndPlayerScaling ( int  numPlayers,
float  balance,
float  bossAdjustment 
)
virtual

Allows you to customize this NPC's stats when the difficulty is expert or higher.
This runs after NPC.value, NPC.lifeMax, NPC.damage, NPC.knockBackResist have been adjusted for the current difficulty, (expert/master/FTW)
It is common to multiply lifeMax by the balance factor, and sometimes adjust knockbackResist.

Eg:

lifeMax = (int)(lifeMax * balance * bossAdjustment)

Parameters
numPlayersThe number of active players
balanceScaling factor that increases by a fraction for each player
bossAdjustmentAn extra reduction factor to be applied to boss life in high difficulty modes

◆ BossHeadRotation()

virtual void ModNPC.BossHeadRotation ( ref float  rotation)
virtual

Allows you to customize the rotation of this NPC's boss head icon on the map.

Parameters
rotation

◆ BossHeadSlot()

virtual void ModNPC.BossHeadSlot ( ref int  index)
virtual

Allows you to customize the boss head texture used by an NPC based on its state. Set index to -1 to stop the texture from being displayed.

Parameters
indexThe index for NPCID.Sets.BossHeadTextures

◆ BossHeadSpriteEffects()

virtual void ModNPC.BossHeadSpriteEffects ( ref SpriteEffects  spriteEffects)
virtual

Allows you to flip this NPC's boss head icon on the map.

Parameters
spriteEffects

◆ BossLoot()

virtual void ModNPC.BossLoot ( ref string  name,
ref int  potionType 
)
virtual

Allows you to customize what happens when this boss dies, such as which name is displayed in the defeat message and what type of potion it drops.

Parameters
name
potionType

◆ CanBeCaughtBy()

virtual ? bool ModNPC.CanBeCaughtBy ( Item  item,
Player  player 
)
virtual

Allows you to determine whether the given item can catch this NPC.
Return true or false to say this NPC 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 an NPC-catching 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
itemThe item with which the player is trying to catch this NPC.
playerThe player attempting to catch this NPC.
Returns

◆ CanBeHitByItem()

virtual ? bool ModNPC.CanBeHitByItem ( Player  player,
Item  item 
)
virtual

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

Parameters
player
item
Returns

◆ CanBeHitByNPC()

virtual bool ModNPC.CanBeHitByNPC ( NPC  attacker)
virtual

Allows you to determine whether a friendly NPC can be hit by an NPC. Return false to block the attacker from hitting the NPC, and return true to use the vanilla code for whether the target can be hit. Returns true by default.

Parameters
attacker
Returns

◆ CanBeHitByProjectile()

virtual ? bool ModNPC.CanBeHitByProjectile ( Projectile  projectile)
virtual

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

Parameters
projectile
Returns

◆ CanChat()

virtual bool ModNPC.CanChat ( )
virtual

Allows you to determine whether this NPC can talk with the player. By default, returns if the NPC is a town NPC.

This hook is not based on the type of the NPC, and is queried specifically on the ModNPC itself, regardless of if, for example, the type of the NPC instance is changed. Returning true in all circumstances will always make the NPC able to be chatted with no matter what else you do the NPC instance itself.

Returns

◆ CanCollideWithPlayerMeleeAttack()

virtual ? bool ModNPC.CanCollideWithPlayerMeleeAttack ( Player  player,
Item  item,
Rectangle  meleeAttackHitbox 
)
virtual

Allows you to determine whether an NPC can be collided with the player melee weapon when swung.
Use CanBeHitByItem(Player, Item) instead for Guide Voodoo Doll-type effects.

Parameters
playerThe player wielding this item.
itemThe weapon item the player is holding.
meleeAttackHitboxHitbox of melee attack.
Returns
Return true to allow colliding with the melee attack, return false to block the weapon from colliding with the NPC, and return null to use the vanilla code for whether the attack can be colliding. Returns null by default.

◆ CanGoToStatue()

virtual bool ModNPC.CanGoToStatue ( bool  toKingStatue)
virtual

Whether this NPC can be teleported to a King or Queen statue. Returns false by default.

Parameters
toKingStatueWhether the NPC is being teleported to a King or Queen statue.

◆ CanHitNPC()

virtual bool ModNPC.CanHitNPC ( NPC  target)
virtual

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

Parameters
target
Returns

◆ CanHitPlayer()

virtual bool ModNPC.CanHitPlayer ( Player  target,
ref int  cooldownSlot 
)
virtual

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

Parameters
target
cooldownSlot
Returns

◆ CanTownNPCSpawn()

virtual bool ModNPC.CanTownNPCSpawn ( int  numTownNPCs)
virtual

Whether or not the conditions have been met for this town NPC to be able to move into town. For example, the Demolitionist requires that any player has an explosive. Town NPC spawn conditions typically check if specific bosses have been defeated (NPC.downedGolemBoss), the npc has been "saved" somewhere in the world, or any player has specific items in their inventory. To check for inventory items, iterate over Main.ActivePlayers and check Player.HasItem(int) or Player.CountItem(int, int), returning true if any player satisfies the requirement. To support allowing town NPC to respawn without needing to meet the original respawn requirements, a feature added in Terraria v1.4.4, store a bool in a ModSystem and check it. ExamplePerson.CanTownNPCSpawnand TownNPCRespawnSystem.csshow an example of this. Returns false by default, preventing the town NPC from spawning.

Parameters
numTownNPCs
Returns

◆ ChatBubblePosition()

virtual void ModNPC.ChatBubblePosition ( ref Vector2  position,
ref SpriteEffects  spriteEffects 
)
virtual

Allows you to change the location and sprite direction of the chat bubble that shows up while hovering over a Town NPC.

Parameters
position
The default position is:
The X component is set to the NPC's Center - half the width of the chat bubble texture. Then +/- half of the NPC's width + 8 pixels for facing right/left respectively.
Code: npc.Center.X - screenPosition.X - (TextureAssets.Chat.Width() / 2f) +/- (npc.width / 2f + 8)
The Y component is set to the top of the NPC - the height of the chat bubble texture. (Negative Y is up.)
Code: npc.position.Y - TextureAssets.Chat.Height() - (float)(int)screenPosition.Y
spriteEffectsAllows you to change which way the chat bubble is flipped.

◆ CheckActive()

virtual bool ModNPC.CheckActive ( )
virtual

Whether or not to run the code for checking whether this NPC will remain active. Return false to stop this NPC from being despawned and to stop this NPC from counting towards the limit for how many NPCs can exist near a player. Returns true by default.

Returns

◆ CheckDead()

virtual bool ModNPC.CheckDead ( )
virtual

Whether or not this NPC should be killed when it reaches 0 health. You may program extra effects in this hook (for example, how Golem's head lifts up for the second phase of its fight). Return false to stop this NPC from being killed. Returns true by default.

Returns

◆ CreateTemplateEntity()

override NPC ModNPC.CreateTemplateEntity ( )
protectedvirtual

◆ DrawBehind()

virtual void ModNPC.DrawBehind ( int  index)
virtual

When used in conjunction with "NPC.hide = true", allows you to specify that this NPC should be drawn behind certain elements. Add the index to one of Main.DrawCacheNPCsMoonMoon, DrawCacheNPCsOverPlayers, DrawCacheNPCProjectiles, or DrawCacheNPCsBehindNonSolidTiles.

Parameters
index

◆ DrawEffects()

virtual void ModNPC.DrawEffects ( ref Color  drawColor)
virtual

Allows you to add special visual effects to this NPC (such as creating dust), and modify the color in which the NPC is drawn.

Parameters
drawColor

◆ DrawHealthBar()

virtual ? bool ModNPC.DrawHealthBar ( byte  hbPosition,
ref float  scale,
ref Vector2  position 
)
virtual

Allows you to control how the health bar for this NPC is drawn. The hbPosition parameter is the same as Main.hbPosition; it determines whether the health bar gets drawn above or below the NPC by default. The scale parameter is the health bar's size. By default, it will be the normal 1f; most bosses set this to 1.5f. Return null to let the normal vanilla health-bar-drawing code to run. Return false to stop the health bar from being drawn. Return true to draw the health bar in the position specified by the position parameter (note that this is the world position, not screen position).

Parameters
hbPosition
scale
position
Returns

◆ DrawTownAttackGun()

virtual void ModNPC.DrawTownAttackGun ( ref Texture2D  item,
ref Rectangle  itemFrame,
ref float  scale,
ref int  horizontalHoldoutOffset 
)
virtual

Allows you to customize how this town NPC's weapon is drawn when this NPC is shooting (this NPC must have an attack type (NPCID.Sets.AttackType) of 1). scale is a multiplier for the item's drawing size, item is the Texture2D instance of the item to be drawn, itemFrame is the section of the texture to draw, and horizontalHoldoutOffset is how far away the item should be drawn from the NPC.
To use an actual item sprite, use

Main.GetItemDrawFrame(itemTypeHere, out item, out itemFrame); horizontalHoldoutOffset = (int)Main.DrawPlayerItemPos(1f, itemType).X - someOffsetHere

Parameters
item
itemFrame
scale
horizontalHoldoutOffset

◆ DrawTownAttackSwing()

virtual void ModNPC.DrawTownAttackSwing ( ref Texture2D  item,
ref Rectangle  itemFrame,
ref int  itemSize,
ref float  scale,
ref Vector2  offset 
)
virtual

Allows you to customize how this town NPC's weapon is drawn when this NPC is swinging it (this NPC must have an attack type (NPCID.Sets.AttackType) of 3). item is the Texture2D instance of the item to be drawn, itemFrame is the section of the texture to draw, itemSize is the width and height of the item's hitbox (the same values for TownNPCAttackSwing), scale is the multiplier for the item's drawing size, and offset is the offset from which to draw the item from its normal position. The item texture can be any texture, but if it is an item texture you can use Main.GetItemDrawFrame(int, out Texture2D, out Rectangle) to set item and itemFrame easily.

Parameters
item
itemFrame
itemSize
scale
offset

◆ EmoteBubblePosition()

virtual void ModNPC.EmoteBubblePosition ( ref Vector2  position,
ref SpriteEffects  spriteEffects 
)
virtual

Allows you to change the location and sprite direction of the emote bubble when anchored to an NPC.

Parameters
position
The default position is:
The X component is set to the NPC's Top + 75% of their width.
Code: entity.Top.X + ((-entity.direction * entity.width) * 0.75f)
The Y component is set to the NPC's Y position + 2 pixels. (Positive Y is down.)
Code: entity.VisualPosition.Y + 2f
(
See also
Entity.VisualPosition, Player.gfxOffY
is only used for the player for )
spriteEffectsAllows you to change which way the emote bubble is flipped.

◆ FindFrame()

virtual void ModNPC.FindFrame ( int  frameHeight)
virtual

Allows you to modify the frame from this NPC's texture that is drawn, which is necessary in order to animate NPCs.

Parameters
frameHeight

◆ GetAlpha()

virtual ? Color ModNPC.GetAlpha ( Color  drawColor)
virtual

Allows you to determine the color and transparency in which this NPC is drawn. Return null to use the default color (normally light and buff color). Returns null by default.

Parameters
drawColor
Returns

◆ GetChat()

virtual string ModNPC.GetChat ( )
virtual

Allows you to give this NPC a chat message when a player talks to it. By default returns something embarrassing.

Returns

◆ LoadData()

virtual void ModNPC.LoadData ( TagCompound  tag)
virtual

Allows you to load custom data that you have saved for this npc.

Parameters
tagThe tag.

◆ ModifyActiveShop()

virtual void ModNPC.ModifyActiveShop ( string  shopName,
Item[]  items 
)
virtual

Allows you to modify the contents of a shop whenever player opens it.
To create a shop, use AddShops
Note that for special shops like travelling merchant, the shopName may not correspond to a NPCShop in the NPCShopDatabase Also note that unused slots in items are null while Item.IsAir entries are entries that have a reserved slot (NPCShop.Entry.SlotReserved) but did not have their conditions met. These should not be overwritten.

Parameters
shopNameThe full name of the shop being opened. See NPCShopDatabase.GetShopName for the format.
itemsItems in the shop including 'air' items in empty slots.

◆ ModifyCollisionData()

virtual bool ModNPC.ModifyCollisionData ( Rectangle  victimHitbox,
ref int  immunityCooldownSlot,
ref MultipliableFloat  damageMultiplier,
ref Rectangle  npcHitbox 
)
virtual

Allows you to modify the NPC's

See also
ImmunityCooldownID

, damage multiplier, and hitbox. Useful for implementing dynamic damage hitboxes that change in dimensions or deal extra damage. Returns false to prevent vanilla code from running. Returns true by default.

Parameters
victimHitbox
immunityCooldownSlot
damageMultiplier
npcHitbox
Returns

◆ ModifyHitByItem()

virtual void ModNPC.ModifyHitByItem ( Player  player,
Item  item,
ref NPC.HitModifiers  modifiers 
)
virtual

Allows you to modify the damage, knockback, etc., that this NPC takes from a melee weapon.
Runs on the local client.

Parameters
player
item
modifiers

◆ ModifyHitByProjectile()

virtual void ModNPC.ModifyHitByProjectile ( Projectile  projectile,
ref NPC.HitModifiers  modifiers 
)
virtual

Allows you to modify the damage, knockback, etc., that this NPC takes from a projectile. This method is only called for the owner of the projectile, meaning that in multi-player, projectiles owned by a player call this method on that client, and projectiles owned by the server such as enemy projectiles call this method on the server.

Parameters
projectile
modifiers

◆ ModifyHitNPC()

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

Allows you to modify the damage, knockback, etc., that this NPC does to a friendly NPC.
Runs in single player or on the server.

Parameters
target
modifiers

◆ ModifyHitPlayer()

virtual void ModNPC.ModifyHitPlayer ( Player  target,
ref Player.HurtModifiers  modifiers 
)
virtual

Allows you to modify the damage, etc., that this NPC does to a player.
Runs on the local client.

Parameters
target
modifiers

◆ ModifyHoverBoundingBox()

virtual void ModNPC.ModifyHoverBoundingBox ( ref Rectangle  boundingBox)
virtual

Allows you to modify the bounding box for hovering over this NPC (affects things like whether or not its name is displayed).

Parameters
boundingBoxThe bounding box used for determining whether or not the NPC counts as being hovered over.

◆ ModifyIncomingHit()

virtual void ModNPC.ModifyIncomingHit ( ref NPC.HitModifiers  modifiers)
virtual

Allows you to use a custom damage formula for when this NPC takes damage from any source. For example, you can change the way defense works or use a different crit multiplier.

Parameters
modifiers

◆ ModifyNPCLoot()

virtual void ModNPC.ModifyNPCLoot ( NPCLoot  npcLoot)
virtual

Allows you to add and modify NPC loot tables to drop on death and to appear in the Bestiary.
The Basic NPC Drops and Loot 1.4 Guideexplains how to use this hook to modify NPC loot.
This hook only runs once during mod loading, any dynamic behavior must be contained in the rules themselves.

Parameters
npcLootA reference to the item drop database for this npc type

◆ OnCaughtBy()

virtual void ModNPC.OnCaughtBy ( Player  player,
Item  item,
bool  failed 
)
virtual

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

Parameters
playerThe player attempting to catch this NPC.
itemThe item used to catch this NPC.
failedWhether or not this NPC has been successfully caught.

◆ OnChatButtonClicked()

virtual void ModNPC.OnChatButtonClicked ( bool  firstButton,
ref string  shopName 
)
virtual

Allows you to make something happen whenever a button is clicked on this NPC's chat window. The firstButton parameter tells whether the first button or second button (button and button2 from SetChatButtons) was clicked. Set the shopName parameter to "Shop" to open this NPC's shop.

Parameters
firstButton
shopName

◆ OnGoToStatue()

virtual void ModNPC.OnGoToStatue ( bool  toKingStatue)
virtual

Allows you to make things happen when this NPC teleports to a King or Queen statue. This method is only called server side.

Parameters
toKingStatueWhether the NPC was teleported to a King or Queen statue.

◆ OnHitByItem()

virtual void ModNPC.OnHitByItem ( Player  player,
Item  item,
NPC.HitInfo  hit,
int  damageDone 
)
virtual

Allows you to create special effects when this NPC is hit by a melee weapon.
Runs on the client or server doing the damage.

Parameters
player
item
hit
damageDone

◆ OnHitByProjectile()

virtual void ModNPC.OnHitByProjectile ( Projectile  projectile,
NPC.HitInfo  hit,
int  damageDone 
)
virtual

Allows you to create special effects when this NPC is hit by a projectile.

Parameters
projectile
hit
damageDone

◆ OnHitNPC()

virtual void ModNPC.OnHitNPC ( NPC  target,
NPC.HitInfo  hit 
)
virtual

Allows you to create special effects when this NPC hits a friendly NPC.
Runs in single player or on the server.

Parameters
target
hit

◆ OnHitPlayer()

virtual void ModNPC.OnHitPlayer ( Player  target,
Player.HurtInfo  hurtInfo 
)
virtual

Allows you to create special effects when this NPC hits a player (for example, inflicting debuffs).
Runs on the local client.

Parameters
target
hurtInfo

◆ PartyHatPosition()

virtual void ModNPC.PartyHatPosition ( ref Vector2  position,
ref SpriteEffects  spriteEffects 
)
virtual


Allows you to fully control the location of the party and sprite direction of the party while an NPC is wearing it.

See also
NPCID.Sets.HatOffsetY, NPCID.Sets.NPCFramingGroup

can be used instead of this hook for a constant Y offset.
can be additionally be used for the Y offset for the Town NPC's animations.

Parameters
position
This is the final position right before the party hat gets drawn which is generally the top center of the NPC's hitbox.
See also
NPCID.Sets.HatOffsetY, NPCID.Sets.NPCFramingGroup
and are already taken into account.
spriteEffectsAllows you to change which way the party hat is flipped.

◆ PickEmote()

virtual ? int ModNPC.PickEmote ( Player  closestPlayer,
List< int >  emoteList,
WorldUIAnchor  otherAnchor 
)
virtual

Allows you to change the emote that the NPC will pick

Parameters
closestPlayerThe Player closest to the NPC. You can check the biome the player is in and let the NPC pick the emote that corresponds to the biome.
emoteListA list of emote IDs from which the NPC will randomly select one
otherAnchorA WorldUIAnchor instance that indicates the target of this emote conversation. Use this to get the instance of the NPC or Player this NPC is talking to.
Returns
Return null to use vanilla mechanic (pick one from the list), otherwise pick the emote by the returned ID. Returning -1 will prevent the emote from being used. Returns null by default

◆ PostDraw()

virtual void ModNPC.PostDraw ( SpriteBatch  spriteBatch,
Vector2  screenPos,
Color  drawColor 
)
virtual

Allows you to draw things in front of this NPC. Substract screenPos from the draw position before drawing. This method is called even if PreDraw returns false.

Parameters
spriteBatchThe spritebatch to draw on
screenPosThe screen position used to translate world position into screen position
drawColorThe color the NPC is drawn in

◆ PreAI()

virtual bool ModNPC.PreAI ( )
virtual

Allows you to determine how this NPC behaves. Return false to stop the vanilla AI and the AI hook from being run. Returns true by default.

Returns

◆ PreDraw()

virtual bool ModNPC.PreDraw ( SpriteBatch  spriteBatch,
Vector2  screenPos,
Color  drawColor 
)
virtual

Allows you to draw things behind this NPC, or to modify the way this NPC is drawn. Substract screenPos from the draw position before drawing. Return false to stop the game from drawing the NPC (useful if you're manually drawing the NPC). Returns true by default.

Parameters
spriteBatchThe spritebatch to draw on
screenPosThe screen position used to translate world position into screen position
drawColorThe color the NPC is drawn in
Returns

◆ PreKill()

virtual bool ModNPC.PreKill ( )
virtual

Allows you to determine whether or not this NPC will do anything upon death (besides dying). Returns true by default.

Returns

◆ ReceiveExtraAI()

virtual void ModNPC.ReceiveExtraAI ( BinaryReader  reader)
virtual

Use this to receive information that was sent in SendExtraAI.
Called whenever MessageID.SyncNPC is successfully received.
Only called on the client.

Parameters
readerThe reader.

◆ Register()

sealed override void ModNPC.Register ( )
protectedvirtual

If you make a new ModType, seal this override.

Implements ModType< NPC, ModNPC >.

◆ SaveData()

virtual void ModNPC.SaveData ( TagCompound  tag)
virtual

Allows you to save custom data for the given item. Allows you to save custom data for the given npc.

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.
NOTE: The npc may be saved even if NeedSaving returns false and this is not a townNPC, if another mod returns true on NeedSaving.

Parameters
tagThe TagCompound to save data into. Note that this is always empty by default, and is provided as an argument

◆ SendExtraAI()

virtual void ModNPC.SendExtraAI ( BinaryWriter  writer)
virtual

If you are storing AI information outside of the NPC.ai array, use this to send that AI information between clients and servers, which will be handled in ReceiveExtraAI.
Called whenever MessageID.SyncNPC is successfully sent, for example on NPC creation, on player join, or whenever NPC.netUpdate is set to true in the update loop for that tick.
Only called on the server.

Parameters
writerThe writer.

◆ SetBestiary()

virtual void ModNPC.SetBestiary ( BestiaryDatabase  database,
BestiaryEntry  bestiaryEntry 
)
virtual

Allows you to set an NPC's information in the Bestiary.

Parameters
database
bestiaryEntry

◆ SetChatButtons()

virtual void ModNPC.SetChatButtons ( ref string  button,
ref string  button2 
)
virtual

Allows you to set the text for the buttons that appear on this NPC's chat window. A parameter left as an empty string will not be included as a button on the chat window.

Parameters
button
button2

◆ SetNPCNameList()

virtual List< string > ModNPC.SetNPCNameList ( )
virtual

Allows you to give a list of names this NPC can be given on spawn.
By default, returns a blank list, which means the NPC will simply use its type name as its given name when prompted.

Returns

◆ SetupContent()

sealed override void ModNPC.SetupContent ( )
virtual

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

Reimplemented from ModType< NPC, ModNPC >.

◆ SpawnChance()

virtual float ModNPC.SpawnChance ( NPCSpawnInfo  spawnInfo)
virtual

Whether or not this NPC can spawn with the given spawning conditions. Return the weight for the chance of this NPC to spawn compared to vanilla mobs. All vanilla mobs combined have a total weight of 1. Returns 0 by default, which disables natural spawning. Remember to always use spawnInfo.player and not Main.LocalPlayer when checking Player or ModPlayer fields, otherwise your mod won't work in Multiplayer.

Parameters
spawnInfo
Returns

◆ SpawnNPC()

virtual int ModNPC.SpawnNPC ( int  tileX,
int  tileY 
)
virtual

Allows you to customize how this NPC is created when it naturally spawns (for example, its position or ai array). Return the return value of NPC.NewNPC. By default this method spawns this NPC on top of the tile at the given coordinates.

Parameters
tileX
tileY
Returns

◆ SpecialOnKill()

virtual bool ModNPC.SpecialOnKill ( )
virtual

Allows you to call OnKill on your own when the NPC dies, rather then letting vanilla call it on its own. Returns false by default.

Returns
Return true to stop vanilla from calling OnKill on its own. Do this if you call OnKill yourself.

◆ TownNPCAttackCooldown()

virtual void ModNPC.TownNPCAttackCooldown ( ref int  cooldown,
ref int  randExtraCooldown 
)
virtual

Allows you to determine the cooldown between each of this town NPC's attack. The cooldown will be a number greater than or equal to the first parameter, and less then the sum of the two parameters.

Parameters
cooldown
randExtraCooldown

◆ TownNPCAttackMagic()

virtual void ModNPC.TownNPCAttackMagic ( ref float  auraLightMultiplier)
virtual

Allows you to control the brightness of the light emitted by this town NPC's aura when it performs a magic attack. Only used when the town NPC has an attack type (NPCID.Sets.AttackType) of 2 (magic)

Parameters
auraLightMultiplier

◆ TownNPCAttackProj()

virtual void ModNPC.TownNPCAttackProj ( ref int  projType,
ref int  attackDelay 
)
virtual

Allows you to determine the projectile type of this town NPC's attack, and how long it takes for the projectile to actually appear. This hook is only used when the town NPC has an attack type (NPCID.Sets.AttackType) of 0 (throwing), 1 (shooting), or 2 (magic).

Parameters
projType
attackDelay

◆ TownNPCAttackProjSpeed()

virtual void ModNPC.TownNPCAttackProjSpeed ( ref float  multiplier,
ref float  gravityCorrection,
ref float  randomOffset 
)
virtual

Allows you to determine the speed at which this town NPC throws a projectile when it attacks. Multiplier is the speed of the projectile, gravityCorrection is how much extra the projectile gets thrown upwards, and randomOffset allows you to randomize the projectile's velocity in a square centered around the original velocity. This hook is only used when the town NPC has an attack type (NPCID.Sets.AttackType) of 0 (throwing), 1 (shooting), or 2 (magic).

Parameters
multiplier
gravityCorrection
randomOffset

◆ TownNPCAttackShoot()

virtual void ModNPC.TownNPCAttackShoot ( ref bool  inBetweenShots)
virtual

Allows you to tell the game that this town NPC has already created a projectile and will still create more projectiles as part of a single attack so that the game can animate the NPC's attack properly. Only used when the town NPC has an attack type (NPCID.Sets.AttackType) of 1 (shooting).

Parameters
inBetweenShots

◆ TownNPCAttackStrength()

virtual void ModNPC.TownNPCAttackStrength ( ref int  damage,
ref float  knockback 
)
virtual

Allows you to determine the damage and knockback of this town NPC's attack before the damage is scaled. (More information on scaling in GlobalNPC.BuffTownNPCs.)

Parameters
damage
knockback

◆ TownNPCAttackSwing()

virtual void ModNPC.TownNPCAttackSwing ( ref int  itemWidth,
ref int  itemHeight 
)
virtual

Allows you to determine the width and height of the item this town NPC swings when it attacks, which controls the range of this NPC's swung weapon. Only used when the town NPC has an attack type (NPCID.Sets.AttackType) of 3 (swinging).

Parameters
itemWidth
itemHeight

◆ UpdateLifeRegen()

virtual void ModNPC.UpdateLifeRegen ( ref int  damage)
virtual

Allows you to make the NPC either regenerate health or take damage over time by setting NPC.lifeRegen. This is useful for implementing damage over time debuffs such as BuffID.Poisoned or BuffID.OnFire. Regeneration or damage will occur at a rate of half of NPC.lifeRegen per second. Essentially, modders implementing damage over time debuffs should subtract from NPC.lifeRegen a number that is twice as large as the intended damage per second. See DamageOverTimeGlobalNPC.csfor an example of this. The damage parameter is the number that appears above the NPC's head if it takes damage over time. Multiple debuffs work together by following some conventions: NPC.lifeRegen should not be assigned a number, rather it should be subtracted from. damage should only be assigned if the intended popup text is larger then its current value.

Parameters
damage

◆ UsesPartyHat()

virtual bool ModNPC.UsesPartyHat ( )
virtual

Allows you to determine whether this town NPC wears a party hat during a party. Returns true by default.

Returns

Property Documentation

◆ LocalizationCategory

virtual string ModNPC.LocalizationCategory
get

The category used by this modded content for use in localization keys. Localization keys follow the pattern of "Mods.{ModName}.{Category}.{ContentName}.{DataName}". The Localization wiki pageexplains how custom ModType classes can utilize this.

Implements ILocalizedModType.

◆ Music

int ModNPC.Music = -1
getset

The ID of the music that plays when this NPC is on or near the screen. Defaults to -1, which means music plays normally.

Note: This property gets ignored if the game would not play music for this NPC by default (i.e. it's not a boss, or it doesn't belong to an invasion)

Will be superseded by ModSceneEffect. Kept for legacy.

◆ SceneEffectPriority

SceneEffectPriority ModNPC.SceneEffectPriority = SceneEffectPriority.BossLow
getset

The priority of the music that plays when this NPC is on or near the screen.

Will be superseded by ModSceneEffect. Kept for legacy.