tModLoader v0.11.8.9
A mod to make and play Terraria mods
Terraria.ModLoader.ModNPC Class Reference

This class serves as a place for you to place all your properties and hooks for each NPC. Create instances of ModNPC (preferably overriding this class) to pass as parameters to Mod.AddNPC. More...

+ Collaboration diagram for Terraria.ModLoader.ModNPC:

Public Member Functions

 ModNPC ()
 ModNPC constructor. More...
 
virtual void AI ()
 Allows you to determine how this NPC behaves. This will only be called if PreAI returns true. More...
 
virtual bool Autoload (ref string name)
 Allows you to automatically load an NPC instead of using Mod.AddNPC. Return true to allow autoloading; by default returns the mod's autoload property. Name is initialized to the overriding class name, texture is initialized to the namespace and overriding class name with periods replaced with slashes, and altTextures is initialized to null. Use this method to either force or stop an autoload, or to change the default display name. More...
 
virtual void AutoStaticDefaults ()
 Automatically sets certain static defaults. Override this if you do not want the properties to be set for you. More...
 
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 this 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 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 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 CanGoToStatue (bool toKingStatue)
 Whether this NPC can be telported 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 true to allow hitting the target, return false to block this NPC 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 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 to use (-1, 0, or 1), and defaults to -1. More...
 
virtual bool CanTownNPCSpawn (int numTownNPCs, int money)
 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. 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. More...
 
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 ModNPC Clone ()
 Returns a clone of this ModNPC. Allows you to decide which fields of your ModNPC class are copied over when a new NPC is created. By default this will return a memberwise clone; you will want to override this if your ModNPC contains object references. Only called if CloneNewInstances is set to true. 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 float scale, ref int item, ref int closeness)
 Allows you to customize how this town NPC's weapon is drawn when this NPC is shooting (this NPC must have an attack type of 1). Scale is a multiplier for the item's drawing size, item is the ID of the item to be drawn, and closeness is how close the item should be drawn to the NPC. More...
 
virtual void DrawTownAttackSwing (ref Texture2D item, 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 of 3). Item is the Texture2D instance of the item to be drawn (use Main.itemTexture[id of item]), 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. 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 (int hitDirection, double damage)
 Allows you to make things happen whenever this NPC is hit, such as creating dust or gores. This hook is client side. 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. More...
 
virtual void ModifyHitByItem (Player player, Item item, ref int damage, ref float knockback, ref bool crit)
 Allows you to modify the damage, knockback, etc., that this NPC takes from a melee weapon. More...
 
virtual void ModifyHitByProjectile (Projectile projectile, ref int damage, ref float knockback, ref bool crit, ref int hitDirection)
 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 int damage, ref float knockback, ref bool crit)
 Allows you to modify the damage, knockback, etc., that this NPC does to a friendly NPC. More...
 
virtual void ModifyHitPlayer (Player target, ref int damage, ref bool crit)
 Allows you to modify the damage, etc., that this NPC does to a player. More...
 
virtual ModNPC NewInstance (NPC npcClone)
 Create a new instance of this ModNPC for an NPC instance. Called at the end of NPC.SetDefaults. If CloneNewInstances is true, just calls Clone() Otherwise calls the default constructor and copies fields More...
 
virtual void NPCLoot ()
 Allows you to make things happen when this NPC dies (for example, dropping items and setting ModWorld fields). This hook runs on the server/single player. For client-side effects, such as dust, gore, and sounds, see HitEffect More...
 
virtual void OnCatchNPC (Player player, Item item)
 Allows you to make things happen when this NPC is caught. Ran Serverside More...
 
virtual void OnChatButtonClicked (bool firstButton, ref bool shop)
 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 shop parameter to true 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, int damage, float knockback, bool crit)
 Allows you to create special effects when this NPC is hit by a melee weapon. More...
 
virtual void OnHitByProjectile (Projectile projectile, int damage, float knockback, bool crit)
 Allows you to create special effects when this NPC is hit by a projectile. More...
 
virtual void OnHitNPC (NPC target, int damage, float knockback, bool crit)
 Allows you to create special effects when this NPC hits a friendly NPC. More...
 
virtual void OnHitPlayer (Player target, int damage, bool crit)
 Allows you to create special effects when this NPC hits a player (for example, inflicting debuffs). More...
 
virtual void PostAI ()
 
virtual void PostDraw (SpriteBatch spriteBatch, Color drawColor)
 Allows you to draw things in front of this NPC. 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, Color drawColor)
 Allows you to draw things behind this NPC, or to modify the way this NPC is drawn. 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 PreNPCLoot ()
 Allows you to determine whether or not this NPC will drop anything at all. Return false to stop the NPC from dropping anything. Returns true by default. More...
 
