tModLoader v2023.01
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 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.
 
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.
 
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.
The Expert Cross Mod Content Guideexplains how to use this hook to implement and utilize cross-mod capabilities.
 
Recipe CloneRecipe (Recipe recipe)
 
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
 
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...
 
ModConfig GetConfig (string name)
 
IEnumerable< ILoadableGetContent ()
 
IEnumerable< T > GetContent< T > ()
 
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...
 
ModPacket GetPacket (int capacity=256)
 Creates a ModPacket object that you can write to and then send between servers and clients. 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.
 
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.
 
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).
 
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.
 

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.
 
Assembly Code [get, set]
 The assembly code this is loaded when tModLoader loads this mod.
Do NOT call Assembly.GetTypes on this as it will error out if the mod uses the ExtendsFromModAttribute attribute to inherit from weakly referenced mods. Use AssemblyManager.GetLoadableTypes(Assembly) instead.
 
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.
 
string DisplayName [get, set]
 The display name of this mod in the Mods menu.
 
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.
 
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.
 
bool IsNetSynced [get]
 
ILog Logger [get, set]
 A logger with this mod's name for easy logging.
 
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.
 
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.
 
short NetID [get]
 
PreJITFilter PreJITFilter = new PreJITFilter() [get, protected set]
 
IContentSource RootContentSource [get]
 
ModSide Side [get, set]
 The ModSide that controls how this mod is synced between client and server.
 
Version TModLoaderVersion [get, set]
 The version of tModLoader that was being used when this mod was built.
 
virtual Version Version [get]
 This version number of this mod.
 

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

◆ AddContent< T >()

void Terraria.ModLoader.Mod.AddContent< T > ( )
Type Constraints
T :ILoadable 
T :new() 
T :AddContent 
T :new 
T :T() 

◆ 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

◆ 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 

◆ GetContent< T >()

IEnumerable< T > Terraria.ModLoader.Mod.GetContent< T > ( )
Type Constraints
T :ILoadable 
T :content.OfType<T>() 

◆ 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.
newFileStream
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

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

◆ RequestAssetIfExists< T >()

bool Terraria.ModLoader.Mod.RequestAssetIfExists< T > ( string  assetName,
out Asset< T >  asset 
)
Type Constraints
T :class 

◆ 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