tModLoader  0.12 Alpha
A mod to make and play Terraria mods
Terraria.ModLoader.Mod Class Reference

Mod is an abstract class that you will override. It serves as a central place from which the mod's contents are stored. It provides methods for you to use or override. More...

Inherited by Terraria.ModLoader.Default.ModLoaderMod.

Public Member Functions

int AddBossHeadTexture (string texture, int npcType=-1)
 Assigns a head texture that can be used by NPCs on the map. More...
 
void AddConfig (string name, ModConfig mc)
 
void AddContent (ILoadable instance)
 
void AddContent< T > ()
 
int AddEquipTexture (EquipTexture equipTexture, ModItem item, EquipType type, string texture)
 Adds an equipment texture of the specified type, internal name, and associated item to your mod. This method is different from the other AddEquipTexture in that you can specify the class of the equipment texture, thus allowing you to override EquipmentTexture's hooks. All other parameters are the same as the other AddEquipTexture. More...
 
int AddEquipTexture (ModItem item, EquipType type, string texture)
 Adds an equipment texture of the specified type, internal name, and associated item to your mod. (The item parameter may be null if you don't want to associate an item with the texture.) You can then get the ID for your texture by calling EquipLoader.GetEquipTexture, and using the EquipTexture's Slot property. If the EquipType is EquipType.Body, make sure that you also provide an armTexture and a femaleTexture. Returns the ID / slot that is assigned to the equipment texture. More...
 
int AddNPCHeadTexture (int npcType, string texture)
 Assigns a head texture to the given town NPC type. More...
 
virtual void AddRecipeGroups ()
 Override this method to add recipe groups to this mod. You must add recipe groups by calling the RecipeGroup.RegisterGroup method here. A recipe group is a set of items that can be used interchangeably in the same recipe. More...
 
virtual void AddRecipes ()
 Override this method to add recipes to the game. It is recommended that you do so through instances of Recipe, since it provides methods that simplify recipe creation. More...
 
void AddSound (SoundType type, string soundPath, ModSound modSound=null)
 Adds the given sound file to the game as the given type of sound and with the given custom sound playing. If no ModSound instance is provided, the custom sound will play in a similar manner as the default vanilla ones. More...
 
virtual object Call (params object[] args)
 Used for weak inter-mod communication. This allows you to interact with other mods without having to reference their types or namespaces, provided that they have implemented this method. More...
 
virtual void Close ()
 Close is called before Unload, and may be called at any time when mod unloading is imminent (such as when downloading an update, or recompiling) Use this to release any additional file handles, or stop streaming music. Make sure to call base.Close() at the end May be called multiple times before Unload More...
 
virtual IContentSource CreateDefaultContentSource ()
 
Recipe CreateRecipe (int result, int amount=1)
 
bool FileExists (string name)
 
Find< T > (string name)
 Attempts to find the content instance from this mod with the specified name. Caching the result is recommended.This will throw exceptions on failure. More...
 
sbyte GetAccessorySlot (string name, EquipType type)
 Same as GetEquipSlot, except returns the number as an sbyte (signed byte) for your convenience. More...
 
ModConfig GetConfig (string name)
 
IEnumerable< ILoadableGetContent ()
 
IEnumerable< T > GetContent< T > ()
 
int GetEquipSlot (string name, EquipType type)
 Gets the slot/ID of the equipment texture corresponding to the given name. Returns -1 if no EquipTexture with the given name is found. More...
 
EquipTexture GetEquipTexture (string name, EquipType type)
 Gets the EquipTexture instance corresponding to the name and EquipType. Returns null if no EquipTexture with the given name and EquipType is found. More...
 
byte[] GetFileBytes (string name)
 Retrieve contents of files within the tmod file More...
 
List< string > GetFileNames ()
 Retrieves the names of every file packaged into this mod. Note that this includes extensions, and for images the extension will always be .rawimg. More...
 
Stream GetFileStream (string name, bool newFileStream=false)
 Retrieve contents of files within the tmod file More...
 
LegacySoundStyle GetLegacySoundSlot (SoundType type, string name)
 Shorthand for calling SoundLoader.GetLegacySoundSlot(type, this.Name + '/' + name). More...
 
ModPacket GetPacket (int capacity=256)
 Creates a ModPacket object that you can write to and then send between servers and clients. More...
 
int GetSoundSlot (SoundType type, string name)
 Shorthand for calling SoundLoader.GetSoundSlot(type, this.Name + '/' + name). More...
 
virtual void HandlePacket (BinaryReader reader, int whoAmI)
 Called whenever a net message / packet is received from a client (if this is a server) or the server (if this is a client). whoAmI is the ID of whomever sent the packet (equivalent to the Main.myPlayer of the sender), and reader is used to read the binary data of the packet. More...
 
bool HasAsset (string assetName)
 
virtual void Load ()
 Override this method to add most of your content to your mod. Here you will call other methods such as AddItem. This is guaranteed to be called after all content has been autoloaded. More...
 
virtual void PostAddRecipes ()
 This provides a hook into the mod-loading process immediately after recipes have been added. You can use this to edit recipes added by other mods. More...
 
virtual void PostSetupContent ()
 Allows you to load things in your mod after its content has been setup (arrays have been resized to fit the content, etc). More...
 
bool RequestAssetIfExists< T > (string assetName, out Asset< T > asset)
 
bool TryFind< T > (string name, out T value)
 Safely attempts to find the content instance from this mod with the specified name. Caching the result is recommended. More...
 
virtual void Unload ()
 This is called whenever this mod is unloaded from the game. Use it to undo changes that you've made in Load that aren't automatically handled (for example, modifying the texture of a vanilla item). Mods are guaranteed to be unloaded in the reverse order they were loaded in. More...
 

Public Attributes

GameContent.Bestiary.ModSourceBestiaryInfoElement ModSourceBestiaryInfoElement
 

Properties

AssetRepository Assets [get]
 
bool BackgroundAutoloadingEnabled = true [get]
 Whether or not this mod will automatically add images in the Backgrounds folder as background textures to the game. This means you do not need to manually call Mod.AddBackgroundTexture. More...
 
Assembly Code [get, set]
 The assembly code this is loaded when tModLoader loads this mod. More...
 
bool ContentAutoloadingEnabled = true [get]
 Whether or not this mod will autoload content by default. Autoloading content means you do not need to manually add content through methods. More...
 
string DisplayName [get, set]
 The display name of this mod in the Mods menu. More...
 
virtual uint ExtraPlayerBuffSlots [get]
 The amount of extra buff slots this mod desires for Players. This value is checked after Mod.Load but before Mod.PostSetupContent. The actual number of buffs the player can use will be 22 plus the max value of all enabled mods. In-game use Player.MaxBuffs to check the maximum number of buffs. More...
 
bool GoreAutoloadingEnabled = true [get]
 Whether or not this mod will automatically add images in the Gores folder as gores to the game, along with any ModGore classes that share names with the images. This means you do not need to manually call Mod.AddGore. More...
 
bool IsNetSynced [get]
 
ILog Logger [get, set]
 A logger with this mod's name for easy logging. More...
 
bool MusicAutoloadingEnabled = true [get]
 Whether or not this mod will automatically add music in the Sounds folder to the game. Place music tracks in Sounds/Music to autoload them. More...
 
virtual string Name [get]
 Stores the name of the mod. This name serves as the mod's identification, and also helps with saving everything your mod adds. By default this returns the name of the folder that contains all your code and stuff. More...
 
IContentSource RootContentSource [get]
 
ModSide Side [get, set]
 The ModSide that controls how this mod is synced between client and server. More...
 
bool SoundAutoloadingEnabled = true [get]
 Whether or not this mod will automatically add sounds in the Sounds folder to the game. Place sounds in Sounds/Item to autoload them as item sounds, Sounds/NPCHit to add them as npcHit sounds, and Sounds/NPCKilled to add them as npcKilled sounds. Sounds placed anywhere else in the Sounds folder will be added as custom sounds. Any ModSound classes that share the same name as the sound files will be bound to them. Setting this field to true means that you do not need to manually call AddSound. More...
 
Version TModLoaderVersion [get, set]
 The version of tModLoader that was being used when this mod was built. More...
 
virtual Version Version [get]
 This version number of this mod. More...
 

Detailed Description

Mod is an abstract class that you will override. It serves as a central place from which the mod's contents are stored. It provides methods for you to use or override.

Member Function Documentation

◆ AddBossHeadTexture()

int Terraria.ModLoader.Mod.AddBossHeadTexture ( string  texture,
int  npcType = -1 
)

Assigns a head texture that can be used by NPCs on the map.

Parameters
textureThe texture.
npcTypeAn optional npc id for NPCID.Sets.BossHeadTextures
Returns
The boss head txture slot

◆ AddEquipTexture() [1/2]

int Terraria.ModLoader.Mod.AddEquipTexture ( EquipTexture  equipTexture,
ModItem  item,
EquipType  type,
string  texture 
)

Adds an equipment texture of the specified type, internal name, and associated item to your mod. This method is different from the other AddEquipTexture in that you can specify the class of the equipment texture, thus allowing you to override EquipmentTexture's hooks. All other parameters are the same as the other AddEquipTexture.

Parameters
equipTextureThe equip texture.
itemThe item.
typeThe type.
textureThe texture.
Returns

◆ AddEquipTexture() [2/2]

int Terraria.ModLoader.Mod.AddEquipTexture ( ModItem  item,
EquipType  type,
string  texture 
)

Adds an equipment texture of the specified type, internal name, and associated item to your mod. (The item parameter may be null if you don't want to associate an item with the texture.) You can then get the ID for your texture by calling EquipLoader.GetEquipTexture, and using the EquipTexture's Slot property. If the EquipType is EquipType.Body, make sure that you also provide an armTexture and a femaleTexture. Returns the ID / slot that is assigned to the equipment texture.

Parameters
itemThe item.
typeThe type.
nameThe name.
textureThe texture.
armTextureThe arm texture (for body slots).
femaleTextureThe female texture (for body slots), if missing the regular body texture is used.
Returns

◆ AddNPCHeadTexture()

int Terraria.ModLoader.Mod.AddNPCHeadTexture ( int  npcType,
string  texture 
)

Assigns a head texture to the given town NPC type.

Parameters
npcTypeType of the NPC.
textureThe texture.
Returns
The boss head txture slot
Exceptions
MissingResourceException

◆ AddRecipeGroups()

virtual void Terraria.ModLoader.Mod.AddRecipeGroups ( )
virtual

Override this method to add recipe groups to this mod. You must add recipe groups by calling the RecipeGroup.RegisterGroup method here. A recipe group is a set of items that can be used interchangeably in the same recipe.

◆ AddRecipes()

virtual void Terraria.ModLoader.Mod.AddRecipes ( )
virtual

Override this method to add recipes to the game. It is recommended that you do so through instances of Recipe, since it provides methods that simplify recipe creation.

◆ AddSound()

void Terraria.ModLoader.Mod.AddSound ( SoundType  type,
string  soundPath,
ModSound  modSound = null 
)

Adds the given sound file to the game as the given type of sound and with the given custom sound playing. If no ModSound instance is provided, the custom sound will play in a similar manner as the default vanilla ones.

Parameters
typeThe type.
soundPathThe sound path.
modSoundThe mod sound.

◆ Call()

virtual object Terraria.ModLoader.Mod.Call ( params object[]  args)
virtual

Used for weak inter-mod communication. This allows you to interact with other mods without having to reference their types or namespaces, provided that they have implemented this method.

◆ Close()

virtual void Terraria.ModLoader.Mod.Close ( )
virtual

Close is called before Unload, and may be called at any time when mod unloading is imminent (such as when downloading an update, or recompiling) Use this to release any additional file handles, or stop streaming music. Make sure to call base.Close() at the end May be called multiple times before Unload

◆ Find< T >()

T Terraria.ModLoader.Mod.Find< T > ( string  name)

Attempts to find the content instance from this mod with the specified name. Caching the result is recommended.This will throw exceptions on failure.

Exceptions
KeyNotFoundException
Type Constraints
T :IModType 
T :ModContent.Find<T> 
T :Name 
T :name 

◆ GetAccessorySlot()

sbyte Terraria.ModLoader.Mod.GetAccessorySlot ( string  name,
EquipType  type 
)

Same as GetEquipSlot, except returns the number as an sbyte (signed byte) for your convenience.

Parameters
nameThe name.
type
Returns

◆ GetEquipSlot()

int Terraria.ModLoader.Mod.GetEquipSlot ( string  name,
EquipType  type 
)

Gets the slot/ID of the equipment texture corresponding to the given name. Returns -1 if no EquipTexture with the given name is found.

Parameters
nameThe name.
type
Returns

◆ GetEquipTexture()

EquipTexture Terraria.ModLoader.Mod.GetEquipTexture ( string  name,
EquipType  type 
)

Gets the EquipTexture instance corresponding to the name and EquipType. Returns null if no EquipTexture with the given name and EquipType is found.

Parameters
nameThe name.
typeThe type.
Returns

◆ GetFileBytes()

byte [] Terraria.ModLoader.Mod.GetFileBytes ( string  name)

Retrieve contents of files within the tmod file

Parameters
nameThe name.
Returns

◆ GetFileNames()

List<string> Terraria.ModLoader.Mod.GetFileNames ( )

Retrieves the names of every file packaged into this mod. Note that this includes extensions, and for images the extension will always be .rawimg.

Returns

◆ GetFileStream()

Stream Terraria.ModLoader.Mod.GetFileStream ( string  name,
bool  newFileStream = false 
)

Retrieve contents of files within the tmod file

Parameters
nameThe name.
Returns

◆ GetLegacySoundSlot()

LegacySoundStyle Terraria.ModLoader.Mod.GetLegacySoundSlot ( SoundType  type,
string  name 
)

Shorthand for calling SoundLoader.GetLegacySoundSlot(type, this.Name + '/' + name).

Parameters
typeThe type.
nameThe name.
Returns

◆ GetPacket()

ModPacket Terraria.ModLoader.Mod.GetPacket ( int  capacity = 256)

Creates a ModPacket object that you can write to and then send between servers and clients.

Parameters
capacityThe capacity.
Returns
Exceptions
System.ExceptionCannot get packet for " + Name + " because it does not exist on the other side

◆ GetSoundSlot()

int Terraria.ModLoader.Mod.GetSoundSlot ( SoundType  type,
string  name 
)

Shorthand for calling SoundLoader.GetSoundSlot(type, this.Name + '/' + name).

Parameters
typeThe type.
nameThe name.
Returns

◆ HandlePacket()

virtual void Terraria.ModLoader.Mod.HandlePacket ( BinaryReader  reader,
int  whoAmI 
)
virtual

Called whenever a net message / packet is received from a client (if this is a server) or the server (if this is a client). whoAmI is the ID of whomever sent the packet (equivalent to the Main.myPlayer of the sender), and reader is used to read the binary data of the packet.

Parameters
readerThe reader.
whoAmIThe player the message is from.

◆ Load()

virtual void Terraria.ModLoader.Mod.Load ( )
virtual

Override this method to add most of your content to your mod. Here you will call other methods such as AddItem. This is guaranteed to be called after all content has been autoloaded.

◆ PostAddRecipes()

virtual void Terraria.ModLoader.Mod.PostAddRecipes ( )
virtual

This provides a hook into the mod-loading process immediately after recipes have been added. You can use this to edit recipes added by other mods.

◆ PostSetupContent()

virtual void Terraria.ModLoader.Mod.PostSetupContent ( )
virtual

Allows you to load things in your mod after its content has been setup (arrays have been resized to fit the content, etc).

◆ TryFind< T >()

bool Terraria.ModLoader.Mod.TryFind< T > ( string  name,
out T  value 
)

Safely attempts to find the content instance from this mod with the specified name. Caching the result is recommended.

Returns
Whether or not the requested instance has been found.
Type Constraints
T :IModType 
T :ModContent.TryFind 
T :Name 
T :name 
T :out 
T :value 

◆ Unload()

virtual void Terraria.ModLoader.Mod.Unload ( )
virtual

This is called whenever this mod is unloaded from the game. Use it to undo changes that you've made in Load that aren't automatically handled (for example, modifying the texture of a vanilla item). Mods are guaranteed to be unloaded in the reverse order they were loaded in.

Property Documentation

◆ BackgroundAutoloadingEnabled

bool Terraria.ModLoader.Mod.BackgroundAutoloadingEnabled = true
get

Whether or not this mod will automatically add images in the Backgrounds folder as background textures to the game. This means you do not need to manually call Mod.AddBackgroundTexture.

◆ Code

Assembly Terraria.ModLoader.Mod.Code
getset

The assembly code this is loaded when tModLoader loads this mod.

◆ ContentAutoloadingEnabled

bool Terraria.ModLoader.Mod.ContentAutoloadingEnabled = true
get

Whether or not this mod will autoload content by default. Autoloading content means you do not need to manually add content through methods.

◆ DisplayName

string Terraria.ModLoader.Mod.DisplayName
getset

The display name of this mod in the Mods menu.

◆ ExtraPlayerBuffSlots

virtual uint Terraria.ModLoader.Mod.ExtraPlayerBuffSlots
get

The amount of extra buff slots this mod desires for Players. This value is checked after Mod.Load but before Mod.PostSetupContent. The actual number of buffs the player can use will be 22 plus the max value of all enabled mods. In-game use Player.MaxBuffs to check the maximum number of buffs.

◆ GoreAutoloadingEnabled

bool Terraria.ModLoader.Mod.GoreAutoloadingEnabled = true
get

Whether or not this mod will automatically add images in the Gores folder as gores to the game, along with any ModGore classes that share names with the images. This means you do not need to manually call Mod.AddGore.

◆ Logger

ILog Terraria.ModLoader.Mod.Logger
getset

A logger with this mod's name for easy logging.

◆ MusicAutoloadingEnabled

bool Terraria.ModLoader.Mod.MusicAutoloadingEnabled = true
get

Whether or not this mod will automatically add music in the Sounds folder to the game. Place music tracks in Sounds/Music to autoload them.

◆ Name

virtual string Terraria.ModLoader.Mod.Name
get

Stores the name of the mod. This name serves as the mod's identification, and also helps with saving everything your mod adds. By default this returns the name of the folder that contains all your code and stuff.

◆ Side

ModSide Terraria.ModLoader.Mod.Side
getset

The ModSide that controls how this mod is synced between client and server.

◆ SoundAutoloadingEnabled

bool Terraria.ModLoader.Mod.SoundAutoloadingEnabled = true
get

Whether or not this mod will automatically add sounds in the Sounds folder to the game. Place sounds in Sounds/Item to autoload them as item sounds, Sounds/NPCHit to add them as npcHit sounds, and Sounds/NPCKilled to add them as npcKilled sounds. Sounds placed anywhere else in the Sounds folder will be added as custom sounds. Any ModSound classes that share the same name as the sound files will be bound to them. Setting this field to true means that you do not need to manually call AddSound.

◆ TModLoaderVersion

Version Terraria.ModLoader.Mod.TModLoaderVersion
getset

The version of tModLoader that was being used when this mod was built.

◆ Version

virtual Version Terraria.ModLoader.Mod.Version
get

This version number of this mod.