tModLoader  0.12 Alpha
A mod to make and play Terraria mods
Terraria.NPC Class Reference

Inherits Terraria.Entity, and IEntityWithGlobals< GlobalNPC >.

Public Member Functions

void AddBuff (int type, int time, bool quiet=false)
void AI ()
void AI_000_TransformBoundNPC (int playerID, int npcType)
void AI_001_SetRainbowSlimeColor ()
NPC AI_113_WindyBalloon_GetSlaveNPC ()
bool AI_120_HallowBoss_IsGenuinelyEnraged ()
bool AI_120_HallowBoss_IsInPhase2 ()
void AI_122_PirateGhost ()
bool AnyInteractions ()
void ApplyInteraction (int player)
void AttemptToConvertNPCToEvil (bool crimson)
int BannerID ()
void BigMimicSpawnSmoke ()
void BloodNautilus_GetMouthPositionAndRotation (out Vector2 mouthPosition, out Vector2 mouthDirection)
bool Boss_CanShootExtraAt (int playerIndex, int rotationIndexToAttack, int rotationSize, float attackScanDistance, bool alwaysSkipMainTarget=true)
bool CanBeChasedBy (object attacker=null, bool ignoreDontTakeDamage=false)
bool CanReflectProjectile (Projectile proj)
void CheckActive ()
int checkArmorPenetration (int armorPenetration)
void checkDead ()
void CheckDrowning ()
object Clone ()
void CloneDefaults (int Type)
void CopyInteractions (NPC npc)
void DelBuff (int buffIndex)
void DiscourageDespawn (int despawnTime)
bool DoesntDespawnToInactivity ()
void DropItemInstanced (Vector2 Position, Vector2 HitboxSize, int itemType, int itemStack=1, bool interactionRequired=true)
void DropTombstoneTownNPC (NetworkText deathText)
void EncourageDespawn (int despawnTime)
bool ExcludedFromDeathTally ()
void FaceTarget ()
int FindBuffIndex (int type)
int FindClosestPlayer ()
int FindClosestPlayer (out float distanceToPlayer)
void FindFrame ()
Color GetAlpha (Color newColor)
int GetAttackDamage_ForProjectiles (float normalDamage, float expertDamage)
int GetAttackDamage_ForProjectiles_MultiLerp (float normalDamage, float expertDamage, float masterDamage)
int GetAttackDamage_LerpBetweenFinalValues (float normalDamage, float expertDamage)
float GetAttackDamage_LerpBetweenFinalValuesFloat (float normalDamage, float expertDamage)
int GetAttackDamage_ScaledByStrength (float normalDamage)
string GetBestiaryCreditId ()
Color GetBestiaryEntryColor ()
float GetBossHeadRotation ()
SpriteEffects GetBossHeadSpriteEffects ()
int GetBossHeadTextureIndex ()
string GetChat ()
Color GetColor (Color newColor)
NetworkText GetFullNetName ()
NetworkText GetGivenNetName ()
NetworkText GetGivenOrTypeNetName ()
GetGlobalNPC< T > (bool exactType=true)
 Gets the instance of the specified GlobalNPC type. This will throw exceptions on failure. More...
GetGlobalNPC< T > (T baseInstance)
 Gets the local instance of the type of the specified GlobalNPC instance. This will throw exceptions on failure. More...
void GetImmuneTime (int fromWho, int time)
float GetLifePercent ()
void GetLifeStats (out int statLife, out int statLifeMax)
NPCSpawnParams GetMatchingSpawnParams ()
float GetMyBalance ()
string getNewNPCName ()
Color GetNPCColorTintedByBuffs (Color npcColor)
PartyHatColor GetPartyHatColor ()
Rectangle getRect ()
int GetShootingFrame (float circleY)
IEntitySource GetSource_Buff (int buffIndex)
bool GetSpecialEventTextIfNotEmpty (string specialTextKey, object substitutes, ref string specialEventText)
Tuple< Vector2, float > GetSwingStats (int swingMax, int swingCurrent, int aimDir, int itemWidth, int itemHeight)
NPCAimedTarget GetTargetData (bool ignorePlayerTankPets=true)
void GetTileCollisionParameters (out Vector2 cPosition, out int cWidth, out int cHeight)
NetworkText GetTypeNetName ()
bool GetWereThereAnyInteractions ()
bool HasBuff (int type)
 Returns whether or not this NPC currently has a (de)buff of the provided type. More...
