tModLoader v2024.03
A mod to make and play Terraria mods
NPCLoader Class Reference

This serves as the central class from which NPC-related functions are carried out. It also stores a list of mod NPCs by ID. More...

Static Public Member Functions

static T AddModHook< T > (T hook)
 
static void AddShops (int type)
 
static void AI (NPC npc)
 
static void ApplyDifficultyAndPlayerScaling (NPC npc, int numPlayers, float balance, float bossAdjustment)
 
static void BossHeadRotation (NPC npc, ref float rotation)
 
static void BossHeadSlot (NPC npc, ref int index)
 
static void BossHeadSpriteEffects (NPC npc, ref SpriteEffects spriteEffects)
 
static void BossLoot (NPC npc, ref string name, ref int potionType)
 
static void BuffTownNPC (ref float damageMult, ref int defense)
 
static ? bool CanBeCaughtBy (NPC npc, Item item, Player player)
 
static ? bool CanBeHitByItem (NPC npc, Player player, Item item)
 
static ? bool CanBeHitByProjectile (NPC npc, Projectile projectile)
 
static ? bool CanChat (NPC npc)
 
static ? bool CanCollideWithPlayerMeleeAttack (NPC npc, Player player, Item item, Rectangle meleeAttackHitbox)
 
static ? bool CanFallThroughPlatforms (NPC npc)
 
static ? bool CanGoToStatue (NPC npc, bool toKingStatue)
 
static bool CanHitNPC (NPC npc, NPC target)
 
static bool CanHitPlayer (NPC npc, Player target, ref int cooldownSlot)
 
static void CanTownNPCSpawn (int numTownNPCs)
 
static bool CheckActive (NPC npc)
 
static bool CheckConditions (int type)
 
static bool CheckDead (NPC npc)
 
static ? int ChooseSpawn (NPCSpawnInfo spawnInfo)
 
static void DrawEffects (NPC npc, ref Color drawColor)
 
static bool DrawHealthBar (NPC npc, ref float scale)
 
static void DrawTownAttackGun (NPC npc, ref Texture2D item, ref Rectangle itemFrame, ref float scale, ref int horizontalHoldoutOffset)
 
static void DrawTownAttackSwing (NPC npc, ref Texture2D item, ref Rectangle itemFrame, ref int itemSize, ref float scale, ref Vector2 offset)
 
static void EditSpawnRange (Player player, ref int spawnRangeX, ref int spawnRangeY, ref int safeRangeX, ref int safeRangeY)
 
static void EditSpawnRate (Player player, ref int spawnRate, ref int maxSpawns)
 
static void FindFrame (NPC npc, int frameHeight)
 
static ? Color GetAlpha (NPC npc, Color lightColor)
 
static void GetChat (NPC npc, ref string chat)
 
static ModNPC GetNPC (int type)
 Gets the ModNPC template instance corresponding to the specified type (not the clone/new instance which gets added to NPCs as the game is played). More...
 
static void HitEffect (NPC npc, in NPC.HitInfo hit)
 
static void ModifyActiveShop (NPC npc, string shopName, Item[] shopContents)
 
static bool ModifyCollisionData (NPC npc, Rectangle victimHitbox, ref int immunityCooldownSlot, ref float damageMultiplier, ref Rectangle npcHitbox)
 
static void ModifyGlobalLoot (GlobalLoot globalLoot)
 
static void ModifyHitByItem (NPC npc, Player player, Item item, ref NPC.HitModifiers modifiers)
 
static void ModifyHitByProjectile (NPC npc, Projectile projectile, ref NPC.HitModifiers modifiers)
 
static void ModifyHitNPC (NPC npc, NPC target, ref NPC.HitModifiers modifiers)
 
static void ModifyHitPlayer (NPC npc, Player target, ref Player.HurtModifiers modifiers)
 
static void ModifyHoverBoundingBox (NPC npc, ref Rectangle boundingBox)
 
static void ModifyIncomingHit (NPC npc, ref NPC.HitModifiers modifiers)
 
static void ModifyNPCLoot (NPC npc, NPCLoot npcLoot)
 