virtual void ReceiveExtraAI (BinaryReader reader)
 Use this to receive information that was sent in SendExtraAI. 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.) More...
 
virtual void ScaleExpertStats (int numPlayers, float bossLifeScale)
 Allows you to customize this NPC's stats in expert mode. This is useful because expert mode's doubling of damage and life might be too much sometimes (for example, with bosses). Also useful for scaling life with the number of players in the world. 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. 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. More...
 
virtual void SetStaticDefaults ()
 Allows you to set all your NPC's static properties, such as names/translations and the arrays in NPCID.Sets. More...
 
virtual void SetupShop (Chest shop, ref int nextSlot)
 Allows you to add items to this NPC's shop. Add an item by setting the defaults of shop.item[nextSlot] then incrementing nextSlot. In the end, nextSlot must have a value of 1 greater than the highest index in shop.item that contains an item. 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 SpecialNPCLoot ()
 Allows you to call NPCLoot on your own when the NPC dies, rather then letting vanilla call it on its own. Useful for things like dropping loot from the nearest segment of a worm boss. Returns false by default. More...
 
virtual bool StrikeNPC (ref double damage, int defense, ref float knockback, int hitDirection, ref bool crit)
 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. Return false to stop the game from running the vanilla damage formula; returns true 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 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 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 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 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 of 3 (swinging). More...
 
virtual string TownNPCName ()
 Allows you to give this town NPC any name when it spawns. By default returns something embarrassing. More...
 
virtual void UpdateLifeRegen (ref int damage)
 Allows you to make the NPC either regenerate health or take damage over time by setting npc.lifeRegen. Regeneration or damage will occur at a rate of half of npc.lifeRegen per second. The damage parameter is the number that appears above the NPC's head if it takes damage over time. 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 Attributes

int aiType = 0
 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. More...
 
int animationType = 0
 Determines which type of vanilla NPC this ModNPC will copy the animation (FindFrame) of. Leave as 0 to not copy any animation. Defaults to 0. More...
 
int banner = 0
 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. More...
 
int bannerItem = 0
 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. More...
 
int bossBag = -1
 The item type of the boss bag that is dropped when DropBossBags is called for this NPC. More...
 
float drawOffsetY = 0f
 The vertical offset used for drawing this NPC. Defaults to 0. More...
 
int music = -1
 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...
 
MusicPriority musicPriority = MusicPriority.BossLow
 The priority of the music that plays when this NPC is on or near the screen. More...
 

Properties

virtual string[] AltTextures [get]
 The file names of this NPC's alternate texture files, if any. This will be used in the given AutoStaticDefaults. More...
 
virtual string BossHeadTexture [get]
 This file name of this NPC's boss head texture file, to be used in autoloading. More...
 
virtual bool CloneNewInstances [get]
 Whether instances of this ModNPC are created through a memberwise clone or its constructor. Defaults to false. More...
 
ModTranslation DisplayName [get, set]
 The translations for the display name of this NPC. More...
 
virtual string HeadTexture [get]
 The file name of this NPC's head texture file, to be used in autoloading. More...
 
Mod mod [get, set]
 The mod that added this ModNPC. More...
 
string Name [get, set]
 The internal name of this NPC. More...
 
NPC npc [get, set]
 The NPC object that this ModNPC controls. More...
 
virtual string Texture [get]
 The file name of this NPC's texture file in the mod loader's file space. More...
 

Detailed Description

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

Definition at line 14 of file ModNPC.cs.

Constructor & Destructor Documentation

◆ ModNPC()

Terraria.ModLoader.ModNPC.ModNPC ( )

ModNPC constructor.

Definition at line 111 of file ModNPC.cs.

111 {
112 npc = new NPC();
113 npc.modNPC = this;
114 }
NPC npc
The NPC object that this ModNPC controls.
Definition: ModNPC.cs:21

References Terraria.ModLoader.ModNPC.npc.

Referenced by Terraria.ModLoader.ModNPC.NewInstance().

+ Here is the caller graph for this function:

Member Function Documentation

◆ AI()

virtual void Terraria.ModLoader.ModNPC.AI ( )
virtual

Allows you to determine how this NPC behaves. This will only be called if PreAI returns true.

Definition at line 247 of file ModNPC.cs.

247 {
248 }

◆ Autoload()

virtual bool Terraria.ModLoader.ModNPC.Autoload ( ref string  name)
virtual

Allows you to automatically load an NPC instead of using Mod.AddNPC. Return true to allow autoloading; by default returns the mod's autoload property. Name is initialized to the overriding class name, texture is initialized to the namespace and overriding class name with periods replaced with slashes, and altTextures is initialized to null. Use this method to either force or stop an autoload, or to change the default display name.

Parameters
name
Returns

Definition at line 121 of file ModNPC.cs.

