tModLoader v2024.09
A mod to make and play Terraria mods
GlobalProjectile Class Reference

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

Inherits GlobalType< Projectile, GlobalProjectile >.

Public Member Functions

virtual void AI (Projectile projectile)
 Allows you to determine how any projectile behaves. This will only be called if PreAI returns true. More...
 
virtual ? bool CanCutTiles (Projectile projectile)
 Return true or false to specify if the projectile can cut tiles like vines, pots, and Queen Bee larva. Return null for vanilla decision. More...
 
virtual ? bool CanDamage (Projectile projectile)
 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. More...
 
virtual ? bool CanHitNPC (Projectile projectile, NPC target)
 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. More...
 
virtual bool CanHitPlayer (Projectile projectile, Player target)
 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. More...
 
virtual bool CanHitPvp (Projectile projectile, Player target)
 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. More...
 
virtual ? bool CanUseGrapple (int type, Player player)
 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.
 
virtual ? bool Colliding (Projectile projectile, Rectangle projHitbox, Rectangle targetHitbox)
 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. More...
 
virtual void CutTiles (Projectile projectile)
 Code ran when the projectile cuts tiles. Only runs if CanCutTiles() returns true. Useful when programming lasers and such. More...
 
virtual void DrawBehind (Projectile projectile, int index, List< int > behindNPCsAndTiles, List< int > behindNPCs, List< int > behindProjectiles, List< int > overPlayers, List< int > overWiresUI)
 When used in conjunction with "projectile.hide = true", allows you to specify that this projectile should be drawn behind certain elements. Add the index to one and only one of the lists. For example, the Nebula Arcanum projectile draws behind NPCs and tiles. More...
 
virtual void EmitEnchantmentVisualsAt (Projectile projectile, Vector2 boxPosition, int boxWidth, int boxHeight)
 
virtual ? Color GetAlpha (Projectile projectile, Color lightColor)
 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. More...
 
virtual ? bool GrappleCanLatchOnTo (Projectile projectile, Player player, int x, int y)
 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.
 
virtual void GrapplePullSpeed (Projectile projectile, Player player, ref float speed)
 The speed at which the grapple pulls the player after hitting something. Defaults to 11, but the Bat Hook uses 16.
 
virtual void GrappleRetreatSpeed (Projectile projectile, Player player, ref float speed)
 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.
 
virtual void GrappleTargetPoint (Projectile projectile, Player player, ref float grappleX, ref float grappleY)
 The location that the grappling hook pulls the player to. Defaults to the center of the hook projectile.
 
virtual void Kill (Projectile projectile, int timeLeft)
 
virtual bool MinionContactDamage (Projectile projectile)
 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. More...
 
virtual void ModifyDamageHitbox (Projectile projectile, ref Rectangle hitbox)
 Allows you to change the hitbox used by a projectile for damaging players and NPCs. More...
 
virtual void ModifyHitNPC (Projectile projectile, NPC target, ref NPC.HitModifiers modifiers)
 Allows you to modify the damage, knockback, etc., that a projectile does to an NPC. 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 ModifyHitPlayer (Projectile projectile, Player target, ref Player.HurtModifiers modifiers)
 Allows you to modify the damage, etc., that a hostile projectile does to a player. More...
 
virtual void NumGrappleHooks (Projectile projectile, Player player, ref int numHooks)
 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.
 
virtual void OnHitNPC (Projectile projectile, NPC target, NPC.HitInfo hit, int damageDone)
 Allows you to create special effects when a projectile hits an NPC (for example, inflicting debuffs). 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 OnHitPlayer (Projectile projectile, Player target, Player.HurtInfo info)
 Allows you to create special effects when a hostile projectile hits a player.
Only runs on the local client in multiplayer. More...
 
virtual void OnKill (Projectile projectile, int timeLeft)
 Allows you to control what happens when a projectile is killed (for example, creating dust or making sounds). More...
 
virtual void OnSpawn (Projectile projectile, IEntitySource source)
 Gets called when any projectiles spawns in world
 
virtual bool OnTileCollide (Projectile projectile, Vector2 oldVelocity)
 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. More...
 
virtual void PostAI (Projectile projectile)
 Allows you to determine how any projectile behaves. This will be called regardless of what PreAI returns. More...
 
