tModLoader v2024.04
A mod to make and play Terraria mods
ModContent Class Reference

Manages content added by mods. Liaisons between mod content and Terraria's arrays and oversees the Loader classes. More...

Static Public Member Functions

static int BuffType< T > ()
 Get the id (type) of a ModBuff by class. Assumes one instance per class. More...
 
static int DustType< T > ()
 Get the id (type) of a ModDust by class. Assumes one instance per class. More...
 
static int EmoteBubbleType< T > ()
 Get the id (type) of a ModEmoteBubble by class. Assumes one instance per class. More...
 
static bool FileExists (string name)
 Returns whether or not a file with the specified name exists. Note that this includes file extension, the folder path, and must start with the mod name at the start of the path: "ModFolder/OtherFolders/FileNameWithExtension"
 
static T Find< T > (string fullname)
 Attempts to find the template instance with the specified full name (not the clone/new instance which gets added to Items/Players/NPCs etc. as the game is played). Caching the result is recommended.This will throw exceptions on failure. More...
 
static T Find< T > (string modName, string name)
 Attempts to find the template instance with the specified name and mod name (not the clone/new instance which gets added to Items/Players/NPCs etc. as the game is played). Caching the result is recommended.This will throw exceptions on failure. More...
 
static IEnumerable< T > GetContent< T > ()
 Returns all registered content instances that derive from the provided type and that are added by all currently loaded mods.
This only includes the 'template' instance for each piece of content, not all the clones/new instances which get added to Items/Players/NPCs etc. as the game is played More...
 
static EquipTexture GetEquipTexture (EquipType type, int slot)
 
static byte[] GetFileBytes (string name)
 Retrieves the contents of a file packaged within the .tmod file as a byte array. Should be used mainly for non-Asset<T> files. The name should be in the format of "ModFolder/OtherFolders/FileNameWithExtension". Throws an ArgumentException if the mod does not exist. Returns null if the file does not exist. A typical usage of this might be to load a text file containing structured data included within your mod. Make sure the txt file is UTF8 encoded and use the following to retrieve file's text contents: string pointsFileContents = Encoding.UTF8.GetString(ModContent.GetFileBytes("MyMod/data/points.txt")); More...
 
static T GetInstance< T > ()
 Returns the template instance of the provided content type (not the clone/new instance which gets added to Items/Players/NPCs etc. as the game is played). More...
 
static int GetModBackgroundSlot (string texture)
 
static int GetModBossHeadSlot (string texture)
 
static ModBuff GetModBuff (int type)
 
static ModDust GetModDust (int type)
 
static int GetModHeadSlot (string texture)
 
static ModItem GetModItem (int type)
 
static ModMount GetModMount (int type)
 
static ModNPC GetModNPC (int type)
 
static ModProjectile GetModProjectile (int type)
 
static ModSurfaceBackgroundStyle GetModSurfaceBackgroundStyle (int style)
 Returns the ModSurfaceBackgroundStyle object with the given ID.
 
static ModTile GetModTile (int type)
 
static ModUndergroundBackgroundStyle GetModUndergroundBackgroundStyle (int style)
 Returns the ModUndergroundBackgroundStyle object with the given ID.
 
static ModWall GetModWall (int type)
 
static ModWaterfallStyle GetModWaterfallStyle (int style)
 Returns the ModWaterfallStyle with the given ID.
 
static ModWaterStyle GetModWaterStyle (int style)
 Returns the ModWaterStyle with the given ID.
 
static int GoreType< T > ()
 Get the id (type) of a ModGore by class. Assumes one instance per class. More...
 
static bool HasAsset (string name)
 Returns whether or not a asset with the specified name exists. Includes the mod name prefix like Request
 
static int ItemType< T > ()
 Get the id (type) of a ModItem by class. Assumes one instance per class. More...
 
static int MountType< T > ()
 Get the id (type) of a ModMount by class. Assumes one instance per class. More...
 
static int NPCType< T > ()
 Get the id (type) of a ModNPC by class. Assumes one instance per class. More...
 
static Stream OpenRead (string assetName, bool newFileStream=false)
 
static int PrefixType< T > ()
 Get the id (type) of a ModPrefix by class. Assumes one instance per class. More...
 
static int ProjectileType< T > ()
 Get the id (type) of a ModProjectile by class. Assumes one instance per class. More...
 
static TeleportPylonType PylonType< T > ()
 Get the id (type) of a ModPylon by class. Assumes one instance per class. If nothing is found, returns 0, or the "Forest Pylon" type. More...
 
