tModLoader v2025.08
A mod to make and play Terraria mods
ModAchievement Class Reference

Defines a custom achievement and implements how it should act upon completion. An achievement consists of several parts:

The ModAchievement represents a single achievement, it provides the image (Texture), display name (FriendlyName), description (Description), and category (Achievement.SetCategory(AchievementCategory)).

Each achievement also has one or more conditions (AchievementCondition). Conditions can be existing conditions, like crafting specific items or killing specific NPCs, or they can be completely custom. If an achievement has multiple conditions, each must use a unique identifier. Once every condition is completed, the achievement itself is completed and OnCompleted(Achievement) is called.

And finally, each achievement can have an optional tracker. The tracker is responsible for consolidating all of the conditions and reporting a completion progress value shown in the achievements menu. A tracker will be assigned automatically if not assigned in SetStaticDefaults and if there are multiple conditions or if the sole condition has an associated tracker.

Achievements are not loaded on the server. More...

Inherits ModType< Achievement, ModAchievement >, and ILocalizedModType.

Classes

class  After
 
class  Before
 
class  Default
 
class  Position
 

Public Member Functions

CustomFlagCondition AddCondition (string key="Condition")
 
AddCondition< T > (T condition)
 Used to add any custom AchievementCondition. More...
 
CustomFloatCondition AddFloatCondition (float maxValue)
 
CustomFloatCondition AddFloatCondition (string key, float maxValue)
 
CustomIntCondition AddIntCondition (int maxValue)
 
CustomIntCondition AddIntCondition (string key, int maxValue)
 
ItemCraftCondition AddItemCraftCondition (int itemId)
 
ItemCraftCondition AddItemCraftCondition (int[] itemIds)
 
ItemCraftCondition AddItemCraftCondition (string key, int itemId)
 
ItemCraftCondition AddItemCraftCondition (string key, int[] itemIds)
 
ItemPickupCondition AddItemPickupCondition (int itemId)
 
ItemPickupCondition AddItemPickupCondition (int[] itemIds)
 
ItemPickupCondition AddItemPickupCondition (string key, int itemId)
 
ItemPickupCondition AddItemPickupCondition (string key, int[] itemIds)
 
ItemCraftCondition[] AddManyItemCraftCondition (int[] itemIds)
 Adds a ItemCraftCondition for each itemIds entry. Unlike with passing in several Item IDs to AddItemCraftCondition(int[]), this method will require that each Item be crafted rather than just any one of them.
 
ItemPickupCondition[] AddManyItemPickupCondition (int[] itemIds)
 Adds a ItemPickupCondition for each itemIds entry. Unlike with passing in several Item IDs to AddItemPickupCondition(int[]), this method will require that each Item be picked up rather than just any one of them.
 
NPCKilledCondition[] AddManyNPCKilledCondition (int[] npcIDs)
 Adds a NPCKilledCondition for each npcIDs entry. Unlike with passing in several NPC IDs to AddNPCKilledCondition(int[]), this method will require that each NPC be killed rather than just any one of them.
 
NPCKilledCondition AddNPCKilledCondition (int npcID)
 
NPCKilledCondition AddNPCKilledCondition (int[] npcIDs)
 
NPCKilledCondition AddNPCKilledCondition (string key, int npcID)
 
NPCKilledCondition AddNPCKilledCondition (string key, int[] npcIDs)
 
TileDestroyedCondition AddTileDestroyedCondition (int[] tileIds)
 
TileDestroyedCondition AddTileDestroyedCondition (string key, int[] tileIds)
 
virtual void AutoStaticDefaults ()
 Automatically assigns an IAchievementTracker if not yet assigned. Override this if you need to skip this logic.
 
virtual Position GetDefaultPosition ()
 Returns the achievement's default position in regard to vanilla's achievement ordering. Make use of e.g. Before/After, and provide an achievement (for example new After("EYE_ON_YOU")). Consult the Achievement Identifiers section of the Vanilla Content IDs wiki pageto look up the string to use with GetAchievement. You can also use BeforeFirstVanillaAchievement or AfterLastVanillaAchievement to put your achievement at the start/end of the vanilla achievement order.

NOTE: The position must specify a vanilla Achievements.Achievement otherwise an exception will be thrown. Use GetModdedConstraints to order modded achievements.

By default, this hook positions this achievement after all vanilla achievements.
 
virtual IEnumerable< PositionGetModdedConstraints ()
 Modded achievements are placed between vanilla achievements via GetDefaultPosition and, by default, are sorted in load order.
This hook allows you to sort this achievement before/after other modded achievements that were placed between the same two vanilla achievements.
Example: More...
 
virtual void OnCompleted (Achievement achievement)
 Called when the achievement is completed. Use this to add custom behavior when the achievement is achieved.

Note that achievements will only be completed once per user, not per world or per player, so rewarding players with tangible rewards, like an Item, isn't recommended. More...
 
