Skip to content

API Projectiles

JonataOliveiraa edited this page Nov 14, 2026 · 1 revision
Reference

API reference · generated by tools/docs/ApiReference, do not edit by hand

Projectiles and their global hooks.

GlobalProjectile

abstract class Terraria.ModLoader.GlobalProjectile : GlobalType<Projectile, GlobalProjectile>

This class allows you to modify and use hooks for all projectiles, both vanilla and modded. To use it, simply create a new class deriving from this one. Implementations will be registered automatically.

Member Kind tModLoader What it does
void SetDefaults(Projectile entity) hook only here Allows you to set all your projectile's properties, such as width, damage, aiStyle, penetrate, etc.
void OnSpawn(Projectile projectile, IEntitySource source) hook same Gets called when any projectiles spawns in world Called on the client or server spawning the projectile via Projectile.NewProjectile.
bool PreAI(Projectile projectile) hook same Allows you to determine how any projectile behaves. Return false to stop the vanilla AI and the AI hook from being run. Returns true by default. Called on local, server, and remote clients.
void AI(Projectile projectile) hook same Allows you to determine how any projectile behaves. This will only be called if PreAI returns true. Called on local, server, and remote clients.
void PostAI(Projectile projectile) hook same Allows you to determine how any projectile behaves. This will be called regardless of what PreAI returns. Called on local, server, and remote clients.
bool ShouldUpdatePosition(Projectile projectile) hook same Whether or not the given projectile should update its position based on factors such as its velocity, whether it is in liquid, etc. Return false to make its velocity have no effect on its position. Returns true by default. Called on local, server, and remote clients.
bool TileCollideStyle(Projectile projectile, ref int width, ref int height, ref bool fallThrough, ref Vector2 hitboxCenterFrac) hook same Allows you to determine how a projectile interacts with tiles. Return false if you completely override or cancel a projectile's tile collision behavior. Returns true by default. Called on local, server, and remote clients.
bool OnTileCollide(Projectile projectile, Vector2 oldVelocity) hook same Allows you to determine what happens when a projectile collides with a tile. OldVelocity is the velocity before tile collision. The velocity that takes tile collision into account can be found with projectile.velocity. Return true to allow the vanilla tile collision code to take place (which normally kills the projectile). Returns true by default. Called on local, server, and remote clients.
bool PreKill(Projectile projectile, int timeLeft) hook same Allows you to determine whether the vanilla code for Kill and the Kill hook will be called. Return false to stop them from being called. Returns true by default. Note that this does not stop the projectile from dying. Called on local, server, and remote clients.
void OnKill(Projectile projectile, int timeLeft) hook same Allows you to control what happens when a projectile is killed (for example, creating dust or making sounds). Be sure to check if (Projectile.owner == Main.myPlayer) for logic that should only run for the projectile owner. Some examples include spawning items, spawning projectiles, and modifying tiles. Called on local, server, and remote clients.
void PrepareBombToBlow(Projectile projectile) hook same Used to adjust projectile properties immediately before the projectile becomes an explosion. This is called on projectiles using the Explosive aiStyle or projectiles that are contained in the Explosive set. By defaults tileCollide is set to false and alpha is set to 255. Use this to adjust damage, knockBack, and the projectile hitbox (Projectile.Resize). Called during Projectile.PrepareBombToBlow, which is called by default during Projectile.AI_016 and during Projectile.Kill for the aforementioned projectiles. Can be called on the local client or server, depending on who owns the projectile.
bool DisplayDollSettings(Projectile projectile, Player doll, DisplayDollPose pose, ref int aiStyle, ref int aiType) hook same Allows for modifying the position of the held projectile while a Mannequin is holding it. This is needed for held projectiles such as Spears, Drills, Shortswords, Yoyos, Flails, and Whips. Vanilla code supports Spear, Drill, ShortSword, HeldProjectile, ForwardStab, SleepyOctopod, Yoyo, Flail, MedusaRay, and Whip, but the existing logic might not work or look correct for all modded projectiles. aiStyle can be set to a supported vanilla aiStyle to get the same behavior as a vanilla projectile. aiType can be set to a supported vanilla projectile type for some aiStyles that check type. If re-using an existing aiStyle value doesn't work, you will need to implement this hook to make it display correctly on mannequins. Consult the decompiled code of AI_DisplayDoll or Example Mod usages for sample code. See also isAPreviewDisplayDoll.
bool CanCutTiles(Projectile projectile) hook same Return true or false to specify if the projectile can cut tiles like vines, pots, and Queen Bee larva. Return null for vanilla decision. Can be called on the local client or server, depending on who owns the projectile.
void CutTiles(Projectile projectile) hook same Code ran when the projectile cuts tiles. Only runs if CanCutTiles() returns true. Useful when programming lasers and such. Can be called on the local client or server, depending on who owns the projectile.
bool CanDamage(Projectile projectile) hook same Whether or not the given projectile is capable of killing tiles (such as grass) and damaging NPCs/players. Return false to prevent it from doing any sort of damage. Return true if you want the projectile to do damage regardless of the default blacklist. Return null to let the projectile follow vanilla can-damage-anything rules. This is what happens by default. Called on local, server, and remote clients.
bool MinionContactDamage(Projectile projectile) hook same Whether or not a minion can damage NPCs by touching them. Returns false by default. Note that this will only be used if the projectile is considered a pet. Called on local, server, and remote clients.
void ModifyDamageHitbox(Projectile projectile, ref Rectangle hitbox) hook same Allows you to change the hitbox used by a projectile for damaging players and NPCs. Called on local, server, and remote clients.
bool CanHitNPC(Projectile projectile, NPC target) hook same Allows you to determine whether a projectile can hit the given NPC. Return true to allow hitting the target, return false to block the projectile from hitting the target, and return null to use the vanilla code for whether the target can be hit. Returns null by default. Can be called on the local client or server, depending on who owns the projectile.
void ModifyHitNPC(Projectile projectile, NPC target, ref HitModifiers modifiers) hook same Allows you to modify the damage, knockback, etc., that a projectile does to an NPC. Can be called on the local client or server, depending on who owns the projectile.
void OnHitNPC(Projectile projectile, NPC target, HitInfo hit, int damageDone) hook same Allows you to create special effects when a projectile hits an NPC (for example, inflicting debuffs). Can be called on the local client or server, depending on who owns the projectile.
bool CanHitPvp(Projectile projectile, Player target) hook same Allows you to determine whether a projectile can hit the given opponent player. Return false to block the projectile from hitting the target. Returns true by default. Called on the client hitting the target.
bool CanHitPlayer(Projectile projectile, Player target) hook same Allows you to determine whether a hostile projectile can hit the given player. Return false to block the projectile from hitting the target. Returns true by default. Called on the server only.
void ModifyHitPlayer(Projectile projectile, Player target, ref HurtModifiers modifiers) hook same Allows you to modify the damage, etc., that a hostile projectile does to a player. Called on the client taking damage.
void OnHitPlayer(Projectile projectile, Player target, HurtInfo info) hook same Allows you to create special effects when a hostile projectile hits a player. Called on the client taking damage.
bool Colliding(Projectile projectile, Rectangle projHitbox, Rectangle targetHitbox) hook same Allows you to use custom collision detection between a projectile and a player or NPC that the projectile can damage. Useful for things like diagonal lasers, projectiles that leave a trail behind them, etc. Can be called on the local client or server, depending on who owns the projectile.
Color GetAlpha(Projectile projectile, Color lightColor) hook same Allows you to determine the color and transparency in which a projectile is drawn. Return null to use the default color (normally light and buff color). Returns null by default. Called on local and remote clients.
bool PreDrawExtras(Projectile projectile, Player player) hook same Allows you to draw things behind a projectile. Use the Main.EntitySpriteDraw method for drawing. Returns false to stop the game from drawing extras textures related to the projectile (for example, the chains for grappling hooks), useful if you're manually drawing the extras. Returns true by default. Called on local and remote clients.
bool PreDraw(Projectile projectile, Player player, ref Color lightColor) hook same Allows you to draw things behind a projectile, or to modify the way the projectile is drawn. Use the Main.EntitySpriteDraw method for drawing. Return false to stop the vanilla projectile drawing code (useful if you're manually drawing the projectile). Returns true by default. Called on local and remote clients.
void PostDraw(Projectile projectile, Player player, Color lightColor) hook same Allows you to draw things in front of a projectile. Use the Main.EntitySpriteDraw method for drawing. This method is called even if PreDraw returns false. Called on local and remote clients.
void SendExtraAI(Projectile projectile, BitWriter bitWriter, BinaryWriter binaryWriter) hook same Use this judiciously to avoid straining the network. Checks and methods such as AppliesToEntity can reduce how much data must be sent for how many projectiles. Called whenever SyncProjectile is successfully sent, for example on projectile creation, or whenever Projectile.netUpdate is set to true in the update loop for that tick. Can be called on the local client or server, depending on who owns the projectile.
void ReceiveExtraAI(Projectile projectile, BitReader bitReader, BinaryReader binaryReader) hook same Use this to receive information that was sent in SendExtraAI. Called whenever SyncProjectile is successfully received. Can be called on the local client or server, depending on who owns the projectile.
bool CanUseGrapple(int type, Player player) hook same Whether or not a grappling hook that shoots this type of projectile can be used by the given player. Return null to use the default code (whether or not the player is in the middle of firing the grappling hook). Returns null by default. Called on the local client only.
void UseGrapple(Player player, ref int type) hook same This code is called whenever the player uses a grappling hook that shoots this type of projectile. Use it to change what kind of hook is fired (for example, the Dual Hook does this), to kill old hook projectiles, etc. Called on the local client only.
void NumGrappleHooks(Projectile projectile, Player player, ref int numHooks) hook same How many of this type of grappling hook the given player can latch onto blocks before the hooks start disappearing. Change the numHooks parameter to determine this; by default it will be 3. Called on the local client only.
void GrappleRetreatSpeed(Projectile projectile, Player player, ref float speed) hook same The speed at which the grapple retreats back to the player after not hitting anything. Defaults to 11, but vanilla hooks go up to 24. Called on local, server, and remote clients.
void GrapplePullSpeed(Projectile projectile, Player player, ref float speed) hook same The speed at which the grapple pulls the player after hitting something. Defaults to 11, but the Bat Hook uses 16. Called on local, server, and remote clients.
void GrappleTargetPoint(Projectile projectile, Player player, ref float grappleX, ref float grappleY) hook same The location that the grappling hook pulls the player to. Defaults to the center of the hook projectile. Called on local, server, and remote clients.
bool GrappleCanLatchOnTo(Projectile projectile, Player player, int x, int y) hook same Whether or not the grappling hook can latch onto the given position in tile coordinates. This position may be air or an actuated tile! Return true to make it latch, false to prevent it, or null to apply vanilla conditions. Returns null by default. Called on local, server, and remote clients.
void EmitEnchantmentVisualsAt(Projectile projectile, Vector2 boxPosition, int boxWidth, int boxHeight) hook not here Called when EmitEnchantmentVisualsAt is called. Typically used to spawn visual effects (Dust) indicating weapon enchantments such as flasks, frost armor, or magma stone effects. This is similar to how items spawn visual effects in MeleeEffects, but for projectiles instead. A typical weapon enchantment would likely include similar code in both to support weapon enchantment visuals for both items and projectiles. Projectiles can use noEnchantments to indicate that a projectile should not be considered for enchantment visuals, so check that field if relevant. Called on local, server, and remote clients.
void FlailStats(Projectile projectile, ref int launchTimeLimit, ref float launchSpeed, ref float maxLaunchLength, ref float retractAcceleration, ref float maxRetractSpeed, ref float forcedRetractAcceleration, ref float maxForcedRetractSpeed, ref int ricochetTimeLimit, ref float spinVisualDistance) hook not here Used to adjust flail properties. Called when aiStyle is Flail.
void FlailSpinCollisionRange(Projectile projectile, ref float range) hook not here Used to adjust flail spin collision range. Called during Colliding when aiStyle is Flail.

ModProjectile

abstract class Terraria.ModLoader.ModProjectile : ModType<Projectile, ModProjectile>

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

Member Kind tModLoader What it does
ref Projectile Projectile property differs The projectile object that this ModProjectile controls. tML: Projectile Projectile
int Type property same Shorthand for Projectile.type;
string LocalizationCategory hook same The folder of this content in the localization files.
LocalizedText DisplayName hook same The translations for the display name of this projectile.
int AIType property same Determines which type of vanilla projectile this ModProjectile will copy the behavior (AI) of. Leave as 0 to not copy any behavior. Defaults to 0.
int CooldownSlot property same Determines which ImmunityCooldownID to use when this projectile damages a player. Defaults to -1 (General).
int DrawOffsetX property same How far to the right of its position this projectile should be drawn. Defaults to 0.
int DrawOriginOffsetY property same The vertical origin offset from the projectile's center when it is drawn. The origin is essentially the point of rotation. This field will also determine the vertical drawing offset of the projectile.
float DrawOriginOffsetX property same The horizontal origin offset from the projectile's center when it is drawn.
string Texture hook same The file name of this type's texture file in the mod loader's file space. The resulting Asset can be retrieved using Projectile indexed by Type if needed. You can use a vanilla texture by returning $"Terraria/Images/Projectile_{ProjectileID.ProjectileNameHere}"
string GlowTexture hook same The file name of this projectile's glow texture file in the mod loader's file space. If it does not exist it is ignored. Phone: Drawn after the sprite. Spears and other projectiles with their own drawing in the game get it too.
void SetDefaults() hook same Allows you to set all your projectile's properties, such as width, damage, aiStyle, penetrate, etc.
void OnSpawn(IEntitySource source) hook same Gets called when your projectiles spawns in world. Called on the client or server spawning the projectile via Projectile.NewProjectile.
void AutoStaticDefaults() hook same Automatically sets certain static defaults. Override this if you do not want the properties to be set for you.
bool PreAI() hook same Allows you to determine how this projectile behaves. Return false to stop the vanilla AI and the AI hook from being run. Returns true by default. Called on local, server, and remote clients.
void AI() hook same Allows you to determine how this projectile behaves. This will only be called if PreAI returns true. The Basic Projectile Guide teaches the basics of writing a custom AI, such as timers, gravity, rotation, etc. Called on local, server, and remote clients.
void PostAI() hook same Allows you to determine how this projectile behaves. This will be called regardless of what PreAI returns. Called on local, server, and remote clients.
void SendExtraAI(BinaryWriter writer) hook same If you are storing AI information outside of the Projectile.ai array, use this to send that AI information between clients and servers, which will be handled in ReceiveExtraAI. Called whenever SyncProjectile is successfully sent, for example on projectile creation, or whenever Projectile.netUpdate is set to true in the update loop for that tick. Can be called on the local client or server, depending on who owns the projectile.
void ReceiveExtraAI(BinaryReader reader) hook same Use this to receive information that was sent in SendExtraAI. Called whenever SyncProjectile is successfully received. Can be called on the local client or server, depending on who owns the projectile.
void ModifyFishingLine(ref Vector2 lineOriginOffset, ref Color lineColor) hook same Changes the origin and color of a bobber's line.
bool ShouldUpdatePosition() hook same Whether or not this projectile should update its position based on factors such as its velocity, whether it is in liquid, etc. Return false to make its velocity have no effect on its position. Returns true by default. Called on local, server, and remote clients.
bool TileCollideStyle(ref int width, ref int height, ref bool fallThrough, ref Vector2 hitboxCenterFrac) hook same Allows you to determine how this projectile interacts with tiles. Return false if you completely override or cancel this projectile's tile collision behavior. Returns true by default. Called on local, server, and remote clients.
bool OnTileCollide(Vector2 oldVelocity) hook same Allows you to determine what happens when this projectile collides with a tile. OldVelocity is the velocity before tile collision. The velocity that takes tile collision into account can be found with Projectile.velocity. Return true to allow the vanilla tile collision code to take place (which normally kills the projectile). Returns true by default. Called on local, server, and remote clients.
bool CanCutTiles() hook same Return true or false to specify if the projectile can cut tiles like vines, pots, and Queen Bee larva. Return null for vanilla decision. Can be called on the local client or server, depending on who owns the projectile.
void CutTiles() hook same Code ran when the projectile cuts tiles. Only runs if CanCutTiles() returns true. Useful when programming lasers and such. Can be called on the local client or server, depending on who owns the projectile.
bool PreKill(int timeLeft) hook same Allows you to determine whether the vanilla code for Kill and the Kill hook will be called. Return false to stop them from being called. Returns true by default. Note that this does not stop the projectile from dying. Called on local, server, and remote clients.
void OnKill(int timeLeft) hook same Allows you to control what happens when this projectile is killed (for example, creating dust or making sounds). Also useful for creating retrievable ammo. Be sure to check if (Projectile.owner == Main.myPlayer) for logic that should only run for the projectile owner. Some examples include spawning items, spawning projectiles, and modifying tiles. Called on local, server, and remote clients.
void PrepareBombToBlow() hook same Used to adjust projectile properties immediately before the projectile becomes an explosion. This is called on projectiles using the Explosive aiStyle or projectiles that are contained in the Explosive set. By defaults tileCollide is set to false and alpha is set to 255. Use this to adjust damage, knockBack, and the projectile hitbox (Projectile.Resize). Called during Projectile.PrepareBombToBlow, which is called by default during Projectile.AI_016 and during Projectile.Kill for the aforementioned projectiles. Can be called on the local client or server, depending on who owns the projectile.
bool DisplayDollSettings(Player doll, DisplayDollPose pose, ref int aiStyle, ref int aiType) hook same Allows for modifying the position of the held projectile while a Mannequin is holding it. This is needed for held projectiles such as Spears, Drills, Shortswords, Yoyos, Flails, and Whips. Vanilla code supports Spear, Drill, ShortSword, HeldProjectile, ForwardStab, SleepyOctopod, Yoyo, Flail, MedusaRay, and Whip, but the existing logic might not work or look correct for all modded projectiles. aiStyle can be set to a supported vanilla aiStyle to get the same behavior as a vanilla projectile. aiType can be set to a supported vanilla projectile type for some aiStyles that check type. If re-using an existing aiStyle value doesn't work, you will need to implement this hook to make it display correctly on mannequins. Consult the decompiled code of AI_DisplayDoll or Example Mod usages for sample code. See also isAPreviewDisplayDoll.
bool CanDamage() hook same Whether or not this projectile is capable of killing tiles (such as grass) and damaging NPCs/players. Return false to prevent it from doing any sort of damage. Return true if you want the projectile to do damage regardless of the default blacklist. Return null to let the projectile follow vanilla can-damage-anything rules. This is what happens by default. Called on local, server, and remote clients.
bool MinionContactDamage() hook same Whether or not this minion can damage NPCs by touching them. Returns false by default. Note that this will only be used if this projectile is considered a pet (projPet). Called on local, server, and remote clients.
void ModifyDamageHitbox(ref Rectangle hitbox) hook same Allows you to change the hitbox used by this projectile for damaging players and NPCs. Called on local, server, and remote clients.
bool CanHitNPC(NPC target) hook same Allows you to determine whether this projectile can hit the given NPC. Return true to allow hitting the target, return false to block this projectile from hitting the target, and return null to use the vanilla code for whether the target can be hit. Returns null by default. Can be called on the local client or server, depending on who owns the projectile.
void ModifyHitNPC(NPC target, ref HitModifiers modifiers) hook same Allows you to modify the damage, knockback, etc., that this projectile does to an NPC. Can be called on the local client or server, depending on who owns the projectile.
void OnHitNPC(NPC target, HitInfo hit, int damageDone) hook same Allows you to create special effects when this projectile hits an NPC (for example, inflicting debuffs). Can be called on the local client or server, depending on who owns the projectile.
bool CanHitPvp(Player target) hook same Allows you to determine whether this projectile can hit the given opponent player. Return false to block this projectile from hitting the target. Returns true by default. Called on the client hitting the target.
bool CanHitPlayer(Player target) hook same Allows you to determine whether this hostile projectile can hit the given player. Return false to block this projectile from hitting the target. Returns true by default. Called on the server only.
void ModifyHitPlayer(Player target, ref HurtModifiers modifiers) hook same Allows you to modify the damage, etc., that this hostile projectile does to a player. Called on the client taking damage.
void OnHitPlayer(Player target, HurtInfo info) hook same Allows you to create special effects when this hostile projectile hits a player. Called on the client taking damage.
bool Colliding(Rectangle projHitbox, Rectangle targetHitbox) hook same Allows you to use custom collision detection between this projectile and a player or NPC that this projectile can damage. Useful for things like diagonal lasers, projectiles that leave a trail behind them, etc. Can be called on the local client or server, depending on who owns the projectile.
Color GetAlpha(Color lightColor) hook same Allows you to determine the color and transparency in which this projectile is drawn. Return null to use the default color (normally light and buff color). Returns null by default. Called on local and remote clients.
bool PreDrawExtras(Player player) hook same Allows you to draw things behind this projectile. Use the Main.EntitySpriteDraw method for drawing. Returns false to stop the game from drawing extras textures related to the projectile (for example, the chains for grappling hooks), useful if you're manually drawing the extras. Returns true by default. Called on local and remote clients.
bool PreDraw(Player player, ref Color lightColor) hook same Allows you to draw things behind this projectile, or to modify the way it is drawn. Use the Main.EntitySpriteDraw method for drawing. Return false to stop the vanilla projectile drawing code (useful if you're manually drawing the projectile). Returns true by default. Called on local and remote clients.
void PostDraw(Player player, Color lightColor) hook same Allows you to draw things in front of this projectile. Use the Main.EntitySpriteDraw method for drawing. This method is called even if PreDraw returns false. Called on local and remote clients.
bool CanUseGrapple(Player player) hook same This code is called whenever the player uses a grappling hook that shoots this type of projectile. Use it to change what kind of hook is fired (for example, the Dual Hook does this), to kill old hook projectiles, etc. Called on the local client only.
void UseGrapple(Player player, ref int type) hook same This code is called whenever the player uses a grappling hook that shoots this type of projectile. Use it to change what kind of hook is fired (for example, the Dual Hook does this), to kill old hook projectiles, etc. Called on the local client only.
float GrappleRange() hook same How far away this grappling hook can travel away from its player before it retracts. Called on local, server, and remote clients.
void NumGrappleHooks(Player player, ref int numHooks) hook same How many of this type of grappling hook the given player can latch onto blocks before the hooks start disappearing. Change the numHooks parameter to determine this; by default it will be 3. Called on the local client only.
void GrappleRetreatSpeed(Player player, ref float speed) hook same The speed at which the grapple retreats back to the player after not hitting anything. Defaults to 11, but vanilla hooks go up to 24. Called on local, server, and remote clients.
void GrapplePullSpeed(Player player, ref float speed) hook same The speed at which the grapple pulls the player after hitting something. Defaults to 11, but the Bat Hook uses 16. Called on local, server, and remote clients.
void GrappleTargetPoint(Player player, ref float grappleX, ref float grappleY) hook same The location that the grappling hook pulls the player to. Defaults to the center of the hook projectile. Called on local, server, and remote clients.
bool GrappleCanLatchOnTo(Player player, int x, int y) hook same Whether or not the grappling hook can latch onto the given position in tile coordinates. This position may be air or an actuated tile! Return true to make it latch, false to prevent it, or null to apply vanilla conditions. Returns null by default. Called on local, server, and remote clients.
void EmitEnchantmentVisualsAt(Vector2 boxPosition, int boxWidth, int boxHeight) hook not here Called when EmitEnchantmentVisualsAt is called. Typically used to spawn visual effects (Dust) indicating weapon enchantments such as flasks, frost armor, or magma stone effects. This is similar to how items spawn visual effects in MeleeEffects, but for projectiles instead. A typical weapon enchantment would likely include similar code in both to support weapon enchantment visuals for both items and projectiles. Projectiles can use noEnchantments to indicate that a projectile should not be considered for enchantment visuals, so check that field if relevant. Called on local, server, and remote clients.
void FlailStats(ref int launchTimeLimit, ref float launchSpeed, ref float maxLaunchLength, ref float retractAcceleration, ref float maxRetractSpeed, ref float forcedRetractAcceleration, ref float maxForcedRetractSpeed, ref int ricochetTimeLimit, ref float spinVisualDistance) hook not here Used to adjust flail properties. Called when aiStyle is Flail.
void FlailSpinCollisionRange(ref float range) hook not here Used to adjust flail spin collision range. Called during Colliding when aiStyle is Flail.

Projectile

struct Terraria.Projectile : IEntityWithGlobals<GlobalProjectile>

What Bunny Loader adds to the game's projectile.

Member Kind tModLoader What it does
IEntitySource GetSource_FromThis(string context) method same The source for what this projectile creates.
bool IsMinionOrSentryRelated property same Checks if the projectile is a minion, sentry, minion shot, or sentry shot.
IEntitySource GetSource_DropAsItem(string context) method same The source for an item it turns into.
IEntitySource GetSource_Death(string context) method only here The source for what it creates at death.
void KillOldestJavelin(int protectedProjectileIndex, int projectileType, int targetNPCIndex, Point[] bufferForScan) static method same Removes the oldest javelin stuck in the same NPC.
IReadOnlyList<GlobalProjectile> EntityGlobals property differs Its GlobalProjectile instances. tML: RefReadOnlyArray<GlobalProjectile> EntityGlobals
T GetGlobalProjectile<T>() method same Gets the instance of the specified GlobalProjectile type. This will throw exceptions on failure.
T GetGlobalProjectile<T>(T baseInstance) method same Gets the local instance of the type of the specified GlobalProjectile instance. This will throw exceptions on failure.
bool TryGetGlobalProjectile<T>(out T result) method same Gets the instance of the specified GlobalProjectile type.
bool TryGetOwner(out Player player) method same Attempts to get the owner player of this projectile. Returns null for projectiles spawned by TownNPC (npcProj) and trap projectiles (trap). Returns Main.player[owner] otherwise. Note that this logic assumes that projectiles have the correct fields set, which might not always be true. Also note that in single player enemy projectiles are also "owned" by the player, so this alone isn't sufficient to know which projectiles were spawned by the player. Additional friendly checks would be needed for that.
DamageClass DamageType property same The damage type assigned to this projectile, represented as a DamageClass. Leave blank or use DamageClass.Default to prevent damage type scaling of any kind for this projectile. Use DamageClass.Generic/Melee/Ranged/Magic/Summon/Throwing for vanilla damage types. Refer to ExampleMod for more information on how to create and use your own damage types.
bool CountsAsClass<T>() method same Whether its damage counts as the class T.
bool CountsAsClass(DamageClass damageClass) method same Whether its damage counts as the class T.
int NewProjectile(IEntitySource spawnSource, Vector2 position, Vector2 velocity, int Type, int Damage, float KnockBack, int Owner, float ai0, float ai1, float ai2) static method differs Creates a projectile. Returns its index in Main.projectile. tML: int NewProjectile(IEntitySource spawnSource, Vector2 position, Vector2 velocity, int Type, int Damage, float KnockBack, int Owner, float ai0, float ai1, float ai2, NewProjectileModifier modifer)
int NewProjectile(IEntitySource spawnSource, float X, float Y, float SpeedX, float SpeedY, int Type, int Damage, float KnockBack, int Owner, float ai0, float ai1, float ai2) static method differs Creates a projectile. Returns its index in Main.projectile. tML: int NewProjectile(IEntitySource spawnSource, Vector2 position, Vector2 velocity, int Type, int Damage, float KnockBack, int Owner, float ai0, float ai1, float ai2, NewProjectileModifier modifer)
Projectile NewProjectileDirect(IEntitySource spawnSource, Vector2 position, Vector2 velocity, int type, int damage, float knockback, int owner, float ai0, float ai1, float ai2) static method differs This particular overload uses a Vector2 instead of X and Y to determine the actual spawn position and a Vector2 to dictate the initial velocity. The return value is the actual Projectile instance rather than the index of the spawned Projectile within the projectile array. A short-hand for Main.projectile[Projectile.NewProjectile(...)] tML: Projectile NewProjectileDirect(IEntitySource spawnSource, Vector2 position, Vector2 velocity, int type, int damage, float knockback, int owner, float ai0, float ai1, float ai2, NewProjectileModifier modifer)
ModProjectile ModProjectile property same The ModProjectile instance that controls the behavior of this projectile. This property is null if this is not a modded projectile.
void CloneDefaults(int TypeToClone) method same Copies the defaults of another projectile, keeping this type.
DrawData GetDefaultDrawData(Player player, Color lightColor) method same Calculates the default drawing parameters for this projectile. This can be used to easily implement custom drawing without reimplementing the vanilla drawing logic, usually in PreDraw or PostDraw. Note that this is only valid for modded projectiles and does not replicate any custom logic that would adjust the drawing parameters for vanilla projectiles. This also does not apply to projectiles drawn with specialized logic, such as spears and chain-drawn projectiles, or projectiles with hardcoded type-specific draw parameters, like golf balls. The returned DrawData can be adjusted and then drawn with EntitySpriteDraw: var drawData = Projectile.GetDefaultDrawData(player, lightColor); var adjustedDrawData = drawData with { color = Color.Blue }; // Adjust any parameter here Main.EntitySpriteDraw(adjustedDrawData);
ref WhipSettings WhipSettings property differs The segments and range of a whip. tML: WhipSettings WhipSettings
void FillWhipControlPoints(Projectile proj, List<Vector2> controlPoints, Player owner, bool getActualCollisionPoints, int frameOffset) static method same The points of a whip's line.

ProjectileDefinition

class Terraria.ModLoader.Config.ProjectileDefinition : EntityDefinition

ProjectileDefinition represents a Projectile identity.

Member Kind tModLoader What it does
Func<TagCompound, ProjectileDefinition> DESERIALIZER static field same Rebuilds this value from a TagCompound.
int Type override same The content ID of the content this EntityDefinition represents. Will be -1 for IsUnloaded EntityDefinition.
new ProjectileDefinition() constructor same Creates an instance.
new ProjectileDefinition(int type) constructor same Note: As ModConfig loads before other content, make sure to only use ProjectileDefinition for modded content in ModConfig classes.
new ProjectileDefinition(string key) constructor same Creates an instance.
new ProjectileDefinition(string mod, string name) constructor same Creates an instance.
ProjectileDefinition FromString(string s) static method same Builds this value from its text form.
ProjectileDefinition Load(TagCompound tag) static method same Rebuilds the definition from a tag.
string DisplayName override same The name shown to the player, as localized text.

ProjectileID

struct Terraria.ID.ProjectileID

Projectile types. A mod projectile's type comes from ModContent.ProjectileType<T>().

Member Kind tModLoader What it does

ProjectileID.Sets

static class Terraria.ID.ProjectileID.Sets

Tables indexed by projectile type.

Member Kind tModLoader What it does
ContentBoolTable IsInteractable static field only here Phone: A tap on the projectile reaches Main.mouseRight during its PreDraw and PostDraw, as tModLoader's code expects.
ContentTable<FallingBlockTileItemInfo> FallingBlockTileItem static field only here The tile and item a falling block becomes.
bool[] Explosive static property same Is an explosive.

ProjectileID.Sets.FallingBlockTileItemInfo

class Terraria.ID.ProjectileID.Sets.FallingBlockTileItemInfo

Used in FallingBlockTileItem.

Member Kind tModLoader What it does
new FallingBlockTileItemInfo(int TileType, int ItemType) constructor same Creates an instance.
int TileType property same The tile it lands as.
int ItemType property same The item it drops when it cannot land.

ProjectileLoader

static class Terraria.ModLoader.ProjectileLoader

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

Member Kind tModLoader What it does
int ProjectileCount static property same How many exist, with the game's and every mod's.
ModProjectile GetProjectile(int type) static method same Gets the ModProjectile template instance corresponding to the specified type (not the clone/new instance which gets added to Projectiles as the game is played).
bool PreAI(Projectile projectile) static method same Allows you to determine how this projectile behaves. Return false to stop the vanilla AI and the AI hook from being run. Returns true by default. Called on local, server, and remote clients.
void AI(Projectile projectile) static method same Allows you to determine how this projectile behaves. This will only be called if PreAI returns true. The Basic Projectile Guide teaches the basics of writing a custom AI, such as timers, gravity, rotation, etc. Called on local, server, and remote clients.
void PostAI(Projectile projectile) static method same Allows you to determine how this projectile behaves. This will be called regardless of what PreAI returns. Called on local, server, and remote clients.
bool ShouldUpdatePosition(Projectile projectile) static method same Whether or not this projectile should update its position based on factors such as its velocity, whether it is in liquid, etc. Return false to make its velocity have no effect on its position. Returns true by default. Called on local, server, and remote clients.
void ModifyFishingLine(Projectile projectile, ref float polePosX, ref float polePosY, ref Color lineColor) static method same Runs ModifyFishingLine.
void SendExtraAI(BinaryWriter writer, byte[] extraAI) static method same If you are storing AI information outside of the Projectile.ai array, use this to send that AI information between clients and servers, which will be handled in ReceiveExtraAI. Called whenever SyncProjectile is successfully sent, for example on projectile creation, or whenever Projectile.netUpdate is set to true in the update loop for that tick. Can be called on the local client or server, depending on who owns the projectile.
byte[] WriteExtraAI(Projectile projectile) static method same The bytes of SendExtraAI.
byte[] ReadExtraAI(BinaryReader reader) static method same The bytes for ReceiveExtraAI.
void ReceiveExtraAI(Projectile projectile, byte[] extraAI) static method same Use this to receive information that was sent in SendExtraAI. Called whenever SyncProjectile is successfully received. Can be called on the local client or server, depending on who owns the projectile.
bool TileCollideStyle(Projectile projectile, ref int width, ref int height, ref bool fallThrough, ref Vector2 hitboxCenterFrac) static method same Allows you to determine how this projectile interacts with tiles. Return false if you completely override or cancel this projectile's tile collision behavior. Returns true by default. Called on local, server, and remote clients.
bool CanCutTiles(Projectile projectile) static method same Return true or false to specify if the projectile can cut tiles like vines, pots, and Queen Bee larva. Return null for vanilla decision. Can be called on the local client or server, depending on who owns the projectile.
void CutTiles(Projectile projectile) static method same Code ran when the projectile cuts tiles. Only runs if CanCutTiles() returns true. Useful when programming lasers and such. Can be called on the local client or server, depending on who owns the projectile.
bool OnTileCollide(Projectile projectile, Vector2 oldVelocity) static method same Allows you to determine what happens when this projectile collides with a tile. OldVelocity is the velocity before tile collision. The velocity that takes tile collision into account can be found with Projectile.velocity. Return true to allow the vanilla tile collision code to take place (which normally kills the projectile). Returns true by default. Called on local, server, and remote clients.
bool PreKill(Projectile projectile, int timeLeft) static method same Allows you to determine whether the vanilla code for Kill and the Kill hook will be called. Return false to stop them from being called. Returns true by default. Note that this does not stop the projectile from dying. Called on local, server, and remote clients.
void OnKill(Projectile projectile, int timeLeft) static method same Allows you to control what happens when this projectile is killed (for example, creating dust or making sounds). Also useful for creating retrievable ammo. Be sure to check if (Projectile.owner == Main.myPlayer) for logic that should only run for the projectile owner. Some examples include spawning items, spawning projectiles, and modifying tiles. Called on local, server, and remote clients.
bool CanDamage(Projectile projectile) static method same Whether or not this projectile is capable of killing tiles (such as grass) and damaging NPCs/players. Return false to prevent it from doing any sort of damage. Return true if you want the projectile to do damage regardless of the default blacklist. Return null to let the projectile follow vanilla can-damage-anything rules. This is what happens by default. Called on local, server, and remote clients.
bool MinionContactDamage(Projectile projectile) static method same Whether or not this minion can damage NPCs by touching them. Returns false by default. Note that this will only be used if this projectile is considered a pet (projPet). Called on local, server, and remote clients.
void ModifyDamageHitbox(Projectile projectile, ref Rectangle hitbox) static method same Allows you to change the hitbox used by this projectile for damaging players and NPCs. Called on local, server, and remote clients.
bool CanHitNPC(Projectile projectile, NPC target) static method same Allows you to determine whether this projectile can hit the given NPC. Return true to allow hitting the target, return false to block this projectile from hitting the target, and return null to use the vanilla code for whether the target can be hit. Returns null by default. Can be called on the local client or server, depending on who owns the projectile.
void ModifyHitNPC(Projectile projectile, NPC target, ref HitModifiers modifiers) static method same Allows you to modify the damage, knockback, etc., that this projectile does to an NPC. Can be called on the local client or server, depending on who owns the projectile.
void OnHitNPC(Projectile projectile, NPC target, in HitInfo hit, int damageDone) static method same Allows you to create special effects when this projectile hits an NPC (for example, inflicting debuffs). Can be called on the local client or server, depending on who owns the projectile.
bool CanHitPvp(Projectile projectile, Player target) static method same Allows you to determine whether this projectile can hit the given opponent player. Return false to block this projectile from hitting the target. Returns true by default. Called on the client hitting the target.
bool CanHitPlayer(Projectile projectile, Player target) static method same Allows you to determine whether this hostile projectile can hit the given player. Return false to block this projectile from hitting the target. Returns true by default. Called on the server only.
void ModifyHitPlayer(Projectile projectile, Player target, ref HurtModifiers modifiers) static method same Allows you to modify the damage, etc., that this hostile projectile does to a player. Called on the client taking damage.
void OnHitPlayer(Projectile projectile, Player target, in HurtInfo hurtInfo) static method same Allows you to create special effects when this hostile projectile hits a player. Called on the client taking damage.
bool Colliding(Projectile projectile, Rectangle projHitbox, Rectangle targetHitbox) static method same Allows you to use custom collision detection between this projectile and a player or NPC that this projectile can damage. Useful for things like diagonal lasers, projectiles that leave a trail behind them, etc. Can be called on the local client or server, depending on who owns the projectile.
Color GetAlpha(Projectile projectile, Color lightColor) static method same Allows you to determine the color and transparency in which this projectile is drawn. Return null to use the default color (normally light and buff color). Returns null by default. Called on local and remote clients.
bool PreDrawExtras(Projectile projectile, Player player) static method same Allows you to draw things behind this projectile. Use the Main.EntitySpriteDraw method for drawing. Returns false to stop the game from drawing extras textures related to the projectile (for example, the chains for grappling hooks), useful if you're manually drawing the extras. Returns true by default. Called on local and remote clients.
bool PreDraw(Projectile projectile, Player player, ref Color lightColor) static method same Allows you to draw things behind this projectile, or to modify the way it is drawn. Use the Main.EntitySpriteDraw method for drawing. Return false to stop the vanilla projectile drawing code (useful if you're manually drawing the projectile). Returns true by default. Called on local and remote clients.
void PostDraw(Projectile projectile, Player player, Color lightColor) static method same Allows you to draw things in front of this projectile. Use the Main.EntitySpriteDraw method for drawing. This method is called even if PreDraw returns false. Called on local and remote clients.
bool CanUseGrapple(int type, Player player) static method same This code is called whenever the player uses a grappling hook that shoots this type of projectile. Use it to change what kind of hook is fired (for example, the Dual Hook does this), to kill old hook projectiles, etc. Called on the local client only.
void UseGrapple(Player player, ref int type) static method same This code is called whenever the player uses a grappling hook that shoots this type of projectile. Use it to change what kind of hook is fired (for example, the Dual Hook does this), to kill old hook projectiles, etc. Called on the local client only.
bool GrappleOutOfRange(float distance, Projectile projectile) static method same Whether a hook has gone too far.
void NumGrappleHooks(Projectile projectile, Player player, ref int numHooks) static method same How many of this type of grappling hook the given player can latch onto blocks before the hooks start disappearing. Change the numHooks parameter to determine this; by default it will be 3. Called on the local client only.
void GrappleRetreatSpeed(Projectile projectile, Player player, ref float speed) static method same The speed at which the grapple retreats back to the player after not hitting anything. Defaults to 11, but vanilla hooks go up to 24. Called on local, server, and remote clients.
void GrapplePullSpeed(Projectile projectile, Player player, ref float speed) static method same The speed at which the grapple pulls the player after hitting something. Defaults to 11, but the Bat Hook uses 16. Called on local, server, and remote clients.
void GrappleTargetPoint(Projectile projectile, Player player, ref float grappleX, ref float grappleY) static method same The location that the grappling hook pulls the player to. Defaults to the center of the hook projectile. Called on local, server, and remote clients.
bool GrappleCanLatchOnTo(Projectile projectile, Player player, int x, int y) static method same Whether or not the grappling hook can latch onto the given position in tile coordinates. This position may be air or an actuated tile! Return true to make it latch, false to prevent it, or null to apply vanilla conditions. Returns null by default. Called on local, server, and remote clients.
void ProjectileAI(Projectile projectile) static method not here Internal here. Override ModProjectile.AI or GlobalProjectile.AI.
void DrawOffset(Projectile projectile, ref int offsetX, ref int offsetY, ref float originX) static method not here Internal here.
void FlailStats(Projectile projectile, ref int launchTimeLimit, ref float launchSpeed, ref float maxLaunchLength, ref float retractAcceleration, ref float maxRetractSpeed, ref float forcedRetractAcceleration, ref float maxForcedRetractSpeed, ref int ricochetTimeLimit, ref float spinVisualDistance) static method not here Used to adjust flail properties. Called when aiStyle is Flail.
void FlailSpinCollisionRange(Projectile projectile, ref float range) static method not here Used to adjust flail spin collision range. Called during Colliding when aiStyle is Flail.

← NPCs  ·  Players, buffs and mounts →

Clone this wiki locally