121 {
122 return mod.Properties.Autoload;
123 }
ModProperties Properties
Definition: Mod.cs:52
Mod mod
The mod that added this ModNPC.
Definition: ModNPC.cs:29
bool Autoload
Whether or not this mod will autoload content by default. Autoloading content means you do not need t...

References Terraria.ModLoader.ModProperties.Autoload, Terraria.ModLoader.ModNPC.mod, and Terraria.ModLoader.Mod.Properties.

Referenced by Terraria.ModLoader.Mod.AutoloadNPC().

+ Here is the caller graph for this function:

◆ AutoStaticDefaults()

virtual void Terraria.ModLoader.ModNPC.AutoStaticDefaults ( )
virtual

Automatically sets certain static defaults. Override this if you do not want the properties to be set for you.

Definition at line 189 of file ModNPC.cs.

189 {
190 Main.npcTexture[npc.type] = ModContent.GetTexture(Texture);
191 if (banner != 0 && bannerItem != 0) {
192 NPCLoader.bannerToItem[banner] = bannerItem;
193 }
194 else if (banner != 0 || bannerItem != 0) {
195 Logging.tML.Warn(Language.GetTextValue("tModLoader.LoadWarningBannerOrBannerItemNotSet", mod.DisplayName, Name));
196 }
197 if (npc.lifeMax > 32767 || npc.boss) {
198 Main.npcLifeBytes[npc.type] = 4;
199 }
200 else if (npc.lifeMax > 127) {
201 Main.npcLifeBytes[npc.type] = 2;
202 }
203 else {
204 Main.npcLifeBytes[npc.type] = 1;
205 }
206
207 string[] altTextures = AltTextures;
208 int altTextureCount = altTextures.Length;
209 NPCID.Sets.ExtraTextureCount[npc.type] = altTextureCount;
210 Main.npcAltTextures[npc.type] = new Texture2D[altTextureCount + 1];
211 if (altTextureCount > 0) {
212 Main.npcAltTextures[npc.type][0] = Main.npcTexture[npc.type];
213 }
214 for (int k = 1; k <= altTextureCount; k++) {
215 Main.npcAltTextures[npc.type][k] = ModContent.GetTexture(altTextures[k - 1]);
216 }
217
219 DisplayName.SetDefault(Regex.Replace(Name, "([A-Z])", " $1").Trim());
220 }
string DisplayName
The display name of this mod in the Mods menu.
Definition: Mod.cs:60
int banner
The type of NPC that this NPC will be considered as when determining banner drops and banner bonuses....
Definition: ModNPC.cs:100
virtual string Texture
The file name of this NPC's texture file in the mod loader's file space.
Definition: ModNPC.cs:53
int bannerItem
The type of the item this NPC drops for every 50 times it is defeated. For any ModNPC whose banner fi...
Definition: ModNPC.cs:106
string Name
The internal name of this NPC.
Definition: ModNPC.cs:37
ModTranslation DisplayName
The translations for the display name of this NPC.
Definition: ModNPC.cs:45
virtual string[] AltTextures
The file names of this NPC's alternate texture files, if any. This will be used in the given AutoStat...
Definition: ModNPC.cs:57

References Terraria.ModLoader.ModNPC.AltTextures, Terraria.ModLoader.ModNPC.banner, Terraria.ModLoader.ModNPC.bannerItem, Terraria.ModLoader.Mod.DisplayName, Terraria.ModLoader.ModNPC.DisplayName, Terraria.ModLoader.ModContent.GetTexture(), Terraria.ModLoader.ModTranslation.IsDefault(), Terraria.ModLoader.ModNPC.mod, Terraria.ModLoader.ModNPC.Name, Terraria.ModLoader.ModNPC.npc, Terraria.ModLoader.ModTranslation.SetDefault(), and Terraria.ModLoader.ModNPC.Texture.

+ Here is the call graph for this function:

◆ BossHeadRotation()

virtual void Terraria.ModLoader.ModNPC.BossHeadRotation ( ref float  rotation)
virtual

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

Parameters
rotation

Definition at line 487 of file ModNPC.cs.

487 {
488 }

◆ BossHeadSlot()

virtual void Terraria.ModLoader.ModNPC.BossHeadSlot ( ref int  index)
virtual

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

Parameters
indexThe index for NPCID.Sets.BossHeadTextures

Definition at line 480 of file ModNPC.cs.

480 {
481 }

◆ BossHeadSpriteEffects()

virtual void Terraria.ModLoader.ModNPC.BossHeadSpriteEffects ( ref SpriteEffects  spriteEffects)
virtual

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

Parameters
spriteEffects

Definition at line 494 of file ModNPC.cs.

494 {
495 }

◆ BossLoot()

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

Definition at line 341 of file ModNPC.cs.

341 {
342 }

◆ CanBeHitByItem()

virtual ? bool Terraria.ModLoader.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

