tModLoader v2024.09
A mod to make and play Terraria mods
GlobalType< TEntity, TGlobal > Class Template Reference

Inherits GlobalType< TGlobal >, and ModType< TEntity, TModType >.

Public Member Functions

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. More...
 
- Public Member Functions inherited from GlobalType< TGlobal >
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. More...
 
- Public Member Functions inherited from ModType< TEntity, TModType >
virtual TModType Clone (TEntity newEntity)
 Create a copy of this instanced global. Called when an entity is cloned. More...
 
virtual bool IsLoadingEnabled (Mod mod)
 Allows you to stop Mod.AddContent from actually adding this content. Useful for items that can be disabled by a config. More...
 
virtual void Load ()
 Allows you to perform one-time loading tasks. Beware that mod content has not finished loading here, things like ModContent lookup tables or ID Sets are not fully populated. More...
 
virtual TModType NewInstance (TEntity entity)
 Create a new instance of this ModType for a specific entity More...
 
string PrettyPrintName ()
 
virtual void SetStaticDefaults ()
 Allows you to modify the properties after initial loading has completed. More...
 
virtual void SetupContent ()
 If you make a new ModType, seal this override, and call SetStaticDefaults in it. More...
 
virtual void Unload ()
 Allows you to safely unload things you added in Load. More...
 
virtual bool IsLoadingEnabled (Mod mod)
 Whether or not this type should be loaded when it's told to. Returning false disables Mod.AddContent from actually loading this type. More...
 
abstract void Load (Mod mod)
 Called when loading the type. More...
 
abstract void Unload ()
 Called during unloading when needed. More...
 
- Public Member Functions inherited from ModType< TEntity >
virtual TModType Clone (TEntity newEntity)
 Create a copy of this instanced global. Called when an entity is cloned. More...
 
virtual bool IsLoadingEnabled (Mod mod)
 Allows you to stop Mod.AddContent from actually adding this content. Useful for items that can be disabled by a config. More...
 
virtual void Load ()
 Allows you to perform one-time loading tasks. Beware that mod content has not finished loading here, things like ModContent lookup tables or ID Sets are not fully populated. More...
 
virtual TModType NewInstance (TEntity entity)
 Create a new instance of this ModType for a specific entity More...
 
string PrettyPrintName ()
 
virtual void SetStaticDefaults ()
 Allows you to modify the properties after initial loading has completed. More...
 
virtual void SetupContent ()
 If you make a new ModType, seal this override, and call SetStaticDefaults in it. More...
 
virtual void Unload ()
 Allows you to safely unload things you added in Load. More...
 

Static Public Member Functions

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)
 
- Static Public Member Functions inherited from GlobalType< TGlobal >
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)
 

Protected Member Functions

override void Register ()
 If you make a new ModType, seal this override. More...
 
override void ValidateType ()
 Check for the correct overrides of different hook methods and fields and properties More...
 
- Protected Member Functions inherited from GlobalType< TGlobal >
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
 
- Protected Member Functions inherited from ModType< TEntity, TModType >
abstract TEntity CreateTemplateEntity ()
 
virtual void InitTemplateInstance ()
 Create dummy objects for instanced mod-types More...
 
override void InitTemplateInstance ()
 Create dummy objects for instanced mod-types More...
 
abstract void Register ()
 If you make a new ModType, seal this override. More...
 
virtual void ValidateType ()
 Check for the correct overrides of different hook methods and fields and properties More...
 
- Protected Member Functions inherited from ModType< TEntity >
abstract TEntity CreateTemplateEntity ()
 
virtual void InitTemplateInstance ()
 Create dummy objects for instanced mod-types More...
 
override void InitTemplateInstance ()
 Create dummy objects for instanced mod-types
 
abstract void Register ()
 If you make a new ModType, seal this override. More...
 
virtual void ValidateType ()
 Check for the correct overrides of different hook methods and fields and properties More...
 

Properties

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
 
- Properties inherited from GlobalType< TGlobal >
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
 
- Properties inherited from ModType< TEntity, TModType >
virtual bool CloneNewInstances [get]
 Whether to create new instances of this mod type via Clone(TEntity) or via the default constructor Defaults to false (default constructor).
 
TEntity Entity [get, set]
 
string FullName [get]
 The internal name of this, including the mod it is from. More...
 
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]
 
Mod Mod [get, set]
 The mod this belongs to. More...
 
virtual string Name [get]
 The internal name of this. More...
 
- Properties inherited from IModType
string FullName [get]
 => $"{Mod.Name}/{Name}" More...
 
Mod Mod [get]
 The mod this belongs to. More...
 
string Name [get]
 The internal name of this instance. More...
 