static int RarityType< T > ()
 Get the id (type) of a ModRarity by class. Assumes one instance per class. More...
 
static Asset< T > Request< T > (string name, AssetRequestMode mode=AssetRequestMode.AsyncLoad)
 Gets the asset with the specified name. Throws an Exception if the asset does not exist. Modders may wish to use Mod.Assets.Request where the mod name prefix may be omitted for convenience. More...
 
static bool RequestIfExists< T > (string name, out Asset< T > asset, AssetRequestMode mode=AssetRequestMode.AsyncLoad)
 
static void SplitName (string name, out string domain, out string subName)
 
static int TileEntityType< T > ()
 Get the id (type) of a ModTileEntity by class. Assumes one instance per class. More...
 
static int TileType< T > ()
 Get the id (type) of a ModTile by class. Assumes one instance per class. More...
 
static bool TryFind< T > (string fullname, out T value)
 Safely attempts to find the template instance with the specified full name (not the clone/new instance which gets added to Items/Players/NPCs etc. as the game is played). Caching the result is recommended. More...
 
static bool TryFind< T > (string modName, string name, out T value)
 Safely attempts to find the template instance with the specified name and mod name (not the clone/new instance which gets added to Items/Players/NPCs etc. as the game is played). Caching the result is recommended. More...
 
static int WallType< T > ()
 Get the id (type) of a ModWall by class. Assumes one instance per class. More...
 

Detailed Description

Manages content added by mods. Liaisons between mod content and Terraria's arrays and oversees the Loader classes.

Member Function Documentation

◆ BuffType< T >()

static int ModContent.BuffType< T > ( )
static

Get the id (type) of a ModBuff by class. Assumes one instance per class.

Type Constraints
T :ModBuff 
T :GetInstance<T>() 
T :Type 

◆ DustType< T >()

static int ModContent.DustType< T > ( )
static

Get the id (type) of a ModDust by class. Assumes one instance per class.

Type Constraints
T :ModDust 
T :GetInstance<T>() 
T :Type 

◆ EmoteBubbleType< T >()

static int ModContent.EmoteBubbleType< T > ( )
static

Get the id (type) of a ModEmoteBubble by class. Assumes one instance per class.

Type Constraints
T :ModEmoteBubble 
T :GetInstance<T>() 
T :Type 

◆ Find< T >() [1/2]

static T ModContent.Find< T > ( string  fullname)
static

Attempts to find the template instance with the specified full name (not the clone/new instance which gets added to Items/Players/NPCs etc. as the game is played). Caching the result is recommended.This will throw exceptions on failure.

Exceptions
KeyNotFoundException
Type Constraints
T :IModType 
T :ModTypeLookup<T> 
T :Get 
T :fullname 

◆ Find< T >() [2/2]

static T ModContent.Find< T > ( string  modName,
string  name 
)
static

Attempts to find the template instance with the specified name and mod name (not the clone/new instance which gets added to Items/Players/NPCs etc. as the game is played). Caching the result is recommended.This will throw exceptions on failure.

Exceptions
KeyNotFoundException
Type Constraints
T :IModType 
T :ModTypeLookup<T> 
T :Get 
T :modName 
T :name 

◆ GetContent< T >()

static IEnumerable< T > ModContent.GetContent< T > ( )
static

Returns all registered content instances that derive from the provided type and that are added by all currently loaded mods.
This only includes the 'template' instance for each piece of content, not all the clones/new instances which get added to Items/Players/NPCs etc. as the game is played

Type Constraints
T :ILoadable 
T :ContentCache.GetContentForAllMods<T>() 

◆ GetFileBytes()

static byte[] ModContent.GetFileBytes ( string  name)
static

Retrieves the contents of a file packaged within the .tmod file as a byte array. Should be used mainly for non-Asset<T> files. The name should be in the format of "ModFolder/OtherFolders/FileNameWithExtension". Throws an ArgumentException if the mod does not exist. Returns null if the file does not exist. A typical usage of this might be to load a text file containing structured data included within your mod. Make sure the txt file is UTF8 encoded and use the following to retrieve file's text contents: string pointsFileContents = Encoding.UTF8.GetString(ModContent.GetFileBytes("MyMod/data/points.txt"));

Exceptions
MissingResourceException

◆ GetInstance< T >()

static T ModContent.GetInstance< T > ( )
static

Returns the template instance of the provided content type (not the clone/new instance which gets added to Items/Players/NPCs etc. as the game is played).

Type Constraints
T :class 
T :ContentInstance<T> 
T :Instance 

◆ GoreType< T >()