Definition at line 407 of file ModNPC.cs.

407 {
408 return null;
409 }

◆ CanBeHitByProjectile()

virtual ? bool Terraria.ModLoader.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

Definition at line 438 of file ModNPC.cs.

438 {
439 return null;
440 }

◆ CanChat()

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

Returns

Definition at line 612 of file ModNPC.cs.

612 {
613 return npc.townNPC;
614 }

References Terraria.ModLoader.ModNPC.npc.

◆ CanGoToStatue()

virtual bool Terraria.ModLoader.ModNPC.CanGoToStatue ( bool  toKingStatue)
virtual

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

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

Definition at line 652 of file ModNPC.cs.

652 {
653 return false;
654 }

◆ CanHitNPC()

virtual ? bool Terraria.ModLoader.ModNPC.CanHitNPC ( NPC  target)
virtual

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

Parameters
target
Returns

Definition at line 377 of file ModNPC.cs.

377 {
378 return null;
379 }

◆ CanHitPlayer()

virtual bool Terraria.ModLoader.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 to use (-1, 0, or 1), and defaults to -1.

Parameters
target
cooldownSlot
Returns

Definition at line 350 of file ModNPC.cs.

350 {
351 return true;
352 }

◆ CanTownNPCSpawn()

virtual bool Terraria.ModLoader.ModNPC.CanTownNPCSpawn ( int  numTownNPCs,
int  money 
)
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.

Parameters
numTownNPCs
money
Returns

Definition at line 576 of file ModNPC.cs.

576 {
577 return false;
578 }

Referenced by Terraria.ModLoader.NPCLoader.CanTownNPCSpawn().

+ Here is the caller graph for this function:

◆ CheckActive()

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

Definition at line 294 of file ModNPC.cs.

294 {
295 return true;
296 }

◆ CheckConditions()

virtual bool Terraria.ModLoader.ModNPC.CheckConditions ( int  left,
int  right,
int  top,
int  bottom 
)
virtual

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.

Parameters
left
right
top
bottom
Returns

Definition at line 588 of file ModNPC.cs.

588 {
589 return true;
590 }

Referenced by Terraria.ModLoader.NPCLoader.CheckConditions().

+ Here is the caller graph for this function:

◆ CheckDead()

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

Definition at line 302 of file ModNPC.cs.

302 {
303 return true;
304 }

◆ Clone()

virtual ModNPC Terraria.ModLoader.ModNPC.Clone ( )
virtual

Returns a clone of this ModNPC. Allows you to decide which fields of your ModNPC class are copied over when a new NPC is created. By default this will return a memberwise clone; you will want to override this if your ModNPC contains object references. Only called if CloneNewInstances is set to true.

Referenced by Terraria.ModLoader.ModNPC.NewInstance().

+ Here is the caller graph for this function:

◆ DrawBehind()

virtual void Terraria.ModLoader.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
npc
index

Definition at line 536 of file ModNPC.cs.

537 {
538 }

◆ DrawEffects()

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

Definition at line 510 of file ModNPC.cs.

510 {
511 }

◆ DrawHealthBar()

virtual ? bool Terraria.ModLoader.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

Definition at line 547 of file ModNPC.cs.

547 {
548 return null;
549 }

◆ DrawTownAttackGun()

virtual void Terraria.ModLoader.ModNPC.DrawTownAttackGun ( ref float  scale,
ref int  item,
ref int  closeness 
)
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 of 1). Scale is a multiplier for the item's drawing size, item is the ID of the item to be drawn, and closeness is how close the item should be drawn to the NPC.

Parameters
scale
item
closeness

Definition at line 725 of file ModNPC.cs.

725 {
726 }

◆ DrawTownAttackSwing()

virtual void Terraria.ModLoader.ModNPC.DrawTownAttackSwing ( ref Texture2D  item,
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 of 3). Item is the Texture2D instance of the item to be drawn (use Main.itemTexture[id of item]), 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.

Parameters
item
itemSize
scale
offset

Definition at line 735 of file ModNPC.cs.

735 {
736 }

◆ FindFrame()

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

Definition at line 272 of file ModNPC.cs.

272 {
273 }

◆ GetAlpha()

virtual ? Color Terraria.ModLoader.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

Definition at line 502 of file ModNPC.cs.

502 {
503 return null;
504 }

◆ GetChat()

virtual string Terraria.ModLoader.ModNPC.GetChat ( )
virtual

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

Returns

Definition at line 620 of file ModNPC.cs.

620 {
621 return Language.GetTextValue("tModLoader.DefaultTownNPCChat");
622 }

◆ HitEffect()

virtual void Terraria.ModLoader.ModNPC.HitEffect ( int  hitDirection,
double  damage 
)
virtual

Allows you to make things happen whenever this NPC is hit, such as creating dust or gores. This hook is client side. 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.