virtual void PostDraw (Projectile projectile, Color lightColor)
 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. More...
 
virtual bool PreAI (Projectile projectile)
 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. More...
 
virtual bool PreDraw (Projectile projectile, ref Color lightColor)
 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. More...
 
virtual bool PreDrawExtras (Projectile projectile)
 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. More...
 
virtual bool PreKill (Projectile projectile, int timeLeft)
 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. More...
 
virtual void PrepareBombToBlow (Projectile projectile)
 
virtual void ReceiveExtraAI (Projectile projectile, BitReader bitReader, BinaryReader binaryReader)
 Use this to receive information that was sent in SendExtraAI.
Called whenever MessageID.SyncProjectile is successfully received.
Can be called on both server and client, depending on who owns the projectile. More...
 
virtual void SendExtraAI (Projectile projectile, BitWriter bitWriter, BinaryWriter binaryWriter)
 Use this judiciously to avoid straining the network.
Checks and methods such as GlobalType<TEntity, TGlobal>.AppliesToEntity can reduce how much data must be sent for how many projectiles.
Called whenever MessageID.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 both server and client, depending on who owns the projectile. More...
 
sealed override void SetupContent ()
 
virtual bool ShouldUpdatePosition (Projectile projectile)
 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. More...
 
virtual bool TileCollideStyle (Projectile projectile, ref int width, ref int height, ref bool fallThrough, ref Vector2 hitboxCenterFrac)
 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. More...
 
virtual void UseGrapple (Player player, ref int type)
 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.
 
- Public Member Functions inherited from GlobalType< Projectile, GlobalProjectile >
virtual bool AppliesToEntity (TEntity entity, bool lateInstantiation)
 Use this to control whether or not this global should be run on the provided entity instance.
More...
 
virtual TGlobal Clone (TEntity? from, TEntity to)
 Create a copy of this instanced global. Called when an entity is cloned. More...
 
TGlobal Instance (TEntity entity)
 
virtual ? TGlobal NewInstance (TEntity target)
 Only called if GlobalType<TGlobal>.InstancePerEntity and AppliesToEntity(target , ...) are both true.

Returning null is permitted but not recommended over AppliesToEntity for performance reasons.
Only return null when the global is disabled based on some runtime property (eg world seed). More...
 
virtual void SetDefaults (TEntity entity)
 Allows you to set the properties of any and every instance that gets created.
 

Protected Member Functions

sealed override void Register ()
 
override void ValidateType ()
 
- Protected Member Functions inherited from GlobalType< Projectile, GlobalProjectile >
override void Register ()
 If you make a new ModType, seal this override.
 
override void ValidateType ()
 Check for the correct overrides of different hook methods and fields and properties
 

Additional Inherited Members

- Static Public Member Functions inherited from GlobalType< Projectile, GlobalProjectile >
static TResult GetGlobal< TResult > (int entityType, ReadOnlySpan< TGlobal > entityGlobals)
 
static TResult GetGlobal< TResult > (int entityType, ReadOnlySpan< TGlobal > entityGlobals, TResult baseInstance)
 
static bool TryGetGlobal< TResult > (int entityType, ReadOnlySpan< TGlobal > entityGlobals, out TResult result)
 
static bool TryGetGlobal< TResult > (int entityType, ReadOnlySpan< TGlobal > entityGlobals, TResult baseInstance, out TResult result)
 
- Properties inherited from GlobalType< Projectile, GlobalProjectile >
virtual bool CloneNewInstances [get]
 Whether to create new instances of this mod type via Clone or via the default constructor Defaults to false (default constructor).
 
abstract bool ConditionallyAppliesToEntities [get]
 Whether this global applies to some entities but not others
 
sealed override bool ConditionallyAppliesToEntities [get]
 Whether this global applies to some entities but not others.
True if the type overrides AppliesToEntity(TEntity, bool)
 
virtual bool InstancePerEntity [get]
 Whether to create a new instance of this Global for every entity that exists. Useful for storing information on an entity. Defaults to false. Return true if you need to store information (have non-static fields).
 
virtual bool IsCloneable [get]
 Whether or not this type is cloneable. Cloning is supported if
all reference typed fields in each sub-class which doesn't override Clone are marked with [CloneByReference]
 
short PerEntityIndex [get, set]
 Index of this global in a IEntityWithGlobals<TGlobal>.EntityGlobals array
-1 if this global does not have a SlotPerEntity
 
virtual bool SlotPerEntity [get]
 If true, the global will be assigned a PerEntityIndex at load time, which can be used to access the instance in the IEntityWithGlobals<TGlobal>.EntityGlobals array.
If false, the global will be a singleton applying to all entities
 
short StaticIndex [get, set]
 Index of this global in the list of all globals of the same type, in registration order
 

Detailed Description

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 Function Documentation

◆ AI()

virtual void GlobalProjectile.AI ( Projectile  projectile)
virtual

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

Parameters
projectile

◆ CanCutTiles()

virtual ? bool GlobalProjectile.CanCutTiles ( Projectile  projectile)
virtual

Return true or false to specify if the projectile can cut tiles like vines, pots, and Queen Bee larva. Return null for vanilla decision.

Parameters
projectile
Returns

◆ CanDamage()

virtual ? bool GlobalProjectile.CanDamage ( Projectile  projectile)
virtual

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.

Parameters
projectile
Returns

◆ CanHitNPC()

virtual ? bool GlobalProjectile.CanHitNPC ( Projectile  projectile,
NPC  target 
)
virtual

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.

Parameters
projectile
target
Returns

◆ CanHitPlayer()

virtual bool GlobalProjectile.CanHitPlayer ( Projectile  projectile,
Player  target 
)
virtual

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.

Parameters
projectile
target
Returns

◆ CanHitPvp()

virtual bool GlobalProjectile.CanHitPvp ( Projectile  projectile,
Player  target 
)
virtual

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.

Parameters
projectile
target
Returns

◆ Colliding()

virtual ? bool GlobalProjectile.Colliding ( Projectile  projectile,
Rectangle  projHitbox,
Rectangle  targetHitbox 
)
virtual

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.

Parameters
projectile
projHitbox
targetHitbox
Returns

◆ CutTiles()

virtual void GlobalProjectile.CutTiles ( Projectile  projectile)
virtual

Code ran when the projectile cuts tiles. Only runs if CanCutTiles() returns true. Useful when programming lasers and such.

Parameters
projectile

◆ DrawBehind()

virtual void GlobalProjectile.DrawBehind ( Projectile  projectile,
int  index,
List< int >  behindNPCsAndTiles,
List< int >  behindNPCs,
List< int >  behindProjectiles,
List< int >  overPlayers,
List< int >  overWiresUI 
)
virtual

When used in conjunction with "projectile.hide = true", allows you to specify that this projectile should be drawn behind certain elements. Add the index to one and only one of the lists. For example, the Nebula Arcanum projectile draws behind NPCs and tiles.

Parameters
projectile
index
behindNPCsAndTiles
behindNPCs
behindProjectiles
overPlayers
overWiresUI

◆ GetAlpha()

virtual ? Color GlobalProjectile.GetAlpha ( Projectile  projectile,
Color  lightColor 
)
virtual

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.

Parameters
projectile
lightColor
Returns

◆ MinionContactDamage()

virtual bool GlobalProjectile.MinionContactDamage ( Projectile  projectile)
virtual

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.

Parameters
projectile
Returns

◆ ModifyDamageHitbox()

virtual void GlobalProjectile.ModifyDamageHitbox ( Projectile  projectile,
ref Rectangle  hitbox 
)
virtual

Allows you to change the hitbox used by a projectile for damaging players and NPCs.

Parameters
projectile
hitbox

◆ ModifyHitNPC()

virtual void GlobalProjectile.ModifyHitNPC ( Projectile  projectile,
NPC  target,
ref NPC.HitModifiers  modifiers 
)
virtual

Allows you to modify the damage, knockback, etc., that a projectile does to an NPC. 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
target
modifiers

◆ ModifyHitPlayer()

virtual void GlobalProjectile.ModifyHitPlayer ( Projectile  projectile,
Player  target,
ref Player.HurtModifiers  modifiers 
)
virtual

Allows you to modify the damage, etc., that a hostile projectile does to a player.

Parameters
projectile
target
modifiers

◆ OnHitNPC()

virtual void GlobalProjectile.OnHitNPC ( Projectile  projectile,
NPC  target,
NPC.HitInfo  hit,
int  damageDone 
)
virtual