bool HasBuff< T > ()
bool HasLuckTextForWizard (out string specialEventText)
bool HasSpecialEventText (string specialTextCategoryKey, out string specialEventText)
void HealEffect (int healAmount, bool broadcast=true)
void HitEffect (int hitDirection=0, double dmg=10.0)
bool HittableForOnHitRewards ()
void IdleSounds ()
void moneyPing (Vector2 pos)
bool NPCCanStickToWalls ()
void NPCLoot ()
void PlayerInteraction (int player)
void PopAllAttachedProjectilesAndTakeDamageForThem ()
void ReflectProjectile (Projectile proj)
void ReflectProjectiles (Rectangle myRect)
void RequestBuffRemoval (int buffTypeToRemove)
void ScaleStats (int? activePlayersCount, GameModeData gameModeData, float? strengthOverride)
void ScaleStats_UseStrengthMultiplier (float strength)
void SetDefaults (int Type, NPCSpawnParams spawnparams=default(NPCSpawnParams))
void SetDefaults_ForNetId (int Type, float scaleOverride)
void SetDefaults_ForNetId (int Type, NPCSpawnParams spawnparams, float scaleOverride)
void SetDefaultsKeepPlayerInteraction (int Type)
void SetFrameSize ()
bool ShouldBestiaryGirlBeLycantrope ()
bool ShouldFaceTarget (ref NPCUtils.TargetSearchResults searchResults, NPCUtils.TargetType? overrideTargetType=null)
void SimpleFlyMovement (Vector2 desiredVelocity, float moveSpeed)
void SitDown (Point anchorTilePosition, out int direction, out Vector2 bottom)
 Helper method for getting the parameters for seating a town NPC. Assumes the tile at anchorTilePosition is a valid tile for sitting More...
void SpawnWithHigherTime (int timeMult)
double StrikeNPC (int Damage, float knockBack, int hitDirection, bool crit=false, bool noEffect=false, bool fromNet=false)
double StrikeNPCNoInteraction (int Damage, float knockBack, int hitDirection, bool crit=false, bool noEffect=false, bool fromNet=false)
void TargetClosest (bool faceTarget=true)
void TargetClosest_WOF (bool faceTarget=true)
void TargetClosestUpgraded (bool faceTarget=true, Vector2? checkPosition=null)
void Teleport (Vector2 newPos, int Style=0, int extraInfo=0)
override string ToString ()
void Transform (int newType)
void TransformVisuals (int oldType, int newType)
bool TryGetGlobalNPC< T > (out T result, bool exactType=true)
 Gets the instance of the specified GlobalNPC type. More...
bool TryGetGlobalNPC< T > (T baseInstance, out T result)
 Safely attempts to get the local instance of the type of the specified GlobalNPC instance. More...
void TryPortalJumping ()
void TweakSwingStats (int swingMax, int swingCurrent, int aimDir, ref Rectangle itemRectangle)
void UpdateAltTexture ()
void UpdateNPC (int i)
void UpdateNPC_BuffSetFlags (bool lowerBuffTime=true)
bool UsesPartyHat ()
void VanillaAI ()
void VanillaFindFrame (int num)
void VanillaHitEffect (int hitDirection=0, double dmg=10.0)
- Public Member Functions inherited from Terraria.Entity
float AngleFrom (Vector2 Source)
float AngleTo (Vector2 Destination)
Vector2 DirectionFrom (Vector2 Source)
Vector2 DirectionTo (Vector2 Destination)
float Distance (Vector2 Other)
float DistanceSQ (Vector2 Other)
IEntitySource GetSource_Accessory (Item item, string? context=null)
IEntitySource GetSource_CatchEntity (string? context=null)
IEntitySource GetSource_Death (string? context=null)
IEntitySource GetSource_DropAsItem (string? context=null)
IEntitySource GetSource_FromAI (string? context=null)
IEntitySource GetSource_FromThis (string? context=null)
IEntitySource GetSource_GiftOrReward (string? context=null)
IEntitySource GetSource_ItemUse (Item item, string? context=null)
IEntitySource GetSource_ItemUse_WithPotentialAmmo (Item item, int ammoItemId, string? context=null)
IEntitySource GetSource_Loot (string? context=null)
IEntitySource GetSource_Misc (string context)
IEntitySource GetSource_OnHit (Entity victim, string? context=null)
IEntitySource GetSource_OnHurt (Entity attacker, string? context=null)
IEntitySource GetSource_OpenItem (int itemType, string? context=null)
IEntitySource GetSource_ReleaseEntity (string? context=null)
IEntitySource GetSource_TileInteraction (int tileCoordsX, int tileCoordsY, string? context=null)
bool WithinRange (Vector2 Target, float MaxRange)