Parameters
hitDirection
damage

Definition at line 280 of file ModNPC.cs.

280 {
281 }

◆ ModifyHitByItem()

virtual void Terraria.ModLoader.ModNPC.ModifyHitByItem ( Player  player,
Item  item,
ref int  damage,
ref float  knockback,
ref bool  crit 
)
virtual

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

Parameters
player
item
damage
knockback
crit

Definition at line 419 of file ModNPC.cs.

419 {
420 }

◆ ModifyHitByProjectile()

virtual void Terraria.ModLoader.ModNPC.ModifyHitByProjectile ( Projectile  projectile,
ref int  damage,
ref float  knockback,
ref bool  crit,
ref int  hitDirection 
)
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
damage
knockback
crit
hitDirection

Definition at line 450 of file ModNPC.cs.

450 {
451 }

◆ ModifyHitNPC()

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

Allows you to modify the damage, knockback, etc., that this NPC does to a friendly NPC.

Parameters
target
damage
knockback
crit

Definition at line 388 of file ModNPC.cs.

388 {
389 }

◆ ModifyHitPlayer()

virtual void Terraria.ModLoader.ModNPC.ModifyHitPlayer ( Player  target,
ref int  damage,
ref bool  crit 
)
virtual

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

Parameters
target
damage
crit

Definition at line 360 of file ModNPC.cs.

360 {
361 }

◆ NewInstance()

virtual ModNPC Terraria.ModLoader.ModNPC.NewInstance ( NPC  npcClone)
virtual

Create a new instance of this ModNPC for an NPC instance. Called at the end of NPC.SetDefaults. If CloneNewInstances is true, just calls Clone() Otherwise calls the default constructor and copies fields

Definition at line 153 of file ModNPC.cs.

153 {
154 if (CloneNewInstances) {
155 ModNPC clone = Clone();
156 clone.npc = npcClone;
157 return clone;
158 }
159
160 ModNPC copy = (ModNPC)Activator.CreateInstance(GetType());
161 copy.npc = npcClone;
162 copy.mod = mod;
163 copy.Name = Name;
164 copy.aiType = aiType;
165 copy.animationType = animationType;
166 copy.bossBag = bossBag;
167 copy.music = music;
168 copy.drawOffsetY = drawOffsetY;
169 copy.banner = banner;
170 copy.bannerItem = bannerItem;
171 return copy;
172 }
virtual ModNPC Clone()
Returns a clone of this ModNPC. Allows you to decide which fields of your ModNPC class are copied ove...
virtual bool CloneNewInstances
Whether instances of this ModNPC are created through a memberwise clone or its constructor....
Definition: ModNPC.cs:137
int animationType
Determines which type of vanilla NPC this ModNPC will copy the animation (FindFrame) of....
Definition: ModNPC.cs:73
float drawOffsetY
The vertical offset used for drawing this NPC. Defaults to 0.
Definition: ModNPC.cs:92
int aiType
Determines which type of vanilla NPC this ModNPC will copy the behavior (AI) of. Leave as 0 to not co...
Definition: ModNPC.cs:69
ModNPC()
ModNPC constructor.
Definition: ModNPC.cs:111
int music
The ID of the music that plays when this NPC is on or near the screen. Defaults to -1,...
Definition: ModNPC.cs:82
int bossBag
The item type of the boss bag that is dropped when DropBossBags is called for this NPC.
Definition: ModNPC.cs:77

References Terraria.ModLoader.ModNPC.ModNPC(), Terraria.ModLoader.ModNPC.aiType, Terraria.ModLoader.ModNPC.animationType, Terraria.ModLoader.ModNPC.banner, Terraria.ModLoader.ModNPC.bannerItem, Terraria.ModLoader.ModNPC.bossBag, Terraria.ModLoader.ModNPC.Clone(), Terraria.ModLoader.ModNPC.CloneNewInstances, Terraria.ModLoader.ModNPC.drawOffsetY, Terraria.ModLoader.ModNPC.mod, Terraria.ModLoader.ModNPC.music, and Terraria.ModLoader.ModNPC.Name.

+ Here is the call graph for this function:

◆ NPCLoot()

virtual void Terraria.ModLoader.ModNPC.NPCLoot ( )
virtual

Allows you to make things happen when this NPC dies (for example, dropping items and setting ModWorld fields). This hook runs on the server/single player. For client-side effects, such as dust, gore, and sounds, see HitEffect

Definition at line 325 of file ModNPC.cs.

325 {
326 }

◆ OnCatchNPC()

virtual void Terraria.ModLoader.ModNPC.OnCatchNPC ( Player  player,
Item  item 
)
virtual

Allows you to make things happen when this NPC is caught. Ran Serverside

Parameters
playerThe player catching this NPC
itemThe item that will be spawned