Allows you to create special effects when a projectile hits an NPC (for example, inflicting debuffs). 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
target
hit
damageDone

◆ OnHitPlayer()

virtual void GlobalProjectile.OnHitPlayer ( Projectile  projectile,
Player  target,
Player.HurtInfo  info 
)
virtual

Allows you to create special effects when a hostile projectile hits a player.
Only runs on the local client in multiplayer.

Parameters
projectile
target
info

◆ OnKill()

virtual void GlobalProjectile.OnKill ( Projectile  projectile,
int  timeLeft 
)
virtual

Allows you to control what happens when a projectile is killed (for example, creating dust or making sounds).

Parameters
projectile
timeLeft

◆ OnTileCollide()

virtual bool GlobalProjectile.OnTileCollide ( Projectile  projectile,
Vector2  oldVelocity 
)
virtual

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.

Parameters
projectile
oldVelocity
Returns

◆ PostAI()

virtual void GlobalProjectile.PostAI ( Projectile  projectile)
virtual

Allows you to determine how any projectile behaves. This will be called regardless of what PreAI returns.

Parameters
projectile

◆ PostDraw()

virtual void GlobalProjectile.PostDraw ( Projectile  projectile,
Color  lightColor 
)
virtual

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.

Parameters
projectileThe projectile.
lightColorThe color of the light at the projectile's center, after being modified by vanilla and other mods.

◆ PreAI()

virtual bool GlobalProjectile.PreAI ( Projectile  projectile)
virtual

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.

Parameters
projectile
Returns

◆ PreDraw()

virtual bool GlobalProjectile.PreDraw ( Projectile  projectile,
ref Color  lightColor 
)
virtual

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.

Parameters
projectileThe projectile.
lightColorThe color of the light at the projectile's center.

◆ PreDrawExtras()

virtual bool GlobalProjectile.PreDrawExtras ( Projectile  projectile)
virtual

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.

Parameters
projectileThe projectile.

◆ PreKill()

virtual bool GlobalProjectile.PreKill ( Projectile  projectile,
int  timeLeft 
)
virtual

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.

Parameters
projectile
timeLeft
Returns

◆ ReceiveExtraAI()

virtual void GlobalProjectile.ReceiveExtraAI ( Projectile  projectile,
BitReader  bitReader,
BinaryReader  binaryReader 
)
virtual

Use this to receive information that was sent in SendExtraAI.
Called whenever MessageID.SyncProjectile is successfully received.
Can be called on both server and client, depending on who owns the projectile.

Parameters
projectileThe projectile.
bitReaderThe compressible bit reader.
binaryReaderThe reader.

◆ SendExtraAI()

virtual void GlobalProjectile.SendExtraAI ( Projectile  projectile,
BitWriter  bitWriter,
BinaryWriter  binaryWriter 
)
virtual

Use this judiciously to avoid straining the network.
Checks and methods such as GlobalType<TEntity, TGlobal>.AppliesToEntity can reduce how much data must be sent for how many projectiles.
Called whenever MessageID.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 both server and client, depending on who owns the projectile.

Parameters
projectileThe projectile.
bitWriterThe compressible bit writer. Booleans written via this are compressed across all mods to improve multiplayer performance.
binaryWriterThe writer.

◆ ShouldUpdatePosition()

virtual bool GlobalProjectile.ShouldUpdatePosition ( Projectile  projectile)
virtual

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.

Parameters
projectile
Returns

◆ TileCollideStyle()

virtual bool GlobalProjectile.TileCollideStyle ( Projectile  projectile,
ref int  width,
ref int  height,
ref bool  fallThrough,
ref Vector2  hitboxCenterFrac 
)
virtual

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.

Parameters
projectileThe projectile.
widthThe width of the hitbox the projectile will use for tile collision. If vanilla or a mod don't modify it, defaults to projectile.width.
heightThe height of the hitbox the projectile will use for tile collision. If vanilla or a mod don't modify it, defaults to projectile.height.
fallThroughWhether or not the projectile falls through platforms and similar tiles.
hitboxCenterFracDetermines by how much the tile collision hitbox's position (top left corner) will be offset from the projectile's real center. If vanilla or a mod don't modify it, defaults to half the hitbox size (new Vector2(0.5f, 0.5f)).
Returns