Static Public Member Functions

static Color AI_121_QueenSlime_GetDustColor ()
static bool AnyDanger (bool quickBossNPCCheck=false, bool ignorePillars=false)
static bool AnyHelpfulFairies ()
static bool AnyNPCs (int Type)
static bool AnyoneNearCultists ()
static bool BigMimicSummonCheck (int x, int y, Player user)
static Color buffColor (Color newColor, float R, float G, float B, float A)
static bool BusyWithAnyInvasionOfSorts ()
static bool CanReleaseNPCs (int who)
static void CatchNPC (int i, int who=-1)
static void ClearFoundActiveNPCs ()
static void ClearFoundNPCTypesForBestiary ()
static int CountNPCS (int Type)
static int DefaultHeadIndexToType (int headIndex)
static bool DespawnEncouragement_AIStyle2_FloatingEye_IsDiscouraged (int npcID, Vector2 npcPosition, int target=255)
static bool DespawnEncouragement_AIStyle3_Fighters_CanBeBusyWithAction (int npcID)
static bool DespawnEncouragement_AIStyle3_Fighters_NotDiscouraged (int npcID, Vector2 position, NPC npcInstance)
static void FairyEffects (Vector2 Position, int type)
static bool FindCattailTop (int landX, int landY, out int cattailX, out int cattailY)
static int FindFirstNPC (int Type)
static bool FindTreeBranch (int landX, int landY, out int treeBranchX, out int treeBranchY)
static int GetActivePlayerCount ()
static int GetAvailableAmountOfNPCsToSpawnFromTraps (int amountWeWant)
static float GetBalance ()
static IEntitySource GetBossSpawnSource (int targetPlayerIndex)
static int GetBrainOfCthuluCreepersCount ()
static int GetEaterOfWorldsSegmentsCount ()
static int GetEaterOfWorldsSegmentsCountByGamemode (int gamemode)
static string GetFirstNPCNameOrNull (int npcType)
static string GetFullnameByID (int npcID)
static void GetMeleeCollisionData (Rectangle victimHitbox, int enemyIndex, ref int specialHitSetter, ref float damageMultiplier, ref Rectangle npcRect)
static int GetNPCInvasionGroup (int npcID)
static bool GetNPCLocation (int i, bool seekHead, bool averageDirection, out int index, out Vector2 pos)
static int GetStackForSlimeItemDrop (int item)
static void GetStatScalingFactors (int numPlayers, out float balance, out float boost)
static void HealEffect (Rectangle r, int healAmount, bool broadcast=true)
static int[,,,] InitializeMoonLordAttacks ()
static int[,] InitializeMoonLordAttacks2 ()
static bool IsADeerclopsNearScreen ()
static bool IsValidSpawningGroundTile (int x, int y)
static void LadyBugKilled (Vector2 Position, bool GoldLadyBug=false)
static bool MechSpawn (float x, float y, int type)
static bool NearSpikeBall (int x, int y)
static int NewNPC (IEntitySource source, int X, int Y, int Type, int Start=0, float ai0=0f, float ai1=0f, float ai2=0f, float ai3=0f, int Target=255)
static NPC NewNPCDirect (IEntitySource source, int x, int y, int type, int start=0, float ai0=0f, float ai1=0f, float ai2=0f, float ai3=0f, int target=255)
 A short-hand for More...