- Properties inherited from ModType< TEntity >
virtual bool CloneNewInstances [get]
 Whether to create new instances of this mod type via Clone(TEntity) or via the default constructor Defaults to false (default constructor).
 
TEntity Entity [get, set]
 
string FullName [get]
 The internal name of this, including the mod it is from. More...
 
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]
 
Mod Mod [get, set]
 The mod this belongs to. More...
 
virtual string Name [get]
 The internal name of this. More...
 

Member Function Documentation

◆ AppliesToEntity()

virtual bool GlobalType< TEntity, TGlobal >.AppliesToEntity ( TEntity  entity,
bool  lateInstantiation 
)
virtual

Use this to control whether or not this global should be run on the provided entity instance.

Parameters
entityThe entity for which the global instantiation is being checked.
lateInstantiationWhether this check occurs before or after the ModX.SetDefaults call.
If you're relying on entity values that can be changed by that call, you should likely prefix your return value with the following:
lateInstantiation &amp;&amp; ...

Reimplemented from GlobalType< TGlobal >.

Reimplemented in GlobalType< TEntity, TGlobal >.

◆ Clone()

virtual TGlobal GlobalType< TEntity, TGlobal >.Clone ( TEntity?  from,
TEntity  to 
)
virtual

Create a copy of this instanced global. Called when an entity is cloned.

Parameters
fromThe entity being cloned. May be null if CloneNewInstances is true (via call from NewInstance(TEntity))
toThe new clone of the entity
Returns
A clone of this global

Reimplemented from GlobalType< TGlobal >.

Reimplemented in GlobalType< TEntity, TGlobal >.

◆ GetGlobal< TResult >() [1/2]

static TResult GlobalType< TEntity, TGlobal >.GetGlobal< TResult > ( int  entityType,
ReadOnlySpan< TGlobal >  entityGlobals 
)
static
Type Constraints
TResult :TGlobal 
TResult :TryGetGlobal 
TResult :entityType 
TResult :entityGlobals 
TResult :out 
TResult :TResult 
TResult :result 
TResult :result 
TResult :throw 
TResult :new 
TResult :KeyNotFoundException 
TResult :typeof 
TResult :TResult 
TResult :FullName 

◆ GetGlobal< TResult >() [2/2]

static TResult GlobalType< TEntity, TGlobal >.GetGlobal< TResult > ( int  entityType,
ReadOnlySpan< TGlobal >  entityGlobals,
TResult  baseInstance 
)
static
Type Constraints
TResult :TGlobal 
TResult :TryGetGlobal 
TResult :entityType 
TResult :entityGlobals 
TResult :baseInstance 
TResult :out 
TResult :TResult 
TResult :result 
TResult :result 
TResult :throw 
TResult :new 
TResult :KeyNotFoundException 
TResult :baseInstance.FullName 

◆ NewInstance()

virtual ? TGlobal GlobalType< TEntity, TGlobal >.NewInstance ( TEntity  target)
virtual

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

Parameters
targetThe entity instance the global is being instantiated for
Returns

Reimplemented from GlobalType< TGlobal >.

Reimplemented in GlobalType< TEntity, TGlobal >.

◆ Register()

override void GlobalType< TEntity, TGlobal >.Register ( )
protectedvirtual

If you make a new ModType, seal this override.

Implements ModType< TEntity >.

◆ SetDefaults()

virtual void GlobalType< TEntity, TGlobal >.SetDefaults ( TEntity  entity)
virtual

Allows you to set the properties of any and every instance that gets created.

Reimplemented from GlobalType< TGlobal >.

Reimplemented in GlobalType< TEntity, TGlobal >.

◆ TryGetGlobal< TResult >() [1/2]

static bool GlobalType< TEntity, TGlobal >.TryGetGlobal< TResult > ( int  entityType,
ReadOnlySpan< TGlobal >  entityGlobals,
out TResult  result 
)
static
Type Constraints
TResult :TGlobal 
TResult :TryGetGlobal 
TResult :entityType 
TResult :entityGlobals 
TResult :ModContent.GetInstance<TResult>() 
TResult :out 
TResult :result 

◆ TryGetGlobal< TResult >() [2/2]

static bool GlobalType< TEntity, TGlobal >.TryGetGlobal< TResult > ( int  entityType,
ReadOnlySpan< TGlobal >  entityGlobals,
TResult  baseInstance,
out TResult  result 
)
static
Type Constraints
TResult :TGlobal 

◆ ValidateType()

override void GlobalType< TEntity, TGlobal >.ValidateType ( )
protectedvirtual

Check for the correct overrides of different hook methods and fields and properties

Reimplemented from ModType< TEntity >.