Definition at line 333 of file ModNPC.cs.

333 {
334 }

◆ OnChatButtonClicked()

virtual void Terraria.ModLoader.ModNPC.OnChatButtonClicked ( bool  firstButton,
ref bool  shop 
)
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 shop parameter to true to open this NPC's shop.

Parameters
firstButton
shop

Definition at line 637 of file ModNPC.cs.

637 {
638 }

◆ OnGoToStatue()

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

Definition at line 661 of file ModNPC.cs.

661 {
662 }

◆ OnHitByItem()

virtual void Terraria.ModLoader.ModNPC.OnHitByItem ( Player  player,
Item  item,
int  damage,
float  knockback,
bool  crit 
)
virtual

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

Parameters
player
item
damage
knockback
crit

Definition at line 430 of file ModNPC.cs.

430 {
431 }

◆ OnHitByProjectile()

virtual void Terraria.ModLoader.ModNPC.OnHitByProjectile ( Projectile  projectile,
int  damage,
float  knockback,
bool  crit 
)
virtual

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

Parameters
projectile
damage
knockback
crit

Definition at line 460 of file ModNPC.cs.

460 {
461 }

◆ OnHitNPC()

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

Allows you to create special effects when this NPC hits a friendly NPC.

Parameters
target
damage
knockback
crit

Definition at line 398 of file ModNPC.cs.

398 {
399 }

◆ OnHitPlayer()

virtual void Terraria.ModLoader.ModNPC.OnHitPlayer ( Player  target,
int  damage,
bool  crit 
)
virtual

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

Parameters
target
damage
crit

Definition at line 369 of file ModNPC.cs.

369 {
370 }

◆ PostAI()

virtual void Terraria.ModLoader.ModNPC.PostAI ( )
virtual

Definition at line 251 of file ModNPC.cs.

251 {
252 }

◆ PostDraw()

virtual void Terraria.ModLoader.ModNPC.PostDraw ( SpriteBatch  spriteBatch,
Color  drawColor 
)
virtual

Allows you to draw things in front of this NPC. This method is called even if PreDraw returns false.

Parameters
spriteBatch
drawColor

Definition at line 528 of file ModNPC.cs.

528 {
529 }

◆ PreAI()

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

Definition at line 240 of file ModNPC.cs.

240 {
241 return true;
242 }

◆ PreDraw()

virtual bool Terraria.ModLoader.ModNPC.PreDraw ( SpriteBatch  spriteBatch,
Color  drawColor 
)
virtual

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

Parameters
spriteBatch
drawColor
Returns

Definition at line 519 of file ModNPC.cs.

519 {
520 return true;
521 }

◆ PreNPCLoot()

virtual bool Terraria.ModLoader.ModNPC.PreNPCLoot ( )
virtual

Allows you to determine whether or not this NPC will drop anything at all. Return false to stop the NPC from dropping anything. Returns true by default.

Returns

Definition at line 318 of file ModNPC.cs.

318 {
319 return true;
320 }

◆ ReceiveExtraAI()

virtual void Terraria.ModLoader.ModNPC.ReceiveExtraAI ( BinaryReader  reader)
virtual

Use this to receive information that was sent in SendExtraAI.

Parameters
reader

Definition at line 265 of file ModNPC.cs.

265 {
266 }

◆ ResetEffects()

virtual void Terraria.ModLoader.ModNPC.ResetEffects ( )
virtual

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.)

Definition at line 233 of file ModNPC.cs.

233 {
234 }

◆ ScaleExpertStats()

virtual void Terraria.ModLoader.ModNPC.ScaleExpertStats ( int  numPlayers,
float  bossLifeScale 
)
virtual

Allows you to customize this NPC's stats in expert mode. This is useful because expert mode's doubling of damage and life might be too much sometimes (for example, with bosses). Also useful for scaling life with the number of players in the world.

Parameters
numPlayers
bossLifeScale

Definition at line 227 of file ModNPC.cs.

227 {
228 }

◆ SendExtraAI()

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

Parameters
writer

Definition at line 258 of file ModNPC.cs.

258 {
259 }

◆ SetChatButtons()

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

Definition at line 629 of file ModNPC.cs.

629 {
630 }

◆ SetDefaults()

virtual void Terraria.ModLoader.ModNPC.SetDefaults ( )
virtual

Allows you to set all your NPC's properties, such as width, damage, aiStyle, lifeMax, etc.

Definition at line 177 of file ModNPC.cs.

177 {
178 }

◆ SetStaticDefaults()

virtual void Terraria.ModLoader.ModNPC.SetStaticDefaults ( )
virtual

Allows you to set all your NPC's static properties, such as names/translations and the arrays in NPCID.Sets.

Definition at line 183 of file ModNPC.cs.

183 {
184 }

◆ SetupShop()