static NPC NewNPCDirect (IEntitySource source, Vector2 position, int type, int start=0, float ai0=0f, float ai1=0f, float ai2=0f, float ai3=0f, int target=255)
static void OnGameEventClearedForTheFirstTime (int gameEventId)
static void ReleaseNPC (int x, int y, int Type, int Style, int who)
static void ResetBadgerHatTime ()
static void ResetKillCount ()
static void ResetNetOffsets ()
static void SetEventFlagCleared (ref bool eventFlag, int gameEventId)
static void setFireFlyChance ()
static void setNPCName (string newName, int npcType, bool resetExtras=false)
static void SetWorldSpecificMonstersByWorldID ()
static bool ShouldEmpressBeEnraged ()
static void SlimeRainSpawns (int plr)
static void SpawnBoss (int spawnPositionX, int spawnPositionY, int Type, int targetPlayerIndex)
static bool Spawning_FlyingAntlionCheck (int x, int y)
static bool Spawning_SandstoneCheck (int x, int y)
static void SpawnNPC ()
static void SpawnOnPlayer (int plr, int Type)
static void SpawnSkeletron (int onWho)
static void SpawnWOF (Vector2 pos)
static int TypeToDefaultHeadIndex (int type)
static void UpdateFoundActiveNPCs ()
static void UpdateRGBPeriheralProbe ()
static bool WouldBeEncouragedToDespawn (int aistyle, int type)
- Static Public Member Functions inherited from Terraria.Entity
static IEntitySource GetSource_NaturalSpawn ()
static ? IEntitySource GetSource_None ()
static IEntitySource GetSource_TownSpawn ()
static ? IEntitySource InheritSource (Entity entity)

Public Attributes

float[] ai = new float[maxAI]
int aiAction
int aiStyle
int alpha
int altTexture
bool behindTiles
bool betsysCurse
bool boss
int breath
int breathCounter
bool[] buffImmune = new bool[BuffLoader.BuffCount]
int[] buffTime = new int[5]
int[] buffType = new int[5]
bool canGhostHeal = true
short catchItem
bool celled
bool chaseable = true
bool closeDoor
bool coldDamage
bool collideX
bool collideY
Color color
bool confused
int damage
bool daybreak
LegacySoundStyle DeathSound
int defDamage
int defDefense
int defense
bool despawnEncouraged
int directionY = 1
bool dontCountMe
bool dontTakeDamage
bool dontTakeDamageFromHostiles
int doorX
int doorY
bool dripping
bool drippingSlime
bool drippingSparkleSlime
bool dryadBane
bool dryadWard
int extraValue
bool ForcePartyHatOn
Rectangle frame
double frameCounter
bool friendly
int friendlyRegen
float gfxOffY
bool hide
LegacySoundStyle HitSound
bool homeless
int homeTileX = -1
int homeTileY = -1
int housingCategory
bool ichor
bool immortal
int[] immune = new int[256]
bool IsABestiaryIconDummy
bool javelined
bool justHit
float knockBackResist = 1f
int lastInteraction = 255
int lastPortalColorIndex
bool lavaImmune
int life
int lifeMax
int lifeRegen
int lifeRegenCount
int lifeRegenExpectedLossPerSecond = -1
float[] localAI = new float[maxAI]
bool loveStruck
bool markedByScytheWhip
bool midas
float nameOver
bool netAlways
int netID
Vector2 netOffset = Vector2.Zero
int netSkip
int netSpam
bool netUpdate
bool netUpdate2
bool noGravity
bool noTileCollide
float npcSlots = 1f
bool oiled
int oldDirectionY
bool oldHomeless
int oldHomeTileX = -1
int oldHomeTileY = -1
Vector2[] oldPos = new Vector2[10]
float[] oldRot = new float[10]
int oldTarget
bool onFire
bool onFire2
bool onFire3
bool onFrostBurn
bool onFrostBurn2
bool[] playerInteraction = new bool[256]
bool poisoned
int rarity
int realLife = -1
bool reflectsProjectiles
short releaseOwner = 255
float rotation
float scale = 1f
bool setFrameSize
bool shadowFlame
bool soulDrain
int soundDelay
bool SpawnedFromStatue
int spriteDirection = -1
bool stairFall
int statsAreScaledForThisManyPlayers
float stepSpeed
bool stinky
float strengthMultiplier = 1f
float takenDamageMultiplier = 1f
int target = -1
Rectangle targetRect
bool teleporting
int teleportStyle
float teleportTime
bool tentacleSpiked
int timeLeft
bool townNPC
int townNpcVariationIndex
bool trapImmune
int type
float value
bool venom
- Public Attributes inherited from Terraria.Entity
bool active
int direction = 1
int height
bool honeyWet
bool lavaWet
int oldDirection
Vector2 oldPosition
Vector2 oldVelocity
Vector2 position
Vector2 velocity
bool wet
byte wetCount
int whoAmI
int width