static int ModContent.GoreType< T > ( )
static

Get the id (type) of a ModGore by class. Assumes one instance per class.

Type Constraints
T :ModGore 
T :GetInstance<T>() 
T :Type 

◆ ItemType< T >()

static int ModContent.ItemType< T > ( )
static

Get the id (type) of a ModItem by class. Assumes one instance per class.

Type Constraints
T :ModItem 
T :GetInstance<T>() 
T :Type 

◆ MountType< T >()

static int ModContent.MountType< T > ( )
static

Get the id (type) of a ModMount by class. Assumes one instance per class.

Type Constraints
T :ModMount 
T :GetInstance<T>() 
T :Type 

◆ NPCType< T >()

static int ModContent.NPCType< T > ( )
static

Get the id (type) of a ModNPC by class. Assumes one instance per class.

Type Constraints
T :ModNPC 
T :GetInstance<T>() 
T :Type 

◆ PrefixType< T >()

static int ModContent.PrefixType< T > ( )
static

Get the id (type) of a ModPrefix by class. Assumes one instance per class.

Type Constraints
T :ModPrefix 
T :GetInstance<T>() 
T :Type 

◆ ProjectileType< T >()

static int ModContent.ProjectileType< T > ( )
static

Get the id (type) of a ModProjectile by class. Assumes one instance per class.

Type Constraints
T :ModProjectile 
T :GetInstance<T>() 
T :Type 

◆ PylonType< T >()

static TeleportPylonType ModContent.PylonType< T > ( )
static

Get the id (type) of a ModPylon by class. Assumes one instance per class. If nothing is found, returns 0, or the "Forest Pylon" type.

Type Constraints
T :ModPylon 
T :GetInstance<T>() 
T :PylonType 

◆ RarityType< T >()

static int ModContent.RarityType< T > ( )
static

Get the id (type) of a ModRarity by class. Assumes one instance per class.

Type Constraints
T :ModRarity 
T :GetInstance<T>() 
T :Type 

◆ Request< T >()

static Asset< T > ModContent.Request< T > ( string  name,
AssetRequestMode  mode = AssetRequestMode.AsyncLoad 
)
static

Gets the asset with the specified name. Throws an Exception if the asset does not exist. Modders may wish to use Mod.Assets.Request where the mod name prefix may be omitted for convenience.

Parameters
nameThe path to the asset without extension, including the mod name (or Terraria) for vanilla assets. Eg "ModName/Folder/FileNameWithoutExtension"
modeThe desired timing for when the asset actually loads. Use ImmediateLoad if you need correct dimensions immediately, such as with UI initialization
Type Constraints
T :class 

◆ RequestIfExists< T >()

static bool ModContent.RequestIfExists< T > ( string  name,
out Asset< T >  asset,
AssetRequestMode  mode = AssetRequestMode.AsyncLoad 
)
static
Type Constraints
T :class 

◆ TileEntityType< T >()

static int ModContent.TileEntityType< T > ( )
static

Get the id (type) of a ModTileEntity by class. Assumes one instance per class.

Type Constraints
T :ModTileEntity 
T :GetInstance<T>() 
T :Type 

◆ TileType< T >()

static int ModContent.TileType< T > ( )
static

Get the id (type) of a ModTile by class. Assumes one instance per class.

Type Constraints
T :ModTile 
T :GetInstance<T>() 
T :Type 

◆ TryFind< T >() [1/2]

static bool ModContent.TryFind< T > ( string  fullname,
out T  value 
)
static

Safely attempts to find the template instance with the specified full name (not the clone/new instance which gets added to Items/Players/NPCs etc. as the game is played). Caching the result is recommended.

Returns
Whether or not the requested instance has been found.
Type Constraints
T :IModType 
T :ModTypeLookup<T> 
T :TryGetValue 
T :fullname 
T :out 
T :value 

◆ TryFind< T >() [2/2]

static bool ModContent.TryFind< T > ( string  modName,
string  name,
out T  value 
)
static

Safely attempts to find the template instance with the specified name and mod name (not the clone/new instance which gets added to Items/Players/NPCs etc. as the game is played). Caching the result is recommended.

Returns
Whether or not the requested instance has been found.
Type Constraints
T :IModType 
T :ModTypeLookup<T> 
T :TryGetValue 
T :modName 
T :name 
T :out 
T :value 

◆ WallType< T >()

static int ModContent.WallType< T > ( )
static

Get the id (type) of a ModWall by class. Assumes one instance per class.

Type Constraints
T :ModWall 
T :GetInstance<T>() 
T :Type