override sealed void SetupContent ()
 If you make a new ModType, seal this override, and call SetStaticDefaults in it. More...
 
- Public Member Functions inherited from ModType< Achievement, ModAchievement >
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.
 
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...
 

Protected Member Functions

override sealed Achievement CreateTemplateEntity ()
 
override sealed void Register ()
 If you make a new ModType, seal this override. More...
 
- Protected Member Functions inherited from ModType< Achievement, ModAchievement >
abstract TEntity CreateTemplateEntity ()
 
virtual void InitTemplateInstance ()
 Create dummy objects for instanced mod-types
 
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
 

Properties

Achievement Achievement [get]
 The Achievement object that this ModAchievement controls.
 
static Position AfterLastVanillaAchievement [get]
 
static Position BeforeFirstVanillaAchievement [get]
 
virtual LocalizedText Description [get]
 Gets the localized description of the achievement.
 
virtual LocalizedText FriendlyName [get]
 Gets the localized friendly name of the achievement.
 
virtual bool Hidden [get]
 Should the achievement be hidden, meaning its name and description will both appear as "???" in the achievements menu.

Defaults to false.
 
virtual int Index [get]
 The index of this achievement within the texture. Additional achievements are placed below on new rows. Can be used to share a achievement texture among multiple achievements. Defaults to 0.
 
override sealed bool IsCloneable [get]
 
string LocalizationCategory [get]
 The category used by this modded content for use in localization keys. Localization keys follow the pattern of "Mods.{ModName}.{Category}.{ContentName}.{DataName}". The Localization wiki pageexplains how custom ModType classes can utilize this. More...
 
Asset< Texture2D > Texture [get]
 The texture loaded from TextureName.
 
virtual string TextureName [get]
 
- Properties inherited from ModType< Achievement, ModAchievement >
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 ILocalizedModType
abstract string LocalizationCategory [get]
 The category used by this modded content for use in localization keys. Localization keys follow the pattern of "Mods.{ModName}.{Category}.{ContentName}.{DataName}". The Localization wiki pageexplains how custom ModType classes can utilize this. More...
 

Detailed Description

Defines a custom achievement and implements how it should act upon completion. An achievement consists of several parts:

The ModAchievement represents a single achievement, it provides the image (Texture), display name (FriendlyName), description (Description), and category (Achievement.SetCategory(AchievementCategory)).

Each achievement also has one or more conditions (AchievementCondition). Conditions can be existing conditions, like crafting specific items or killing specific NPCs, or they can be completely custom. If an achievement has multiple conditions, each must use a unique identifier. Once every condition is completed, the achievement itself is completed and OnCompleted(Achievement) is called.

And finally, each achievement can have an optional tracker. The tracker is responsible for consolidating all of the conditions and reporting a completion progress value shown in the achievements menu. A tracker will be assigned automatically if not assigned in SetStaticDefaults and if there are multiple conditions or if the sole condition has an associated tracker.

Achievements are not loaded on the server.

Member Function Documentation

◆ AddCondition< T >()

T ModAchievement.AddCondition< T > ( condition)

Used to add any custom AchievementCondition.

Type Constraints
T :AchievementCondition 

◆ CreateTemplateEntity()

override sealed Achievement ModAchievement.CreateTemplateEntity ( )
protectedvirtual

◆ GetModdedConstraints()

virtual IEnumerable< Position > ModAchievement.GetModdedConstraints ( )
virtual

Modded achievements are placed between vanilla achievements via GetDefaultPosition and, by default, are sorted in load order.
This hook allows you to sort this achievement before/after other modded achievements that were placed between the same two vanilla achievements.
Example:

yield return new After(ModContent.GetInstance<MinionBossKilled>());

By default, this hook returns null, which indicates that this achievement has no modded ordering constraints.

◆ OnCompleted()

virtual void ModAchievement.OnCompleted ( Achievement  achievement)
virtual

Called when the achievement is completed. Use this to add custom behavior when the achievement is achieved.

Note that achievements will only be completed once per user, not per world or per player, so rewarding players with tangible rewards, like an Item, isn't recommended.

Parameters
achievementThe achievement that was completed.

◆ Register()

override sealed void ModAchievement.Register ( )
protectedvirtual

If you make a new ModType, seal this override.

Implements ModType< Achievement, ModAchievement >.

◆ SetupContent()

override sealed void ModAchievement.SetupContent ( )
virtual

If you make a new ModType, seal this override, and call SetStaticDefaults in it.

Reimplemented from ModType< Achievement, ModAchievement >.

Property Documentation

◆ LocalizationCategory

string ModAchievement.LocalizationCategory
get

The category used by this modded content for use in localization keys. Localization keys follow the pattern of "Mods.{ModName}.{Category}.{ContentName}.{DataName}". The Localization wiki pageexplains how custom ModType classes can utilize this.

Implements ILocalizedModType.