Static Public Attributes

static int activeTime = 750
static readonly int AFKTimeNeededForNoWorms = 300
static bool boughtBunny = false
static bool boughtCat = false
static bool boughtDog = false
const int breathMax = 200
static int butterflyChance = 0
static int[,] cavernMonsterType = new int[2, 3]
static bool combatBookWasUsed = false
static int crimsonBoss = -1
static bool downedAncientCultist = false
static bool downedBoss1 = false
static bool downedBoss2 = false
static bool downedBoss3 = false
static bool downedChristmasIceQueen = false
static bool downedChristmasSantank = false
static bool downedChristmasTree = false
static bool downedClown = false
static bool downedDeerclops = false
static bool downedEmpressOfLight = false
static bool downedFishron = false
static bool downedFrost = false
static bool downedGoblins = false
static bool downedGolemBoss = false
static bool downedHalloweenKing = false
static bool downedHalloweenTree = false
static bool downedMartians = false
static bool downedMechBoss1 = false
static bool downedMechBoss2 = false
static bool downedMechBoss3 = false
static bool downedMechBossAny = false
static bool downedMoonlord = false
static bool downedPirates = false
static bool downedPlantBoss = false
static bool downedQueenBee = false
static bool downedQueenSlime = false
static bool downedSlimeKing = false
static bool downedTowerNebula = false
static bool downedTowerSolar = false
static bool downedTowerStardust = false
static bool downedTowerVortex = false
static bool fairyLog = false
static int fireFlyChance = 0
static int fireFlyFriendly = 0
static int fireFlyMultiple = 0
static bool freeCake = false
static int goldCritterChance = 400
static int golemBoss = -1
static int immuneTime = 20
static int[] killCount = new int[670]
static int ladyBugBadLuckTime = -10800
static int ladyBugGoodLuckTime = 43200
static int[] lazyNPCOwnedProjectileSearchArray = new int[200]
static bool LunarApocalypseIsUp = false
static int LunarShieldPowerExpert = 150
static int LunarShieldPowerNormal = 100
static int maxAI = 4
const int maxBuffs = 5
const int MaxMoonLordCountdown = 3600
static readonly int[,,,] MoonLordAttacksArray = InitializeMoonLordAttacks()
static readonly int[,] MoonLordAttacksArray2 = InitializeMoonLordAttacks2()
static int MoonLordCountdown = 0
static int MoonLordFightingDistance = 4500
const float nameOverDistance = 350f
const float nameOverIncrement = 0.025f
static bool[] npcsFoundForCheckActive = new bool[670]
static int offSetDelayTime = 60
static int plantBoss = -1
static CoinLossRevengeSystem RevengeManager = new CoinLossRevengeSystem()
static int safeRangeX = (int)((double)(sWidth / 16) * 0.52)
static int safeRangeY = (int)((double)(sHeight / 16) * 0.52)
static bool savedAngler = false
static bool savedBartender = false
static bool savedGoblin = false
static bool savedGolfer = false
static bool savedMech = false
static bool savedStylist = false
static bool savedTaxCollector = false
static bool savedWizard = false
static int sHeight = 1080
static int ShieldStrengthTowerNebula = 0
static int ShieldStrengthTowerSolar = 0
static int ShieldStrengthTowerStardust = 0
static int ShieldStrengthTowerVortex = 0
static int sWidth = 1920
static bool taxCollector = false
static bool TowerActiveNebula = false
static bool TowerActiveSolar = false
static bool TowerActiveStardust = false
static bool TowerActiveVortex = false
static bool travelNPC = false
static float waveKills = 0f
static int waveNumber = 0


IBigProgressBar BossBar [get, set]
 Assign a special boss bar, vanilla or modded. Not used by vanilla. More...