static List< string > ModifyNPCNameList (NPC npc, List< string > nameList)
 
static void ModifyShop (NPCShop shop)
 
static void ModifyTownNPCProfile (NPC npc, ref ITownNPCProfile profile)
 
static string ModifyTypeName (NPC npc, string typeName)
 
static void NPCAI (NPC npc)
 
static void OnCaughtBy (NPC npc, Player player, Item item, bool failed)
 
static void OnChatButtonClicked (bool firstButton)
 
static void OnGoToStatue (NPC npc, bool toKingStatue)
 
static void OnHitByItem (NPC npc, Player player, Item item, in NPC.HitInfo hit, int damageDone)
 
static void OnHitByProjectile (NPC npc, Projectile projectile, in NPC.HitInfo hit, int damageDone)
 
static void OnHitNPC (NPC npc, NPC target, in NPC.HitInfo hit)
 
static void OnHitPlayer (NPC npc, Player target, Player.HurtInfo hurtInfo)
 
static void OnKill (NPC npc)
 
static ? int PickEmote (NPC npc, Player closestPlayer, List< int > emoteList, WorldUIAnchor anchor)
 
static void PostAI (NPC npc)
 
static void PostDraw (NPC npc, SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor)
 
static bool PreAI (NPC npc)
 
static bool PreChatButtonClicked (bool firstButton)
 
static bool PreDraw (NPC npc, SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor)
 
static bool PreKill (NPC npc)
 
static byte[] ReadExtraAI (BinaryReader reader)
 
static void ReceiveExtraAI (NPC npc, byte[] extraAI)
 
static void ResetEffects (NPC npc)
 
static bool SavesAndLoads (NPC npc)
 
static void SendExtraAI (BinaryWriter writer, byte[] extraAI)
 
static void SetBestiary (NPC npc, BestiaryDatabase database, BestiaryEntry bestiaryEntry)
 
static void SetChatButtons (ref string button, ref string button2)
 
static void SetupTravelShop (int[] shop, ref int nextSlot)
 
static int SpawnNPC (int type, int tileX, int tileY)
 
static bool SpecialOnKill (NPC npc)
 
static void TownNPCAttackCooldown (NPC npc, ref int cooldown, ref int randExtraCooldown)
 
static void TownNPCAttackMagic (NPC npc, ref float auraLightMultiplier)
 
static void TownNPCAttackProj (NPC npc, ref int projType, ref int attackDelay)
 
static void TownNPCAttackProjSpeed (NPC npc, ref float multiplier, ref float gravityCorrection, ref float randomOffset)
 
static void TownNPCAttackShoot (NPC npc, ref bool inBetweenShots)
 
static void TownNPCAttackStrength (NPC npc, ref int damage, ref float knockback)
 
static void TownNPCAttackSwing (NPC npc, ref int itemWidth, ref int itemHeight)
 
static void UpdateLifeRegen (NPC npc, ref int damage)
 
static bool UsesPartyHat (NPC npc)
 
static byte[] WriteExtraAI (NPC npc)
 

Static Public Attributes

static readonly IList< int > blockLoot = new List<int>()
 Allows you to stop an NPC from dropping loot by adding item IDs to this list. This list will be cleared whenever NPCLoot ends. Useful for either removing an item or change the drop rate of an item in the NPC's loot table. To change the drop rate of an item, use the PreNPCLoot hook, spawn the item yourself, then add the item's ID to this list.
 

Properties

static int NPCCount = NPCID.Count [get]
 

Detailed Description

This serves as the central class from which NPC-related functions are carried out. It also stores a list of mod NPCs by ID.

Member Function Documentation

◆ AddModHook< T >()

static T NPCLoader.AddModHook< T > ( hook)
static
Type Constraints
T :HookList 

◆ GetNPC()

static ModNPC NPCLoader.GetNPC ( int  type)
static

Gets the ModNPC template instance corresponding to the specified type (not the clone/new instance which gets added to NPCs as the game is played).

Parameters
typeThe type of the npc
Returns
The ModNPC instance in the npcs array, null if not found.