virtual void Terraria.ModLoader.ModNPC.SetupShop ( Chest  shop,
ref int  nextSlot 
)
virtual

Allows you to add items to this NPC's shop. Add an item by setting the defaults of shop.item[nextSlot] then incrementing nextSlot. In the end, nextSlot must have a value of 1 greater than the highest index in shop.item that contains an item.

Parameters
shop
nextSlot

Definition at line 645 of file ModNPC.cs.

645 {
646 }

Referenced by Terraria.ModLoader.NPCLoader.SetupShop().

+ Here is the caller graph for this function:

◆ SpawnChance()

virtual float Terraria.ModLoader.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

Definition at line 556 of file ModNPC.cs.

556 {
557 return 0f;
558 }

Referenced by Terraria.ModLoader.NPCLoader.ChooseSpawn().

+ Here is the caller graph for this function:

◆ SpawnNPC()

virtual int Terraria.ModLoader.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

Definition at line 566 of file ModNPC.cs.

566 {
567 return NPC.NewNPC(tileX * 16 + 8, tileY * 16, npc.type);
568 }

References Terraria.ModLoader.ModNPC.npc.

Referenced by Terraria.ModLoader.NPCLoader.SpawnNPC().

+ Here is the caller graph for this function:

◆ SpecialNPCLoot()

virtual bool Terraria.ModLoader.ModNPC.SpecialNPCLoot ( )
virtual

Allows you to call NPCLoot on your own when the NPC dies, rather then letting vanilla call it on its own. Useful for things like dropping loot from the nearest segment of a worm boss. Returns false by default.

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

Definition at line 310 of file ModNPC.cs.

310 {
311 return false;
312 }

◆ StrikeNPC()

virtual bool Terraria.ModLoader.ModNPC.StrikeNPC ( ref double  damage,
int  defense,
ref float  knockback,
int  hitDirection,
ref bool  crit 
)
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. Return false to stop the game from running the vanilla damage formula; returns true by default.

Parameters
damage
defense
knockback
hitDirection
crit
Returns

Definition at line 472 of file ModNPC.cs.

472 {
473 return true;
474 }

◆ TownNPCAttackCooldown()

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

Definition at line 677 of file ModNPC.cs.

677 {
678 }

◆ TownNPCAttackMagic()

virtual void Terraria.ModLoader.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 of 2 (magic)

Parameters
auraLightMultiplier

Definition at line 708 of file ModNPC.cs.

708 {
709 }

◆ TownNPCAttackProj()

virtual void Terraria.ModLoader.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 of 0 (throwing), 1 (shooting), or 2 (magic).

Parameters
projType
attackDelay

Definition at line 685 of file ModNPC.cs.

685 {
686 }

◆ TownNPCAttackProjSpeed()

virtual void Terraria.ModLoader.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 of 0 (throwing), 1 (shooting), or 2 (magic).

Parameters
multiplier
gravityCorrection
randomOffset

Definition at line 694 of file ModNPC.cs.

694 {
695 }

◆ TownNPCAttackShoot()

virtual void Terraria.ModLoader.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 of 1 (shooting).

Parameters
inBetweenShots

Definition at line 701 of file ModNPC.cs.

701 {
702 }

◆ TownNPCAttackStrength()

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

Definition at line 669 of file ModNPC.cs.

669 {
670 }

◆ TownNPCAttackSwing()

virtual void Terraria.ModLoader.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 of 3 (swinging).

Parameters
itemWidth
itemHeight

Definition at line 716 of file ModNPC.cs.

716 {
717 }

◆ TownNPCName()

virtual string Terraria.ModLoader.ModNPC.TownNPCName ( )
virtual

Allows you to give this town NPC any name when it spawns. By default returns something embarrassing.

Returns

Definition at line 596 of file ModNPC.cs.

596 {
597 return Language.GetTextValue("tModLoader.DefaultTownNPCName");
598 }

Referenced by Terraria.ModLoader.NPCLoader.TownNPCName().

+ Here is the caller graph for this function:

◆ UpdateLifeRegen()

virtual void Terraria.ModLoader.ModNPC.UpdateLifeRegen ( ref int  damage)
virtual

Allows you to make the NPC either regenerate health or take damage over time by setting npc.lifeRegen. Regeneration or damage will occur at a rate of half of npc.lifeRegen per second. The damage parameter is the number that appears above the NPC's head if it takes damage over time.

Parameters
damage

Definition at line 287 of file ModNPC.cs.

287 {
288 }

◆ UsesPartyHat()

virtual bool Terraria.ModLoader.ModNPC.UsesPartyHat ( )
virtual

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

Returns

Definition at line 604 of file ModNPC.cs.

604 {
605 return true;
606 }

Member Data Documentation

◆ aiType

int Terraria.ModLoader.ModNPC.aiType = 0

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.

Definition at line 69 of file ModNPC.cs.

Referenced by Terraria.ModLoader.ModNPC.NewInstance().

◆ animationType

int Terraria.ModLoader.ModNPC.animationType = 0

Determines which type of vanilla NPC this ModNPC will copy the animation (FindFrame) of. Leave as 0 to not copy any animation. Defaults to 0.

Definition at line 73 of file ModNPC.cs.

Referenced by Terraria.ModLoader.ModNPC.NewInstance().

◆ banner

int Terraria.ModLoader.ModNPC.banner = 0

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.

Definition at line 100 of file ModNPC.cs.

Referenced by Terraria.ModLoader.ModNPC.AutoStaticDefaults(), and Terraria.ModLoader.ModNPC.NewInstance().

◆ bannerItem

int Terraria.ModLoader.ModNPC.bannerItem = 0

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.

Definition at line 106 of file ModNPC.cs.

Referenced by Terraria.ModLoader.ModNPC.AutoStaticDefaults(), and Terraria.ModLoader.ModNPC.NewInstance().

◆ bossBag

int Terraria.ModLoader.ModNPC.bossBag = -1

The item type of the boss bag that is dropped when DropBossBags is called for this NPC.

Definition at line 77 of file ModNPC.cs.

Referenced by Terraria.ModLoader.ModNPC.NewInstance().

◆ drawOffsetY

float Terraria.ModLoader.ModNPC.drawOffsetY = 0f

The vertical offset used for drawing this NPC. Defaults to 0.

Definition at line 92 of file ModNPC.cs.

Referenced by Terraria.ModLoader.ModNPC.NewInstance().

◆ music

int Terraria.ModLoader.ModNPC.music = -1

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

Definition at line 82 of file ModNPC.cs.

Referenced by Terraria.ModLoader.ModNPC.NewInstance().

◆ musicPriority

MusicPriority Terraria.ModLoader.ModNPC.musicPriority = MusicPriority.BossLow

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

Definition at line 86 of file ModNPC.cs.

Property Documentation

◆ AltTextures

virtual string [] Terraria.ModLoader.ModNPC.AltTextures
get

The file names of this NPC's alternate texture files, if any. This will be used in the given AutoStaticDefaults.

Definition at line 57 of file ModNPC.cs.

Referenced by Terraria.ModLoader.ModNPC.AutoStaticDefaults().

◆ BossHeadTexture

virtual string Terraria.ModLoader.ModNPC.BossHeadTexture
get

This file name of this NPC's boss head texture file, to be used in autoloading.

Definition at line 65 of file ModNPC.cs.

Referenced by Terraria.ModLoader.Mod.AutoloadNPC().

◆ CloneNewInstances

virtual bool Terraria.ModLoader.ModNPC.CloneNewInstances
get

Whether instances of this ModNPC are created through a memberwise clone or its constructor. Defaults to false.

Definition at line 137 of file ModNPC.cs.

Referenced by Terraria.ModLoader.ModNPC.NewInstance().

◆ DisplayName

ModTranslation Terraria.ModLoader.ModNPC.DisplayName
getset

The translations for the display name of this NPC.

Definition at line 45 of file ModNPC.cs.

45 {
46 get;
47 internal set;
48 }

Referenced by Terraria.ModLoader.ModNPC.AutoStaticDefaults(), and Terraria.ModLoader.ModContent.RefreshModLanguage().

◆ HeadTexture

virtual string Terraria.ModLoader.ModNPC.HeadTexture
get

The file name of this NPC's head texture file, to be used in autoloading.

Definition at line 61 of file ModNPC.cs.

Referenced by Terraria.ModLoader.Mod.AutoloadNPC().

◆ mod

Mod Terraria.ModLoader.ModNPC.mod
getset

The mod that added this ModNPC.

Definition at line 29 of file ModNPC.cs.

29 {
30 get;
31 internal set;
32 }

Referenced by Terraria.ModLoader.ModNPC.Autoload(), Terraria.ModLoader.ModNPC.AutoStaticDefaults(), and Terraria.ModLoader.ModNPC.NewInstance().

◆ Name

string Terraria.ModLoader.ModNPC.Name
getset

The internal name of this NPC.

Definition at line 37 of file ModNPC.cs.

37 {
38 get;
39 internal set;
40 }

Referenced by Terraria.ModLoader.Mod.AutoloadNPC(), Terraria.ModLoader.ModNPC.AutoStaticDefaults(), and Terraria.ModLoader.ModNPC.NewInstance().

◆ npc

◆ Texture

virtual string Terraria.ModLoader.ModNPC.Texture
get

The file name of this NPC's texture file in the mod loader's file space.

Definition at line 53 of file ModNPC.cs.

Referenced by Terraria.ModLoader.ModNPC.AutoStaticDefaults().