bool CanBeTalkedTo [get]
bool CanTalk [get]
bool CountsAsACritter [get]
static bool downedTowers [get]
string FullName [get]
string?? GivenName [get, set]
string GivenOrTypeName [get]
RefReadOnlyArray< Instanced< GlobalNPC > > Globals [get]
NPCHappiness Happiness [get]
 Provides access to (static) happiness data associated with this NPC's type. More...
bool HasGivenName [get]
bool HasNPCTarget [get]
bool HasPlayerTarget [get]
bool HasValidTarget [get]
bool isLikeATownNPC [get]
ModNPC ModNPC [get, set]
float Opacity [get, set]
static int ShieldStrengthTowerMax [get]
bool SupportsNPCTargets [get]
static bool TooWindyForButterflies [get]
static bool TowersDefeated [get]
int TranslatedTargetIndex [get]
string TypeName [get]
int WhoAmIToTargettingIndex [get]
- Properties inherited from Terraria.Entity
Vector2 Bottom [get, set]
Vector2 BottomLeft [get, set]
Vector2 BottomRight [get, set]
Vector2 Center [get, set]
Rectangle Hitbox [get, set]
Vector2 Left [get, set]
Vector2 Right [get, set]
Vector2 Size [get, set]
Vector2 Top [get, set]
Vector2 TopLeft [get, set]
Vector2 TopRight [get, set]
virtual Vector2 VisualPosition [get]

Member Function Documentation

◆ GetGlobalNPC< T >() [1/2]

T Terraria.NPC.GetGlobalNPC< T > ( bool  exactType = true)

Gets the instance of the specified GlobalNPC type. This will throw exceptions on failure.

Type Constraints
T :GlobalNPC 
T :GlobalType.GetGlobal 
T :GlobalNPC 
T :T 
T :globalNPCs 
T :exactType 

◆ GetGlobalNPC< T >() [2/2]

T Terraria.NPC.GetGlobalNPC< T > ( baseInstance)

Gets the local instance of the type of the specified GlobalNPC instance. This will throw exceptions on failure.

Type Constraints
T :GlobalNPC 
T :GlobalType.GetGlobal 
T :GlobalNPC 
T :T 
T :globalNPCs 
T :baseInstance 

◆ HasBuff()

bool Terraria.NPC.HasBuff ( int  type)

Returns whether or not this NPC currently has a (de)buff of the provided type.

◆ NewNPCDirect()

static NPC Terraria.NPC.NewNPCDirect ( IEntitySource  source,
int  x,
int  y,
int  type,
int  start = 0,
float  ai0 = 0f,
float  ai1 = 0f,
float  ai2 = 0f,
float  ai3 = 0f,
int  target = 255 

A short-hand for


◆ SitDown()

void Terraria.NPC.SitDown ( Point  anchorTilePosition,
out int  direction,
out Vector2  bottom 

Helper method for getting the parameters for seating a town NPC. Assumes the tile at anchorTilePosition is a valid tile for sitting

◆ TryGetGlobalNPC< T >() [1/2]

bool Terraria.NPC.TryGetGlobalNPC< T > ( out T  result,
bool  exactType = true 

Gets the instance of the specified GlobalNPC type.

Type Constraints
T :GlobalNPC 
T :GlobalType.TryGetGlobal 
T :GlobalNPC 
T :T 
T :globalNPCs 
T :exactType 
T :out 
T :result 

◆ TryGetGlobalNPC< T >() [2/2]

bool Terraria.NPC.TryGetGlobalNPC< T > ( baseInstance,
out T  result 

Safely attempts to get the local instance of the type of the specified GlobalNPC instance.

Whether or not the requested instance has been found.
Type Constraints
T :GlobalNPC 
T :GlobalType.TryGetGlobal 
T :GlobalNPC 
T :T 
T :globalNPCs 
T :baseInstance 
T :out 
T :result 

Property Documentation

◆ BossBar

IBigProgressBar Terraria.NPC.BossBar

Assign a special boss bar, vanilla or modded. Not used by vanilla.

To assign a modded boss bar, use NPC.BossBar = ModContent.GetInstance<ExampleBossBar>(); where ExampleBossBar is a ModBossBar

To assign a vanilla boss bar for whatever reason, fetch it first through the NPC type using Main.BigBossProgressBar.TryGetSpecialVanillaBossBar

◆ Happiness

NPCHappiness Terraria.NPC.Happiness

Provides access to (static) happiness data associated with this NPC's type.