TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches
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...

+ Inheritance diagram for Terraria.ModLoader.Mod:
+ Collaboration diagram for Terraria.ModLoader.Mod:

Public Member Functions

void AddConfig (string name, ModConfig mc)
 
bool AddContent< T > ()
 Call this to manually add a content instance of the specified type (with a parameterless constructor) to the game.
 
bool AddContent (ILoadable instance)
 Call this to manually add the given content instance to the game.
 
IEnumerable< ILoadableGetContent ()
 Returns all registered content instances that are added by this mod.
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.
 
IEnumerable< T > GetContent< T > ()
 Returns all registered content instances that derive from the provided type that are added by this mod.
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.
 
Find< T > (string name)
 Attempts to find the template instance from this mod with the specified name (not the clone/new instance which gets added to Items/Players/NPCs etc. as the game is played). Caching the result is recommended.
 
bool TryFind< T > (string name, out T value)
 Safely attempts to find the template instance from this mod with the specified name (not the clone/new instance which gets added to Items/Players/NPCs etc. as the game is played). Caching the result is recommended.
 
string GetLocalizationKey (string suffix)
 Creates a localization key following the pattern of "Mods.{ModName}.{suffix}". Use this with M:Terraria.Localization.Language.GetOrRegister(System.String,System.Func<System.String>) to retrieve a T:Terraria.Localization.LocalizedText for custom localization keys. Alternatively M:Terraria.ModLoader.Mod.GetLocalization(System.String,System.Func<System.String>) can be used directly instead. Custom localization keys need to be registered during the mod loading process to appear automtaically in the localization files.
 
LocalizedText GetLocalization (string suffix, Func< string > makeDefaultValue=null)
 Returns a T:Terraria.Localization.LocalizedText for this Mod with the provided suffix . The suffix will be used to generate a key by providing it to M:Terraria.ModLoader.Mod.GetLocalizationKey(System.String).
If no existing localization exists for the key, it will be defined so it can be exported to a matching mod localization file.
 
int AddNPCHeadTexture (int npcType, string texture)
 Assigns a head texture to the given town NPC type.
 
int AddBossHeadTexture (string texture, int npcType=-1)
 Assigns a head texture that can be used by NPCs on the map.
 
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.
 
byte[] GetFileBytes (string name)
 Retrieve contents of files within the tmod file.
 
Stream GetFileStream (string name, bool newFileStream=false)
 Retrieve contents of files within the tmod file.
 
bool FileExists (string name)
 
bool HasAsset (string assetName)
 
bool RequestAssetIfExists< T > (string assetName, out Asset< T > asset)
 
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.
 
ModPacket GetPacket (int capacity=256)
 Creates a ModPacket object that you can write to and then send between servers and clients.
 
ModConfig GetConfig (string name)
 
Recipe CreateRecipe (int result, int amount=1)
 
Recipe CloneRecipe (Recipe recipe)
 
virtual IContentSource CreateDefaultContentSource ()
 
virtual void Load ()
 Override this method to run code after all content has been autoloaded. Here additional content can be manually loaded and Mod-wide tasks and setup can be done. For organization, it may be more suitable to split some things into various M:Terraria.ModLoader.ModType.Load methods, such as in T:Terraria.ModLoader.ModSystem classes, instead of doing everything here.
Beware that mod content has not finished loading here, things like ModContent lookup tables or ID Sets are not fully populated. Use M:Terraria.ModLoader.Mod.PostSetupContent for any logic that needs to act on all content being fully loaded.
 
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).
 
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.
 
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 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 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 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.
Note that many packets are sent from a client to the server and then relayed to the remaining clients. The whoAmI when the packet arrives at the remaining clients will be the servers F:Terraria.Main.myPlayer, not the original clients F:Terraria.Main.myPlayer. For packets only sent from a client to the server, relying on whoAmI to identify the clients player is fine, but for packets that are relayed, the clients player index will need to be part of the packet itself to correctly identify the client that sent the original packet. Use packet.Write((byte) Main.myPlayer); to write and int player = reader.ReadByte(); to read.
 

Public Attributes

ModSourceBestiaryInfoElement ModSourceBestiaryInfoElement
 

Package Functions

void AutoloadConfig ()
 
void SetupContent ()
 
void UnloadContent ()
 
void Autoload ()
 
void PrepareAssets ()
 
void TransferAllAssets ()
 
void OnceFailedLoadingAnAsset (string assetPath, Exception e)
 

Package Attributes

short netID = -1
 
bool loading
 
readonly IDictionary< Tuple< string, EquipType >, EquipTextureequipTextures = new Dictionary<Tuple<string, EquipType>, EquipTexture>()
 
readonly IList< ILoadablecontent = new List<ILoadable>()
 
bool initialTransferComplete
 
List< ExceptionAssetExceptions = new List<Exception>()
 

Properties

TmodFile File [get, set]
 The TmodFile object created when tModLoader reads this mod.
 
Assembly Code [get, set]
 The assembly code this is loaded when tModLoader loads this mod.
Do NOT call M:System.Reflection.Assembly.GetTypes on this as it will error out if the mod uses the T:Terraria.ModLoader.ExtendsFromModAttribute attribute to inherit from weakly referenced mods. Use M:Terraria.ModLoader.Core.AssemblyManager.GetLoadableTypes(System.Reflection.Assembly) instead.
 
ILog Logger [get, set]
 A logger with this mod's name for easy logging.
 
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.
 
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.
 
List< string > TranslationForMods [get, set]
 
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.
 
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 MusicAutoloadingEnabled = true [get]
 Whether or not this mod will automatically add music to the game. All supported audio files in a folder or subfolder of a folder named "Music" will be autoloaded as music.
 
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.
 
ModSide Side [get, set]
 The ModSide that controls how this mod is synced between client and server.
 
string DisplayName [get, set]
 The display name of this mod in the Mods menu.
 
AssetRepository Assets [get, private set]
 
IContentSource RootContentSource [get, private set]
 
short NetID [get]
 
bool IsNetSynced [get]
 
PreJITFilter PreJITFilter = new PreJITFilter() [get, protected set]
 
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.
 

Private Attributes

IDisposable fileHandle
 
readonly Queue< TaskAsyncLoadQueue = new Queue<Task>()
 

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.

Definition at line 27 of file Mod.cs.


The documentation for this class was generated from the following file: