Immunity frames
Immunity frames, also called invincibility frames, invulnerability frames, and frequently shortened to iframes or i-frames, are a core game mechanic of Terraria which provide a window of time where the player or an NPC is immune to damage from one or all sources.
Many items in both the base game and the Calamity Mod have special interactions with immunity frames, whether it is an accessory which provides extra immunity frames to the player when attacked (e.g. Deific Amulet) or a weapon which can strike NPCs far more quickly than is normally possible (e.g. Dead Sun's Wind).
Player Immunity Frames
There are different ways to augment player immunity frames. Additionally, in Revengeance Mode, player immunity frames are capped at 150, or 2.5 seconds.
Cross Necklace Inheritance
The Cross Necklace accessory doubles the player's immunity frames. The immunity frame doubling effect cannot stack with itself, so obtaining the buff in addition to equipping the Cross Necklace provides no further benefit.
Adding Immunity Frames
There are several events and effects that directly set or add to a player's immuneTime
instead of multiplying. Effects which add immunity frames will stack with the Cross Necklace or other accessories which inherit that effect. Additionally, effects which add immunity frames will affect the immunity frames of attacks with a cooldownSlot
of 0 or 1, whereas effects which directly set their immunity frames will have no effect on such attacks.
A table of all items that use this code, along with the corresponding immuneTime
values is below:
cooldownSlot
- This section primarily describes vanilla Terraria behavior.
When anything hurts the player, they are given one of three different types of immunity frames, based on what the damage source sets the cooldownSlot
variable to upon dealing the damage. All damage sources have the variable set to -1 by default, which uses standard immuneTime
that is affected by all immunity frame-affecting items. However, if cooldownSlot
is set to 0 or 1, then the player is given unique immunity frames that only protect against further damage from sources with the same cooldownSlot
number. For instance, if the player is hit by a projectile with the variable set to 1, they can still be dealt damage by another projectile with the default value of -1 immediately after, but cannot be immediately hurt by another slot 1 projectile. Only certain effects can affect immunity frames given by an attack with cooldownSlot
set to 0 or 1, those effects being the Cross Necklace, the accessories which inherit its effects, and any effects which add to the player's on-hit immunity frames; all other items have no effect.
A table of all enemies and projectiles in the Calamity Mod that have cooldownSlot
set to 0 or 1, thereby only preventing hits from sources with the same value and ignoring immuneTime
modifications by any items except Cross Necklace (and its inheritors), is below:
Ignoring NPC Immunity Frames
Terraria provides three mechanisms by which projectiles may ignore, bypass or reduce NPC immunity frames.
usesLocalNPCImmunity
- This section primarily describes vanilla Terraria behavior.
If a projectile sets usesLocalNPCImmunity
to true, its interaction with immunity frames fundamentally changes. When the projectile strikes an NPC, instead of setting the NPC's npc.immune
, it sets up a timer on the projectile which stops that specific projectile from striking the NPC for a certain number of frames. Once the timer is up, the projectile can strike that NPC again.
The length of the timer is determined by the variable localNPCHitCooldown
. Since Terraria runs at 60 tick per second,[1] a value of 60 for localNPCHitCooldown
would limit the projectile to striking once per second. However, the timer only applies to the specific projectile which started it. Any other projectiles - even piercing ones - can still hit the NPC while the timer is running, which is what gives the impression that the projectile "ignores iframes".
localNPCHitCooldown
also has two special values, -2 and -1. In both of these cases, no internal timer is set. Instead, the NPC that was struck by the projectile becomes permanently immune to that specific projectile forever. This means that the NPC can only be hit by a projectile with negative localNPCHitCooldown
once, no matter how long the projectile lasts. When localNPCHitCooldown
is set to -1, the projectile sets npc.immune
to zero on hit, ensuring that it always hits no matter what. This also lends credence to the phrase "ignores iframes", because the projectile literally ignores the immunity frames of the NPC it is hitting.
Summary of the behavior of localNPCHitCooldown
values:
- -2: The NPC's immunity frames are unaffected by the projectile. If the NPC has immunity frames, the projectile does not strike. Otherwise, the NPC is struck and does not receive any immunity frames. The projectile will never hit this NPC again.
- -1: The projectile explicitly removes the NPC's immunity frames on contact. It always hits. The projectile will never hit this NPC again. An example of
localNPCHitCooldown
-1 is Luminite Bullets. - 0: Behaves effectively the same way as -2, except that the projectile can immediately strike the NPC again on the next frame. The NPC gets no immunity frames if struck, but the projectile won't remove immunity frames if the NPC already has some.
- 1: Behaves almost the same as 0. The difference is that because the NPC's
npc.immune
is set to 1, it is immune to all other basic piercing or -2localNPCHitCooldown
projectiles which would strike it this frame. - 2+: The projectile can only strike a particular NPC once per this many frames. This cooldown is individual per NPC.
A table of all items with projectiles that use this code, along with the corresponding localNPCHitCooldown
values is below:
- Additionally, the explosions created by the Chaotic Puffer also set
usesLocalNPCImmunity
to true, withlocalNPCHitCooldown
set to 1.
usesIDStaticNPCImmunity
- This section primarily describes vanilla Terraria behavior.
If a projectile sets usesIDStaticNPCImmunity
to true and idStaticNPCHitCooldown
to a value, its interaction with immunity frames is fundamentally changed. Much like usesLocalNPCImmunity
, a timer is set when the projectile strikes an NPC. However, this type of internal timer blocks out all projectiles of the same type from the same player. This means that after any instance of a usesIDStaticNPCImmunity
projectile hits an enemy, the NPC is immune to all projectiles of that type from the player who struck them for a given time. All projectiles which use usesIDStaticNPCImmunity
explicitly remove immunity frames from any NPCs they strike, like projectiles which set localNPCHitCooldown
to -1.
A table of all items with projectiles that use this code, along with the corresponding idStaticNPCHitCooldown
values is below:
npc.immune
Projectiles which set npc.immune
to a value upon striking an NPC simply change the number of immunity frames the NPC receives. Like a typical piercing projectile, the NPC will not be able to be struck by any piercing projectiles for that many frames. Normal piercing projectiles set npc.immune
to 10, so typically projectiles which change this behavior set npc.immune
to a lower value such as 4. This behavior is often called "partially ignoring iframes", because it removes or ignores some of the NPC's immunity frames, but not all of them.
A table of all items with projectiles that use this code, along with the corresponding npc.immune
values is below:
References
- ↑ A tick is a time unit countable by the software. Most of Terraria's updating logic happens every tick. A tick has the length of 1/60th of a second, hence there are 60 ticks in a second and 3600 ticks in a minute.
Game mechanics | |||||||||
---|---|---|---|---|---|---|---|---|---|
Combat | Damage Reduction • Defense damage • Enchantment • Hit sounds • Immunity frames • Lifesteal • Minions • Rogue | ||||||||
Environment | Biome backgrounds • Events • Music | ||||||||
Events | Acid Rain • Boss Rush | ||||||||
Game | Bestiary • Configuration options • Difficulty Modes (Death Mode • Revengeance Mode) • Fishing • Game controls • Lore • Secret world seeds (For the worthy • Get fixed boi) • Vanilla changes | ||||||||
Items | Alternative crafting ingredients • Charge • Consumable • Crafting stations (By Hand) • Drops • Modifiers • Rarity • Recipes • Vanilla item recipes | ||||||||
Player | Adrenaline Meter • Aggro • Buffs and Debuffs • Dash • Death prevention • Defense • Dodge • Flight Time Bar • Rage Meter | ||||||||
UI | Boss Health Bar • Cooldown Rack • Speedrun Timer • Status messages • Tips |