tModLoader v2022.09
A mod to make and play Terraria mods
Terraria.ModLoader.ModContent Class Reference

Manages content added by mods. Liasons 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 bool FileExists (string name)
 Returns whether or not a file with the specified name exists.
 
static T Find< T > (string fullname)
 Attempts to find the content instance with the specified full name. Caching the result is recommended.This will throw exceptions on failure. More...
 
static T Find< T > (string modName, string name)
 Attempts to find the content instance with the specified name and mod name. Caching the result is recommended.This will throw exceptions on failure. More...
 
static IEnumerable< T > GetContent< T > ()
 Returns all base content instances that derive from the provided content type across all currently loaded mods. More...
 
static EquipTexture GetEquipTexture (EquipType type, int slot)
 Gets the equipment texture for the specified equipment type and ID. More...
 
static byte[] GetFileBytes (string name)
 Gets the byte representation of the file with the specified name. The name is in the format of "ModFolder/OtherFolders/FileNameWithExtension". Throws an ArgumentException if the file does not exist. More...
 
static T GetInstance< T > ()
 Returns the base instance of the provided content type. More...
 
static int GetModBackgroundSlot (string texture)
 Returns the slot/ID of the background texture with the given name.
 
static int GetModBossHeadSlot (string texture)
 Gets the index of the boss head texture corresponding to the given texture path. More...
 
static ModBuff GetModBuff (int type)
 Gets the ModBuff instance with the given type. If no ModBuff with the given type exists, returns null.
 
static ModDust GetModDust (int type)
 Gets the ModDust instance with the given type. Returns null if no ModDust with the given type exists.
 
static int GetModHeadSlot (string texture)
 Gets the index of the head texture corresponding to the given texture path. More...
 
static ModItem GetModItem (int type)
 Gets the ModItem instance corresponding to the specified type. Returns null if no modded item has the given type.
 
static ModMount GetModMount (int type)
 Gets the ModMount instance corresponding to the given type. Returns null if no ModMount has the given type. More...
 
static ModNPC GetModNPC (int type)
 Gets the ModNPC instance corresponding to the specified type. More...
 
static ModProjectile GetModProjectile (int type)
 Gets the ModProjectile instance corresponding to the specified type. More...
 
static ModSurfaceBackgroundStyle GetModSurfaceBackgroundStyle (int style)
 Returns the ModSurfaceBackgroundStyle object with the given ID.
 
static ModTile GetModTile (int type)
 Gets the ModTile instance with the given type. If no ModTile with the given type exists, returns null. More...
 
static ModUndergroundBackgroundStyle GetModUndergroundBackgroundStyle (int style)
 Returns the ModUndergroundBackgroundStyle object with the given ID.
 
static ModWall GetModWall (int type)
 Gets the ModWall instance with the given type. If no ModWall with the given type exists, returns null.
 
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. 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 content instance with the specified full name. Caching the result is recommended. More...
 
static bool TryFind< T > (string modName, string name, out T value)
 Safely attempts to find the content instance with the specified name and mod name. 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. Liasons between mod content and Terraria's arrays and oversees the Loader classes.

Member Function Documentation

◆ BuffType< T >()

static int Terraria.ModLoader.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 Terraria.ModLoader.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 

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

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

Attempts to find the content instance with the specified full name. 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 Terraria.ModLoader.ModContent.Find< T > ( string  modName,
string  name 
)
static

Attempts to find the content instance with the specified name and mod name. 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 > Terraria.ModLoader.ModContent.GetContent< T > ( )
static

Returns all base content instances that derive from the provided content type across all currently loaded mods.

Type Constraints
T :ILoadable 
T :ModLoader.Mods.SelectMany 
T :m 
T :m.GetContent<T>() 

◆ GetEquipTexture()

static EquipTexture Terraria.ModLoader.ModContent.GetEquipTexture ( EquipType  type,
int  slot 
)
static

Gets the equipment texture for the specified equipment type and ID.

Parameters
type
slot
Returns

◆ GetFileBytes()

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

Gets the byte representation of the file with the specified name. The name is in the format of "ModFolder/OtherFolders/FileNameWithExtension". Throws an ArgumentException if the file does not exist.

Exceptions
MissingResourceExceptionMissing mod: " + name

◆ GetInstance< T >()

static T Terraria.ModLoader.ModContent.GetInstance< T > ( )
static

Returns the base instance of the provided content type.

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

◆ GetModBossHeadSlot()

static int Terraria.ModLoader.ModContent.GetModBossHeadSlot ( string  texture)
static

Gets the index of the boss head texture corresponding to the given texture path.

Parameters
texture
Returns

◆ GetModHeadSlot()

static int Terraria.ModLoader.ModContent.GetModHeadSlot ( string  texture)
static

Gets the index of the head texture corresponding to the given texture path.

Parameters
textureRelative texture path
Returns
The index of the texture in the heads array, -1 if not found.

◆ GetModMount()

static ModMount Terraria.ModLoader.ModContent.GetModMount ( int  type)
static

Gets the ModMount instance corresponding to the given type. Returns null if no ModMount has the given type.

Parameters
typeThe type of the mount.
Returns
Null if not found, otherwise the ModMount associated with the mount.

◆ GetModNPC()

static ModNPC Terraria.ModLoader.ModContent.GetModNPC ( int  type)
static

Gets the ModNPC instance corresponding to the specified type.

Parameters
typeThe type of the npc
Returns
The ModNPC instance in the npcs array, null if not found.

◆ GetModProjectile()

static ModProjectile Terraria.ModLoader.ModContent.GetModProjectile ( int  type)
static

Gets the ModProjectile instance corresponding to the specified type.

Parameters
typeThe type of the projectile
Returns
The ModProjectile instance in the projectiles array, null if not found.

◆ GetModTile()

static ModTile Terraria.ModLoader.ModContent.GetModTile ( int  type)
static

Gets the ModTile instance with the given type. If no ModTile with the given type exists, returns null.

Parameters
typeThe type of the ModTile
Returns
The ModTile instance in the tiles array, null if not found.

◆ GoreType< T >()

static int Terraria.ModLoader.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 Terraria.ModLoader.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 Terraria.ModLoader.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 Terraria.ModLoader.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 Terraria.ModLoader.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 Terraria.ModLoader.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 Terraria.ModLoader.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 Terraria.ModLoader.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 > Terraria.ModLoader.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.

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 Terraria.ModLoader.ModContent.RequestIfExists< T > ( string  name,
out Asset< T >  asset,
AssetRequestMode  mode = AssetRequestMode.AsyncLoad 
)
static
Type Constraints
T :class 

◆ TileEntityType< T >()

static int Terraria.ModLoader.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 Terraria.ModLoader.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 Terraria.ModLoader.ModContent.TryFind< T > ( string  fullname,
out T  value 
)
static

Safely attempts to find the content instance with the specified full name. 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 Terraria.ModLoader.ModContent.TryFind< T > ( string  modName,
string  name,
out T  value 
)
static

Safely attempts to find the content instance with the specified name and mod name. 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 Terraria.ModLoader.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