Terraria ModLoader  0.10.1.5
A framework for 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...

+ Collaboration diagram for Terraria.ModLoader.Mod:

Public Member Functions

void AddBackgroundTexture (string texture)
 Adds a texture to the list of background textures and assigns it a background texture slot. More...
 
void AddBossHeadTexture (string texture, int npcType=-1)
 Assigns a head texture that can be used by NPCs on the map. More...
 
void AddBuff (string name, ModBuff buff, string texture)
 Adds a type of buff to the game with the specified internal name and texture. More...
 
void AddCommand (string name, ModCommand mc)
 Manually add a Command during Load More...
 
void AddConfig (string name, ModConfig mc)
 
void AddDust (string name, ModDust dust, string texture="")
 Adds a type of dust to your mod with the specified name. Create an instance of ModDust normally, preferably through the constructor of an overriding class. Leave the texture as an empty string to use the vanilla dust sprite sheet. More...
 
int AddEquipTexture (ModItem item, EquipType type, string name, string texture, string armTexture="", string femaleTexture="")
 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 AddEquipTexture (EquipTexture equipTexture, ModItem item, EquipType type, string name, string texture, string armTexture="", string femaleTexture="")
 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...
 
void AddGlobalBgStyle (string name, GlobalBgStyle globalBgStyle)
 Adds the given global background style with the given name to this mod. More...
 
void AddGlobalBuff (string name, GlobalBuff globalBuff)
 Adds the given GlobalBuff instance to this mod using the provided name. More...
 
void AddGlobalItem (string name, GlobalItem globalItem)
 Adds the given GlobalItem instance to this mod with the provided name. More...
 
void AddGlobalNPC (string name, GlobalNPC globalNPC)
 Adds the given GlobalNPC instance to this mod with the provided name. More...
 
void AddGlobalProjectile (string name, GlobalProjectile globalProjectile)
 Adds the given GlobalProjectile instance to this mod with the provided name. More...
 
void AddGlobalRecipe (string name, GlobalRecipe globalRecipe)
 Manually add a Global Recipe during Load More...
 
void AddGlobalTile (string name, GlobalTile globalTile)
 Adds the given GlobalTile instance to this mod with the provided name. More...
 
void AddGlobalWall (string name, GlobalWall globalWall)
 Adds the given GlobalWall instance to this mod with the provided name. More...
 
void AddGore (string texture, ModGore modGore=null)
 Adds the given texture to the game as a custom gore, with the given custom gore behavior. If no custom gore behavior is provided, the custom gore will have the default vanilla behavior. More...
 
void AddItem (string name, ModItem item)
 Adds a type of item to your mod with the specified internal name. This method should be called in Load. You can obtain an instance of ModItem by overriding it then creating an instance of the subclass. More...
 
void AddModWorld (string name, ModWorld modWorld)
 Adds a ModWorld to this mod with the given name. More...
 
void AddMount (string name, ModMountData mount, string texture, IDictionary< MountTextureType, string > extraTextures=null)
 Adds the given mount to the game with the given name and texture. The extraTextures dictionary should optionally map types of mount textures to the texture paths you want to include. More...
 
void AddMusicBox (int musicSlot, int itemType, int tileType, int tileFrameY=0)
 Allows you to tie a music ID, and item ID, and a tile ID together to form a music box. When music with the given ID is playing, equipped music boxes have a chance to change their ID to the given item type. When an item with the given item type is equipped, it will play the music that has musicSlot as its ID. When a tile with the given type and Y-frame is nearby, if its X-frame is >= 36, it will play the music that has musicSlot as its ID. More...
 
void AddNPC (string name, ModNPC npc)
 Adds a type of NPC to the game with the specified name and texture. Also allows you to give the NPC alternate textures. More...
 
void AddNPCHeadTexture (int npcType, string texture)
 Assigns a head texture to the given town NPC type. More...
 
void AddPlayer (string name, ModPlayer player)
 Adds a type of ModPlayer to this mod. All ModPlayer types will be newly created and attached to each player that is loaded. More...
 
void AddPrefix (string name, ModPrefix prefix)
 Adds a prefix to your mod with the specified internal name. This method should be called in Load. You can obtain an instance of ModPrefix by overriding it then creating an instance of the subclass. More...
 
void AddProjectile (string name, ModProjectile projectile)
 Adds a type of projectile to the game with the specified name. 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 ModRecipe, 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...
 
void AddSurfaceBgStyle (string name, ModSurfaceBgStyle surfaceBgStyle)
 Adds the given surface background style with the given name to this mod. More...
 
void AddTexture (string name, Texture2D texture)
 Shorthand for calling ModLoader.AddTexture(this.FileName(name), texture). More...
 
void AddTile (string name, ModTile tile, string texture)
 Adds a type of tile to the game with the specified name and texture. More...
 
void AddTileEntity (string name, ModTileEntity entity)
 Manually add a tile entity during Load. More...
 
void AddTranslation (ModTranslation translation)
 Adds a ModTranslation to the game so that you can use Language.GetText to get a LocalizedText. More...
 
void AddUgBgStyle (string name, ModUgBgStyle ugBgStyle)
 Adds the given underground background style with the given name to this mod. More...
 
void AddWall (string name, ModWall wall, string texture)
 Adds a type of wall to the game with the specified name and texture. More...
 
void AddWaterfallStyle (string name, ModWaterfallStyle waterfallStyle, string texture)
 Adds the given waterfall style to the game with the given name and texture path. More...
 
void AddWaterStyle (string name, ModWaterStyle waterStyle, string texture, string blockTexture)
 Adds the given water style to the game with the given name, texture path, and block texture path. More...
 
int BuffType (string name)
 Gets the type of the ModBuff of this mod corresponding to the given name. Returns 0 if no ModBuff with the given name is found. More...
 
int BuffType< T > ()
 Same as the other BuffType, but assumes that the class name and internal name are the same. 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...
 
ModTranslation CreateTranslation (string key)
 Creates a ModTranslation object that you can use in AddTranslation. More...
 
int DustType (string name)
 Gets the type of the ModDust of this mod with the given name. Returns 0 if no ModDust with the given name is found. More...
 
int DustType< T > ()
 Same as the other DustType, but assumes that the class name and internal name are the same. More...
 
bool EffectExists (string name)
 Used to check if a custom Effect exists More...
 
bool FileExists (string name)
 Shorthand for calling ModLoader.FileExists(this.FileName(name)). Note that file extensions are used here. More...
 
bool FontExists (string name)
 Used to check if a custom SpriteFont exists More...
 
sbyte GetAccessorySlot (string name, EquipType type)
 Same as GetEquipSlot, except returns the number as an sbyte (signed byte) for your convenience. More...
 
int GetBackgroundSlot (string name)
 Gets the texture slot corresponding to the specified texture name. Shorthand for calling BackgroundTextureLoader.GetBackgroundSlot(this.Name + '/' + name). More...
 
ModBuff GetBuff (string name)
 Gets the ModBuff of this mod corresponding to the given name. Returns null if no ModBuff with the given name is found. More...
 
GetBuff< T > ()
 
ModConfig GetConfig (string name)
 
GetConfig< T > ()
 
ModDust GetDust (string name)
 Gets the ModDust of this mod corresponding to the given name. Returns null if no ModDust with the given name is found. More...
 
GetDust< T > ()
 Same as the other GetDust, but assumes that the class name and internal name are the same. More...
 
Effect GetEffect (string name)
 Gets an Effect loaded from the specified path. More...
 
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...
 
Stream GetFileSteam (string name)
 Retrieve contents of files within the tmod file More...
 
DynamicSpriteFont GetFont (string name)
 Gets a SpriteFont loaded from the specified path. More...
 
GlobalBgStyle GetGlobalBgStyle (string name)
 Returns the global background style corresponding to the given name. More...
 
GetGlobalBgStyle< T > ()
 
GlobalBuff GetGlobalBuff (string name)
 Gets the GlobalBuff with the given name from this mod. More...
 
GetGlobalBuff< T > ()
 
GlobalItem GetGlobalItem (string name)
 Gets the GlobalItem instance with the given name from this mod. More...
 
GetGlobalItem< T > ()
 Same as the other GetGlobalItem, but assumes that the class name and internal name are the same. More...
 
GlobalNPC GetGlobalNPC (string name)
 Gets the GlobalNPC instance with the given name from this mod. More...
 
GetGlobalNPC< T > ()
 
GlobalProjectile GetGlobalProjectile (string name)
 Gets the GlobalProjectile instance with the given name from this mod. More...
 
GetGlobalProjectile< T > ()
 
GlobalRecipe GetGlobalRecipe (string name)
 Gets the global recipe corresponding to the specified name. More...
 
GetGlobalRecipe< T > ()
 
GlobalTile GetGlobalTile (string name)
 Gets the GlobalTile instance with the given name from this mod. More...
 
GetGlobalTile< T > ()
 Same as the other GetGlobalTile, but assumes that the class name and internal name are the same. More...
 
GlobalWall GetGlobalWall (string name)
 Gets the GlobalWall instance with the given name from this mod. More...
 
GetGlobalWall< T > ()
 
int GetGoreSlot (string name)
 Shorthand for calling ModGore.GetGoreSlot(this.Name + '/' + name). More...
 
int GetGoreSlot< T > ()
 Same as the other GetGoreSlot, but assumes that the class name and internal name are the same. More...
 
ModItem GetItem (string name)
 Gets the ModItem instance corresponding to the name. Because this method is in the Mod class, conflicts between mods are avoided. Returns null if no ModItem with the given name is found. More...
 
GetItem< T > ()
 Same as the other GetItem, but assumes that the class name and internal name are the same. More...
 
LegacySoundStyle GetLegacySoundSlot (SoundType type, string name)
 Shorthand for calling SoundLoader.GetLegacySoundSlot(type, this.Name + '/' + name). More...
 
ModWorld GetModWorld (string name)
 Gets the ModWorld instance with the given name from this mod. More...
 
GetModWorld< T > ()
 Same as the other GetModWorld, but assumes that the class name and internal name are the same. More...
 
ModMountData GetMount (string name)
 Gets the ModMountData instance of this mod corresponding to the given name. Returns null if no ModMountData has the given name. More...
 
GetMount< T > ()
 
Music GetMusic (string name)
 Shorthand for calling ModContent.GetMusic(this.FileName(name)). More...
 
ModNPC GetNPC (string name)
 Gets the ModNPC of this mod corresponding to the given name. Returns null if no ModNPC with the given name is found. More...
 
GetNPC< T > ()
 
ModPacket GetPacket (int capacity=256)
 Creates a ModPacket object that you can write to and then send between servers and clients. More...
 
ModPlayer GetPlayer (string name)
 Gets the ModPlayer of this mod corresponding to the given name. Returns null if no ModPlayer with the given name is found. More...
 
GetPlayer< T > ()
 
ModPrefix GetPrefix (string name)
 Gets the ModPrefix instance corresponding to the name. Because this method is in the Mod class, conflicts between mods are avoided. Returns null if no ModPrefix with the given name is found. More...
 
GetPrefix< T > ()
 Same as the other GetPrefix, but assumes that the class name and internal name are the same. More...
 
ModProjectile GetProjectile (string name)
 Gets the ModProjectile of this mod corresponding to the given name. Returns null if no ModProjectile with the given name is found. More...
 
GetProjectile< T > ()
 
SoundEffect GetSound (string name)
 Shorthand for calling ModContent.GetSound(this.FileName(name)). More...
 
int GetSoundSlot (SoundType type, string name)
 Shorthand for calling SoundLoader.GetSoundSlot(type, this.Name + '/' + name). More...
 
ModSurfaceBgStyle GetSurfaceBgStyle (string name)
 Returns the surface background style corresponding to the given name. More...
 
GetSurfaceBgStyle< T > ()
 
int GetSurfaceBgStyleSlot (string name)
 Returns the Slot of the surface background style corresponding to the given name. More...
 
int GetSurfaceBgStyleSlot< T > ()
 
Texture2D GetTexture (string name)
 Shorthand for calling ModContent.GetTexture(this.FileName(name)). More...
 
ModTile GetTile (string name)
 Gets the ModTile of this mod corresponding to the given name. Returns null if no ModTile with the given name is found. More...
 
GetTile< T > ()
 Same as the other GetTile, but assumes that the class name and internal name are the same. More...
 
ModTileEntity GetTileEntity (string name)
 Gets the ModTileEntity of this mod corresponding to the given name. Returns null if no ModTileEntity with the given name is found. More...
 
GetTileEntity< T > ()
 Same as the other GetTileEntity, but assumes that the class name and internal name are the same. More...
 
ModUgBgStyle GetUgBgStyle (string name)
 Returns the underground background style corresponding to the given name. More...
 
GetUgBgStyle< T > ()
 
ModWall GetWall (string name)
 Gets the ModWall of this mod corresponding to the given name. Returns null if no ModWall with the given name is found. More...
 
GetWall< T > ()
 
ModWaterfallStyle GetWaterfallStyle (string name)
 Returns the waterfall style with the given name from this mod. More...
 
GetWaterfallStyle< T > ()
 
int GetWaterfallStyleSlot (string name)
 Returns the waterfall style corresponding to the given name. More...
 
int GetWaterfallStyleSlot< T > ()
 
ModWaterStyle GetWaterStyle (string name)
 Returns the water style with the given name from this mod. More...
 
GetWaterStyle< T > ()
 
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...
 
virtual bool HijackGetData (ref byte messageType, ref BinaryReader reader, int playerNumber)
 Allows you to modify net message / packet information that is received before the game can act on it. More...
 
virtual bool HijackSendData (int whoAmI, int msgType, int remoteClient, int ignoreClient, NetworkText text, int number, float number2, float number3, float number4, int number5, int number6, int number7)
 Hijacks the send data method. Only use if you absolutely know what you are doing. If any hooks return true, the message is not sent. More...
 
virtual void HotKeyPressed (string name)
 Called when a hotkey is pressed. Check against the name to verify particular hotkey that was pressed. (Using the ModHotKey is more recommended.) More...
 
int ItemType (string name)
 Gets the internal ID / type of the ModItem corresponding to the name. Returns 0 if no ModItem with the given name is found. More...
 
int ItemType< T > ()
 Same as the other ItemType, but assumes that the class name and internal name are the same. More...
 
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 bool LoadResource (string path, int length, Func< Stream > getStream)
 Hook for pre-loading resources More...
 
virtual void LoadResourceFromStream (string path, int len, BinaryReader reader)
 
virtual void LoadResources ()
 
virtual void MidUpdateDustTime ()
 Called after Dust got updated, but before Time (day/night, events, etc.) gets updated. More...
 
virtual void MidUpdateGoreProjectile ()
 Called after Gores got updated, but before any Projectiles get updated. More...
 
virtual void MidUpdateInvasionNet ()
 Called after Invasions got updated. The only thing that is updated after this is the Network. More...
 
virtual void MidUpdateItemDust ()
 Called after Items got updated, but before any Dust gets updated. More...
 
virtual void MidUpdateNPCGore ()
 Called after NPCs got updated, but before any Gores get updated. More...
 
virtual void MidUpdatePlayerNPC ()
 Called after Players got updated, but before any NPCs get updated. More...
 
virtual void MidUpdateProjectileItem ()
 Gets called immediately after all Projectiles are updated, but before any Items get updated. More...
 
virtual void MidUpdateTimeWorld ()
 Called after Time got updated, but before the World gets updated. More...
 
virtual void ModifyInterfaceLayers (List< GameInterfaceLayer > layers)
 Allows you to modify the elements of the in-game interface that get drawn. GameInterfaceLayer can be found in the Terraria.UI namespace. Check https://github.com/blushiemagic/tModLoader/wiki/Vanilla-Interface-layers-values for vanilla interface layer names More...
 
virtual void ModifyLightingBrightness (ref float scale)
 Allows you to modify overall brightness of lights. Can be used to create effects similiar to what night vision and darkness (de)buffs give you. Values too high or too low might result in glitches. For night vision effect use scale 1.03 More...
 
virtual void ModifySunLightColor (ref Color tileColor, ref Color backgroundColor)
 Allows you to modify color of light the sun emits. More...
 
virtual void ModifyTransformMatrix (ref SpriteViewMatrix Transform)
 Allows you to set the transformation of the screen that is drawn. (Translations, rotations, scales, etc.) More...
 
int MountType (string name)
 Gets the ID of the ModMountData instance corresponding to the given name. Returns 0 if no ModMountData has the given name. More...
 
int MountType< T > ()
 Same as the other MountType, but assumes that the class name and internal name are the same. More...
 
bool MusicExists (string name)
 Shorthand for calling ModLoader.MusicExists(this.FileName(name)). More...
 
int NPCType (string name)
 Gets the type of the ModNPC of this mod with the given name. Returns 0 if no ModNPC with the given name is found. More...
 
int NPCType< T > ()
 Same as the other NPCType, but assumes that the class name and internal name are the same. 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 PostDrawFullscreenMap (ref string mouseText)
 Called while the fullscreen map is active. Allows custom drawing to the map. More...
 
virtual void PostDrawInterface (SpriteBatch spriteBatch)
 Called after interface is drawn but right before mouse and mouse hover text is drawn. Allows for drawing interface. 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...
 
virtual void PostUpdateEverything ()
 Called after the Network got updated, this is the last hook that happens in an update. More...
 
virtual void PostUpdateInput ()
 Called after the input keys are polled. Allows for modifying things like scroll wheel if your custom drawing should capture that. More...
 
byte PrefixType (string name)
 Gets the internal ID / type of the ModPrefix corresponding to the name. Returns 0 if no ModPrefix with the given name is found. More...
 
byte PrefixType< T > ()
 Same as the other PrefixType, but assumes that the class name and internal name are the same. More...
 
virtual void PreSaveAndQuit ()
 Called in SP or Client when the Save and Quit button is pressed. One use for this hook is clearing out custom UI slots to return items to the player. More...
 
virtual void PreUpdateEntities ()
 Use this if you want to do something before anything in the World gets updated. Called after UI updates, but before anything in the World (Players, NPCs, Projectiles, Tiles) gets updated. More...
 
int ProjectileType (string name)
 Gets the type of the ModProjectile of this mod with the given name. Returns 0 if no ModProjectile with the given name is found. More...
 
int ProjectileType< T > ()
 Same as the other ProjectileType, but assumes that the class name and internal name are the same. More...
 
ModHotKey RegisterHotKey (string name, string defaultKey)
 Registers a hotkey with a name and defaultKey. Use the returned ModHotKey to detect when buttons are pressed. Do this in a ModPlayer.ProcessTriggers. More...
 
bool SoundExists (string name)
 Shorthand for calling ModLoader.SoundExists(this.FileName(name)). More...
 
bool TextureExists (string name)
 Shorthand for calling ModLoader.TextureExists(this.FileName(name)). More...
 
int TileEntityType (string name)
 Gets the type of the ModTileEntity of this mod with the given name. Returns -1 if no ModTileEntity with the given name is found. More...
 
int TileEntityType< T > ()
 Same as the other TileEntityType, but assumes that the class name and internal name are the same. More...
 
int TileType (string name)
 Gets the type of the ModTile of this mod with the given name. Returns 0 if no ModTile with the given name is found. More...
 
int TileType< T > ()
 Same as the other TileType, but assumes that the class name and internal name are the same. 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...
 
virtual void UpdateMusic (ref int music, ref MusicPriority priority)
 Allows you to determine what music should currently play. More...
 
virtual void UpdateMusic (ref int music)
 A legacy hook that you should no longer use. Use the version with two parameters instead. More...
 
virtual void UpdateUI (GameTime gameTime)
 Ran every update and suitable for calling Update for UserInterface classes More...
 
int WallType (string name)
 Gets the type of the ModWall of this mod with the given name. Returns 0 if no ModWall with the given name is found. More...
 
int WallType< T > ()
 Same as the other WallType, but assumes that the class name and internal name are the same. More...
 

Public Attributes

bool IsNetSynced => netID >= 0
 
virtual string Name => File.name
 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...
 
virtual Version Version => File.version
 This version number of this mod. More...
 

Properties

Assembly Code [get, set]
 The assembly code this is loaded when tModLoader loads this mod. More...
 
string DisplayName [get, set]
 The display name of this mod in the Mods menu. More...
 
TmodFile File [get, set]
 The TmodFile object created when tModLoader reads this mod. More...
 
ILog Logger [get, set]
 A logger with this mod's name for easy logging. More...
 
ModProperties Properties [get, protected set]
 
ModSide Side = ModProperties.AutoLoadAll [get, set]
 The ModSide that controls how this mod is synced between client and server. More...
 
Version tModLoaderVersion [get, set]
 The version of tModLoader that was being used when this mod was built. More...
 

Private Member Functions

void AutoloadBackgrounds ()
 
void AutoloadBuff (Type type)
 
void AutoloadCommand (Type type)
 
void AutoloadDust (Type type)
 
void AutoloadGlobalBgStyle (Type type)
 
void AutoloadGlobalBuff (Type type)
 
void AutoloadGlobalItem (Type type)
 
void AutoloadGlobalNPC (Type type)
 
void AutoloadGlobalProjectile (Type type)
 
void AutoloadGlobalRecipe (Type type)
 
void AutoloadGlobalTile (Type type)
 
void AutoloadGlobalWall (Type type)
 
void AutoloadGores (IList< Type > modGores)
 
void AutoloadItem (Type type)
 
void AutoloadLocalization ()
 Loads .lang files More...
 
void AutoloadModWorld (Type type)
 
void AutoloadMountData (Type type)
 
void AutoloadNPC (Type type)
 
void AutoloadPlayer (Type type)
 
void AutoloadPrefix (Type type)
 
void AutoloadProjectile (Type type)
 
void AutoloadSounds (IList< Type > modSounds)
 
void AutoloadSurfaceBgStyle (Type type)
 
void AutoloadTile (Type type)
 
void AutoloadTileEntity (Type type)
 
void AutoloadUgBgStyle (Type type)
 
void AutoloadWall (Type type)
 
void AutoloadWaterfallStyle (Type type)
 
void AutoloadWaterStyle (Type type)
 
void LoadEffect (string path, BinaryReader br)
 
void LoadFont (string path, byte[] data)
 
void LoadMP3 (string path, byte[] bytes)
 
bool LoadResourceLegacy (string path, int length, Func< Stream > getStream)
 
void LoadTexture (string path, Stream stream, bool rawimg)
 
void LoadWav (string path, byte[] bytes)
 

Private Attributes

readonly Queue< Task > AsyncLoadQueue = 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.

Member Function Documentation

void Terraria.ModLoader.Mod.AddBackgroundTexture ( string  texture)

Adds a texture to the list of background textures and assigns it a background texture slot.

Parameters
textureThe texture.

Definition at line 1320 of file Mod.cs.

References Terraria.ModLoader.BackgroundTextureLoader.GetBackgroundSlot(), and Terraria.ModLoader.ModContent.GetTexture().

1320  {
1321  if (!loading)
1322  throw new Exception("AddBackgroundTexture can only be called from Mod.Load or Mod.Autoload");
1323 
1324  BackgroundTextureLoader.backgrounds[texture] = BackgroundTextureLoader.ReserveBackgroundSlot();
1325  ModContent.GetTexture(texture);
1326  }

+ Here is the call graph for this function:

void 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

Definition at line 881 of file Mod.cs.

References Terraria.ModLoader.ModContent.GetTexture().

881  {
882  if (!loading)
883  throw new Exception("AddBossHeadTexture can only be called from Mod.Load or Mod.Autoload");
884 
885  int slot = NPCHeadLoader.ReserveBossHeadSlot(texture);
886  NPCHeadLoader.bossHeads[texture] = slot;
887  ModContent.GetTexture(texture);
888  if (npcType >= 0) {
889  NPCHeadLoader.npcToBossHead[npcType] = slot;
890  }
891  }

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AddBuff ( string  name,
ModBuff  buff,
string  texture 
)

Adds a type of buff to the game with the specified internal name and texture.

Parameters
nameThe name.
buffThe buff.
textureThe texture.

Definition at line 924 of file Mod.cs.

References Terraria.ModLoader.ModBuff.Description, Terraria.ModLoader.ModBuff.DisplayName, Terraria.ModLoader.ModBuff.mod, Terraria.ModLoader.ModBuff.Name, and Terraria.ModLoader.ModBuff.Type.

924  {
925  if (!loading)
926  throw new Exception("AddBuff can only be called from Mod.Load or Mod.Autoload");
927 
928  if (buffs.ContainsKey(name))
929  throw new Exception("You tried to add 2 ModBuff with the same name: " + name + ". Maybe 2 classes share a classname but in different namespaces while autoloading or you manually called AddBuff with 2 buffs of the same name.");
930 
931  buff.mod = this;
932  buff.Name = name;
933  buff.Type = BuffLoader.ReserveBuffID();
934  buff.texture = texture;
935  buff.DisplayName = GetOrCreateTranslation(string.Format("Mods.{0}.BuffName.{1}", Name, name));
936  buff.Description = GetOrCreateTranslation(string.Format("Mods.{0}.BuffDescription.{1}", Name, name));
937 
938  buffs[name] = buff;
939  BuffLoader.buffs.Add(buff);
940  }
virtual string Name
Stores the name of the mod. This name serves as the mod&#39;s identification, and also helps with saving ...
Definition: Mod.cs:45
void Terraria.ModLoader.Mod.AddCommand ( string  name,
ModCommand  mc 
)

Manually add a Command during Load

Definition at line 1363 of file Mod.cs.

References Terraria.ModLoader.ModCommand.mod, and Terraria.ModLoader.ModCommand.Name.

1363  {
1364  if (!loading)
1365  throw new Exception("AddCommand can only be called from Mod.Load or Mod.Autoload");
1366 
1367  mc.mod = this;
1368  mc.Name = name;
1369  CommandManager.Add(mc);
1370  }
void Terraria.ModLoader.Mod.AddConfig ( string  name,
ModConfig  mc 
)
void Terraria.ModLoader.Mod.AddDust ( string  name,
ModDust  dust,
string  texture = "" 
)

Adds a type of dust to your mod with the specified name. Create an instance of ModDust normally, preferably through the constructor of an overriding class. Leave the texture as an empty string to use the vanilla dust sprite sheet.

Parameters
nameThe name.
dustThe dust.
textureThe texture.

Definition at line 461 of file Mod.cs.

References Terraria.ModLoader.ModContent.GetTexture(), Terraria.ModLoader.ModDust.mod, Terraria.ModLoader.ModDust.Name, Terraria.ModLoader.ModDust.Texture, and Terraria.ModLoader.ModDust.Type.

461  {
462  if (!loading)
463  throw new Exception("AddDust can only be called from Mod.Load or Mod.Autoload");
464 
465  dust.mod = this;
466  dust.Name = name;
467  dust.Type = ModDust.ReserveDustID();
468  dust.Texture = !string.IsNullOrEmpty(texture) ? ModContent.GetTexture(texture) : Main.dustTexture;
469 
470  dusts[name] = dust;
471  ModDust.dusts.Add(dust);
472  }

+ Here is the call graph for this function:

int Terraria.ModLoader.Mod.AddEquipTexture ( ModItem  item,
EquipType  type,
string  name,
string  texture,
string  armTexture = "",
string  femaleTexture = "" 
)

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

Definition at line 324 of file Mod.cs.

325  {
326  return AddEquipTexture(new EquipTexture(), item, type, name, texture, armTexture, femaleTexture);
327  }
int AddEquipTexture(ModItem item, EquipType type, string name, string texture, string armTexture="", string femaleTexture="")
Adds an equipment texture of the specified type, internal name, and associated item to your mod...
Definition: Mod.cs:324
int Terraria.ModLoader.Mod.AddEquipTexture ( EquipTexture  equipTexture,
ModItem  item,
EquipType  type,
string  name,
string  texture,
string  armTexture = "",
string  femaleTexture = "" 
)

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

Definition at line 342 of file Mod.cs.

References Terraria.ModLoader.ModContent.GetTexture(), Terraria.ModLoader.ModItem.item, Terraria.ModLoader.EquipTexture.item, Terraria.ModLoader.EquipTexture.mod, Terraria.ModLoader.EquipTexture.Name, Terraria.ModLoader.EquipTexture.Slot, Terraria.ModLoader.EquipTexture.Texture, Terraria.ModLoader.ModContent.TextureExists(), and Terraria.ModLoader.EquipTexture.Type.

343  {
344  if (!loading)
345  throw new Exception("AddEquipTexture can only be called from Mod.Load or Mod.Autoload");
346 
347  ModContent.GetTexture(texture); //ensure texture exists
348 
349  equipTexture.Texture = texture;
350  equipTexture.mod = this;
351  equipTexture.Name = name;
352  equipTexture.Type = type;
353  equipTexture.item = item;
354  int slot = equipTexture.Slot = EquipLoader.ReserveEquipID(type);
355 
356  EquipLoader.equipTextures[type][slot] = equipTexture;
357  equipTextures[Tuple.Create(name, type)] = equipTexture;
358 
359  if (type == EquipType.Body) {
360  if (femaleTexture == null || !ModContent.TextureExists(femaleTexture))
361  femaleTexture = texture;
362  EquipLoader.femaleTextures[slot] = femaleTexture;
363 
364  ModContent.GetTexture(armTexture); //ensure texture exists
365  EquipLoader.armTextures[slot] = armTexture;
366  }
367  if (item != null) {
368  IDictionary<EquipType, int> slots;
369  if (!EquipLoader.idToSlot.TryGetValue(item.item.type, out slots))
370  EquipLoader.idToSlot[item.item.type] = slots = new Dictionary<EquipType, int>();
371 
372  slots[type] = slot;
373  if (type == EquipType.Head || type == EquipType.Body || type == EquipType.Legs)
374  EquipLoader.slotToId[type][slot] = item.item.type;
375  }
376  return slot;
377  }
EquipType
This is an enum of all the types of equipment that exist. An equipment type is defined as a type or l...
Definition: EquipType.cs:6

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AddGlobalBgStyle ( string  name,
GlobalBgStyle  globalBgStyle 
)

Adds the given global background style with the given name to this mod.

Parameters
nameThe name.
globalBgStyleThe global bg style.

Definition at line 1166 of file Mod.cs.

References Terraria.ModLoader.GlobalBgStyle.mod, and Terraria.ModLoader.GlobalBgStyle.Name.

1166  {
1167  if (!loading)
1168  throw new Exception("AddGlobalBgStyle can only be called from Mod.Load or Mod.Autoload");
1169 
1170  globalBgStyle.mod = this;
1171  globalBgStyle.Name = name;
1172 
1173  globalBgStyles[name] = globalBgStyle;
1174  GlobalBgStyleLoader.globalBgStyles.Add(globalBgStyle);
1175  }
void Terraria.ModLoader.Mod.AddGlobalBuff ( string  name,
GlobalBuff  globalBuff 
)

Adds the given GlobalBuff instance to this mod using the provided name.

Parameters
nameThe name.
globalBuffThe global buff.

Definition at line 970 of file Mod.cs.

References Terraria.ModLoader.GlobalBuff.mod, and Terraria.ModLoader.GlobalBuff.Name.

970  {
971  globalBuff.mod = this;
972  globalBuff.Name = name;
973 
974  globalBuffs[name] = globalBuff;
975  BuffLoader.globalBuffs.Add(globalBuff);
976  }
void Terraria.ModLoader.Mod.AddGlobalItem ( string  name,
GlobalItem  globalItem 
)

Adds the given GlobalItem instance to this mod with the provided name.

Parameters
nameThe name.
globalItemThe global item.

Definition at line 275 of file Mod.cs.

References Terraria.ModLoader.GlobalItem.mod, and Terraria.ModLoader.GlobalItem.Name.

275  {
276  if (!loading)
277  throw new Exception("AddGlobalItem can only be called from Mod.Load or Mod.Autoload");
278 
279  ItemLoader.VerifyGlobalItem(globalItem);
280 
281  globalItem.mod = this;
282  globalItem.Name = name;
283 
284  globalItems[name] = globalItem;
285  globalItem.index = ItemLoader.globalItems.Count;
286  ItemLoader.globalIndexes[Name + ':' + name] = ItemLoader.globalItems.Count;
287  if (ItemLoader.globalIndexesByType.ContainsKey(globalItem.GetType())) {
288  ItemLoader.globalIndexesByType[globalItem.GetType()] = -1;
289  }
290  else {
291  ItemLoader.globalIndexesByType[globalItem.GetType()] = ItemLoader.globalItems.Count;
292  }
293  ItemLoader.globalItems.Add(globalItem);
294  }
virtual string Name
Stores the name of the mod. This name serves as the mod&#39;s identification, and also helps with saving ...
Definition: Mod.cs:45
void Terraria.ModLoader.Mod.AddGlobalNPC ( string  name,
GlobalNPC  globalNPC 
)

Adds the given GlobalNPC instance to this mod with the provided name.

Parameters
nameThe name.
globalNPCThe global NPC.

Definition at line 823 of file Mod.cs.

References Terraria.ModLoader.GlobalNPC.mod, and Terraria.ModLoader.GlobalNPC.Name.

823  {
824  if (!loading)
825  throw new Exception("AddGlobalNPC can only be called from Mod.Load or Mod.Autoload");
826 
827  NPCLoader.VerifyGlobalNPC(globalNPC);
828 
829  globalNPC.mod = this;
830  globalNPC.Name = name;
831 
832  globalNPCs[name] = globalNPC;
833  globalNPC.index = NPCLoader.globalNPCs.Count;
834  NPCLoader.globalIndexes[Name + ':' + name] = NPCLoader.globalNPCs.Count;
835  if (NPCLoader.globalIndexesByType.ContainsKey(globalNPC.GetType())) {
836  NPCLoader.globalIndexesByType[globalNPC.GetType()] = -1;
837  }
838  else {
839  NPCLoader.globalIndexesByType[globalNPC.GetType()] = NPCLoader.globalNPCs.Count;
840  }
841  NPCLoader.globalNPCs.Add(globalNPC);
842  }
virtual string Name
Stores the name of the mod. This name serves as the mod&#39;s identification, and also helps with saving ...
Definition: Mod.cs:45
void Terraria.ModLoader.Mod.AddGlobalProjectile ( string  name,
GlobalProjectile  globalProjectile 
)

Adds the given GlobalProjectile instance to this mod with the provided name.

Parameters
nameThe name.
globalProjectileThe global projectile.

Definition at line 744 of file Mod.cs.

References Terraria.ModLoader.GlobalProjectile.mod, and Terraria.ModLoader.GlobalProjectile.Name.

744  {
745  if (!loading)
746  throw new Exception("AddGlobalProjectile can only be called from Mod.Load or Mod.Autoload");
747 
748  ProjectileLoader.VerifyGlobalProjectile(globalProjectile);
749 
750  globalProjectile.mod = this;
751  globalProjectile.Name = name;
752 
753  globalProjectiles[name] = globalProjectile;
754  globalProjectile.index = ProjectileLoader.globalProjectiles.Count;
755  ProjectileLoader.globalIndexes[Name + ':' + name] = ProjectileLoader.globalProjectiles.Count;
756  if (ProjectileLoader.globalIndexesByType.ContainsKey(globalProjectile.GetType())) {
757  ProjectileLoader.globalIndexesByType[globalProjectile.GetType()] = -1;
758  }
759  else {
760  ProjectileLoader.globalIndexesByType[globalProjectile.GetType()] = ProjectileLoader.globalProjectiles.Count;
761  }
762  ProjectileLoader.globalProjectiles.Add(globalProjectile);
763  }
virtual string Name
Stores the name of the mod. This name serves as the mod&#39;s identification, and also helps with saving ...
Definition: Mod.cs:45
void Terraria.ModLoader.Mod.AddGlobalRecipe ( string  name,
GlobalRecipe  globalRecipe 
)

Manually add a Global Recipe during Load

Parameters
nameThe name.
globalRecipeThe global recipe.

Definition at line 1340 of file Mod.cs.

References Terraria.ModLoader.GlobalRecipe.mod, and Terraria.ModLoader.GlobalRecipe.Name.

1340  {
1341  if (!loading)
1342  throw new Exception("AddGlobalRecipe can only be called from Mod.Load or Mod.Autoload");
1343 
1344  globalRecipe.mod = this;
1345  globalRecipe.Name = name;
1346 
1347  globalRecipes[name] = globalRecipe;
1348  RecipeHooks.Add(globalRecipe);
1349  }
void Terraria.ModLoader.Mod.AddGlobalTile ( string  name,
GlobalTile  globalTile 
)

Adds the given GlobalTile instance to this mod with the provided name.

Parameters
nameThe name.
globalTileThe global tile.

Definition at line 557 of file Mod.cs.

References Terraria.ModLoader.GlobalTile.mod, and Terraria.ModLoader.GlobalTile.Name.

557  {
558  if (!loading)
559  throw new Exception("AddGlobalTile can only be called from Mod.Load or Mod.Autoload");
560 
561  globalTile.mod = this;
562  globalTile.Name = name;
563 
564  globalTiles[name] = globalTile;
565  TileLoader.globalTiles.Add(globalTile);
566  }
void Terraria.ModLoader.Mod.AddGlobalWall ( string  name,
GlobalWall  globalWall 
)

Adds the given GlobalWall instance to this mod with the provided name.

Parameters
nameThe name.
globalWallThe global wall.

Definition at line 675 of file Mod.cs.

References Terraria.ModLoader.GlobalWall.mod, and Terraria.ModLoader.GlobalWall.Name.

675  {
676  if (!loading)
677  throw new Exception("AddGlobalWall can only be called from Mod.Load or Mod.Autoload");
678 
679  globalWall.mod = this;
680  globalWall.Name = name;
681 
682  globalWalls[name] = globalWall;
683  WallLoader.globalWalls.Add(globalWall);
684  }
void Terraria.ModLoader.Mod.AddGore ( string  texture,
ModGore  modGore = null 
)

Adds the given texture to the game as a custom gore, with the given custom gore behavior. If no custom gore behavior is provided, the custom gore will have the default vanilla behavior.

Parameters
textureThe texture.
modGoreThe mod gore.

Definition at line 1258 of file Mod.cs.

References Terraria.ModLoader.ModGore.GetGoreSlot().

1258  {
1259  if (!loading)
1260  throw new Exception("AddGore can only be called from Mod.Load or Mod.Autoload");
1261 
1262  int id = ModGore.ReserveGoreID();
1263  ModGore.gores[texture] = id;
1264  if (modGore != null) {
1265  ModGore.modGores[id] = modGore;
1266  }
1267  }

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AddItem ( string  name,
ModItem  item 
)

Adds a type of item to your mod with the specified internal name. This method should be called in Load. You can obtain an instance of ModItem by overriding it then creating an instance of the subclass.

Parameters
nameThe name.
itemThe item.
Exceptions
System.ExceptionYou tried to add 2 ModItems with the same name: " + name + ". Maybe 2 classes share a classname but in different namespaces while autoloading or you manually called AddItem with 2 items of the same name.

Definition at line 223 of file Mod.cs.

References Terraria.ModLoader.ModItem.DisplayName, Terraria.ModLoader.ModItem.item, Terraria.ModLoader.ModItem.mod, Terraria.ModLoader.ModItem.Name, and Terraria.ModLoader.ModItem.Tooltip.

223  {
224  if (!loading)
225  throw new Exception(Language.GetTextValue("tModLoader.LoadErrorAddItemOnlyInLoad"));
226 
227  if (items.ContainsKey(name))
228  throw new Exception(Language.GetTextValue("tModLoader.LoadError2ModItemSameName", name));
229 
230  item.mod = this;
231  item.Name = name;
232  item.DisplayName = GetOrCreateTranslation(string.Format("Mods.{0}.ItemName.{1}", Name, name));
233  item.Tooltip = GetOrCreateTranslation(string.Format("Mods.{0}.ItemTooltip.{1}", Name, name), true);
234 
235  item.item.ResetStats(ItemLoader.ReserveItemID());
236  item.item.modItem = item;
237 
238  items[name] = item;
239  ItemLoader.items.Add(item);
240  }
virtual string Name
Stores the name of the mod. This name serves as the mod&#39;s identification, and also helps with saving ...
Definition: Mod.cs:45
void Terraria.ModLoader.Mod.AddModWorld ( string  name,
ModWorld  modWorld 
)

Adds a ModWorld to this mod with the given name.

Parameters
nameThe name.
modWorldThe mod world.

Definition at line 1075 of file Mod.cs.

References Terraria.ModLoader.ModWorld.mod, and Terraria.ModLoader.ModWorld.Name.

1075  {
1076  if (!loading)
1077  throw new Exception("AddModWorld can only be called from Mod.Load or Mod.Autoload");
1078 
1079  modWorld.mod = this;
1080  modWorld.Name = name;
1081 
1082  worlds[name] = modWorld;
1083  WorldHooks.Add(modWorld);
1084  }
void Terraria.ModLoader.Mod.AddMount ( string  name,
ModMountData  mount,
string  texture,
IDictionary< MountTextureType, string >  extraTextures = null 
)

Adds the given mount to the game with the given name and texture. The extraTextures dictionary should optionally map types of mount textures to the texture paths you want to include.

Parameters
nameThe name.
mountThe mount.
textureThe texture.
extraTexturesThe extra textures.

Definition at line 994 of file Mod.cs.

References Terraria.ModLoader.ModContent.GetTexture(), Terraria.ModLoader.ModMountData.mod, Terraria.ModLoader.ModMountData.Name, Terraria.ModLoader.ModContent.TextureExists(), and Terraria.ModLoader.ModMountData.Type.

995  {
996  if (!loading)
997  throw new Exception("AddMount can only be called from Mod.Load or Mod.Autoload");
998 
999  if (Mount.mounts == null || Mount.mounts.Length == MountID.Count)
1000  Mount.Initialize();
1001 
1002  mount.mod = this;
1003  mount.Name = name;
1004  mount.Type = MountLoader.ReserveMountID();
1005  mount.texture = texture;
1006 
1007  mountDatas[name] = mount;
1008  MountLoader.mountDatas[mount.Type] = mount;
1009 
1010  if (extraTextures == null)
1011  return;
1012 
1013  foreach (var entry in extraTextures) {
1014  if (!ModContent.TextureExists(entry.Value))
1015  continue;
1016 
1017  Texture2D extraTexture = ModContent.GetTexture(entry.Value);
1018  switch (entry.Key) {
1019  case MountTextureType.Back:
1020  mount.mountData.backTexture = extraTexture;
1021  break;
1022  case MountTextureType.BackGlow:
1023  mount.mountData.backTextureGlow = extraTexture;
1024  break;
1025  case MountTextureType.BackExtra:
1026  mount.mountData.backTextureExtra = extraTexture;
1027  break;
1028  case MountTextureType.BackExtraGlow:
1029  mount.mountData.backTextureExtraGlow = extraTexture;
1030  break;
1031  case MountTextureType.Front:
1032  mount.mountData.frontTexture = extraTexture;
1033  break;
1034  case MountTextureType.FrontGlow:
1035  mount.mountData.frontTextureGlow = extraTexture;
1036  break;
1037  case MountTextureType.FrontExtra:
1038  mount.mountData.frontTextureExtra = extraTexture;
1039  break;
1040  case MountTextureType.FrontExtraGlow:
1041  mount.mountData.frontTextureExtraGlow = extraTexture;
1042  break;
1043  }
1044  }
1045  }
MountTextureType
This is an enum of all possible types of extra mount textures for custom mounts. Use these as keys in...

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AddMusicBox ( int  musicSlot,
int  itemType,
int  tileType,
int  tileFrameY = 0 
)

Allows you to tie a music ID, and item ID, and a tile ID together to form a music box. When music with the given ID is playing, equipped music boxes have a chance to change their ID to the given item type. When an item with the given item type is equipped, it will play the music that has musicSlot as its ID. When a tile with the given type and Y-frame is nearby, if its X-frame is >= 36, it will play the music that has musicSlot as its ID.

Parameters
musicSlotThe music slot.
itemTypeType of the item.
tileTypeType of the tile.
tileFrameYThe tile frame y.
Exceptions
System.ArgumentOutOfRangeExceptionCannot assign music box to vanilla music ID " + musicSlot or Music ID " + musicSlot + " does not exist or Cannot assign music box to vanilla item ID " + itemType or Item ID " + itemType + " does not exist or Cannot assign music box to vanilla tile ID " + tileType or Tile ID " + tileType + " does not exist
System.ArgumentExceptionMusic ID " + musicSlot + " has already been assigned a music box or Item ID " + itemType + " has already been assigned a music or or Y-frame must be divisible by 36

Definition at line 1400 of file Mod.cs.

References Terraria.ModLoader.ItemLoader.GetItem(), Terraria.ModLoader.TileLoader.GetTile(), and Terraria.ModLoader.SoundLoader.SoundCount().

1400  {
1401  if (!loading)
1402  throw new Exception("AddMusicBox can only be called from Mod.Load or Mod.Autoload");
1403 
1404  if (musicSlot < Main.maxMusic) {
1405  throw new ArgumentOutOfRangeException("Cannot assign music box to vanilla music ID " + musicSlot);
1406  }
1407  if (musicSlot >= SoundLoader.SoundCount(SoundType.Music)) {
1408  throw new ArgumentOutOfRangeException("Music ID " + musicSlot + " does not exist");
1409  }
1410  if (itemType < ItemID.Count) {
1411  throw new ArgumentOutOfRangeException("Cannot assign music box to vanilla item ID " + itemType);
1412  }
1413  if (ItemLoader.GetItem(itemType) == null) {
1414  throw new ArgumentOutOfRangeException("Item ID " + itemType + " does not exist");
1415  }
1416  if (tileType < TileID.Count) {
1417  throw new ArgumentOutOfRangeException("Cannot assign music box to vanilla tile ID " + tileType);
1418  }
1419  if (TileLoader.GetTile(tileType) == null) {
1420  throw new ArgumentOutOfRangeException("Tile ID " + tileType + " does not exist");
1421  }
1422  if (SoundLoader.musicToItem.ContainsKey(musicSlot)) {
1423  throw new ArgumentException("Music ID " + musicSlot + " has already been assigned a music box");
1424  }
1425  if (SoundLoader.itemToMusic.ContainsKey(itemType)) {
1426  throw new ArgumentException("Item ID " + itemType + " has already been assigned a music");
1427  }
1428  if (!SoundLoader.tileToMusic.ContainsKey(tileType)) {
1429  SoundLoader.tileToMusic[tileType] = new Dictionary<int, int>();
1430  }
1431  if (SoundLoader.tileToMusic[tileType].ContainsKey(tileFrameY)) {
1432  string message = "Y-frame " + tileFrameY + " of tile type " + tileType + " has already been assigned a music";
1433  throw new ArgumentException(message);
1434  }
1435  if (tileFrameY % 36 != 0) {
1436  throw new ArgumentException("Y-frame must be divisible by 36");
1437  }
1438  SoundLoader.musicToItem[musicSlot] = itemType;
1439  SoundLoader.itemToMusic[itemType] = musicSlot;
1440  SoundLoader.tileToMusic[tileType][tileFrameY] = musicSlot;
1441  }
SoundType
This is an enum of the types of sound you can add to the game. This is used for determining whether a...
Definition: SoundType.cs:12

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AddNPC ( string  name,
ModNPC  npc 
)

Adds a type of NPC to the game with the specified name and texture. Also allows you to give the NPC alternate textures.

Parameters
nameThe name.
npcThe NPC.

Definition at line 779 of file Mod.cs.

References Terraria.ModLoader.ModNPC.DisplayName, Terraria.ModLoader.ModNPC.mod, Terraria.ModLoader.ModNPC.Name, and Terraria.ModLoader.ModNPC.npc.

779  {
780  if (!loading)
781  throw new Exception("AddNPC can only be called from Mod.Load or Mod.Autoload");
782 
783  if (npcs.ContainsKey(name))
784  throw new Exception("You tried to add 2 ModNPC with the same name: " + name + ". Maybe 2 classes share a classname but in different namespaces while autoloading or you manually called AddNPC with 2 npcs of the same name.");
785 
786  npc.mod = this;
787  npc.Name = name;
788  npc.npc.type = NPCLoader.ReserveNPCID();
789  npc.DisplayName = GetOrCreateTranslation(string.Format("Mods.{0}.NPCName.{1}", Name, name));
790 
791  npcs[name] = npc;
792  NPCLoader.npcs.Add(npc);
793  }
virtual string Name
Stores the name of the mod. This name serves as the mod&#39;s identification, and also helps with saving ...
Definition: Mod.cs:45
void 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.
Exceptions
MissingResourceException

Definition at line 859 of file Mod.cs.

References Terraria.ModLoader.ModContent.GetTexture().

859  {
860  if (!loading)
861  throw new Exception("AddNPCHeadTexture can only be called from Mod.Load or Mod.Autoload");
862 
863  int slot = NPCHeadLoader.ReserveHeadSlot();
864  NPCHeadLoader.heads[texture] = slot;
865  if (!Main.dedServ) {
866  ModContent.GetTexture(texture);
867  }
868  /*else if (Main.dedServ && !(ModLoader.FileExists(texture + ".png") || ModLoader.FileExists(texture + ".rawimg")))
869  {
870  throw new MissingResourceException(texture);
871  }*/
872  NPCHeadLoader.npcToHead[npcType] = slot;
873  NPCHeadLoader.headToNPC[slot] = npcType;
874  }

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AddPlayer ( string  name,
ModPlayer  player 
)

Adds a type of ModPlayer to this mod. All ModPlayer types will be newly created and attached to each player that is loaded.

Parameters
nameThe name.
playerThe player.

Definition at line 898 of file Mod.cs.

References Terraria.ModLoader.ModPlayer.mod, and Terraria.ModLoader.ModPlayer.Name.

898  {
899  if (!loading)
900  throw new Exception("AddPlayer can only be called from Mod.Load or Mod.Autoload");
901 
902  player.mod = this;
903  player.Name = name;
904 
905  players[name] = player;
906  PlayerHooks.Add(player);
907  }
void Terraria.ModLoader.Mod.AddPrefix ( string  name,
ModPrefix  prefix 
)

Adds a prefix to your mod with the specified internal name. This method should be called in Load. You can obtain an instance of ModPrefix by overriding it then creating an instance of the subclass.

Parameters
nameThe name.
prefixThe prefix.
Exceptions
System.ExceptionYou tried to add 2 ModItems with the same name: " + name + ". Maybe 2 classes share a classname but in different namespaces while autoloading or you manually called AddItem with 2 items of the same name.

Definition at line 410 of file Mod.cs.

References Terraria.ModLoader.ModPrefix.Category, Terraria.ModLoader.ModPrefix.DisplayName, Terraria.ModLoader.ModPrefix.mod, Terraria.ModLoader.ModPrefix.Name, and Terraria.ModLoader.ModPrefix.Type.

410  {
411  if (!loading)
412  throw new Exception("AddPrefix can only be called from Mod.Load or Mod.Autoload");
413 
414  if (prefixes.ContainsKey(name))
415  throw new Exception("You tried to add 2 ModPrefixes with the same name: " + name + ". Maybe 2 classes share a classname but in different namespaces while autoloading or you manually called AddPrefix with 2 prefixes of the same name.");
416 
417  prefix.mod = this;
418  prefix.Name = name;
419  prefix.DisplayName = GetOrCreateTranslation(string.Format("Mods.{0}.Prefix.{1}", Name, name));
420  prefix.Type = ModPrefix.ReservePrefixID();
421 
422  prefixes[name] = prefix;
423  ModPrefix.prefixes.Add(prefix);
424  ModPrefix.categoryPrefixes[prefix.Category].Add(prefix);
425  }
virtual string Name
Stores the name of the mod. This name serves as the mod&#39;s identification, and also helps with saving ...
Definition: Mod.cs:45
void Terraria.ModLoader.Mod.AddProjectile ( string  name,
ModProjectile  projectile 
)

Adds a type of projectile to the game with the specified name.

Parameters
nameThe name.
projectileThe projectile.

Definition at line 700 of file Mod.cs.

References Terraria.ModLoader.ModProjectile.DisplayName, Terraria.ModLoader.ModProjectile.mod, Terraria.ModLoader.ModProjectile.Name, and Terraria.ModLoader.ModProjectile.projectile.

700  {
701  if (!loading)
702  throw new Exception("AddProjectile can only be called from Mod.Load or Mod.Autoload");
703 
704  if (projectiles.ContainsKey(name))
705  throw new Exception("You tried to add 2 ModProjectile with the same name: " + name + ". Maybe 2 classes share a classname but in different namespaces while autoloading or you manually called AddProjectile with 2 projectiles of the same name.");
706 
707  projectile.mod = this;
708  projectile.Name = name;
709  projectile.projectile.type = ProjectileLoader.ReserveProjectileID();
710  projectile.DisplayName = GetOrCreateTranslation(string.Format("Mods.{0}.ProjectileName.{1}", Name, name));
711 
712  projectiles[name] = projectile;
713  ProjectileLoader.projectiles.Add(projectile);
714  }
virtual string Name
Stores the name of the mod. This name serves as the mod&#39;s identification, and also helps with saving ...
Definition: Mod.cs:45
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.

Definition at line 90 of file Mod.cs.

90  {
91  }
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 ModRecipe, since it provides methods that simplify recipe creation.

Definition at line 96 of file Mod.cs.

96  {
97  }
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.

Definition at line 1289 of file Mod.cs.

References Terraria.ModLoader.ModContent.GetSound(), and Terraria.ModLoader.SoundLoader.GetSoundSlot().

1289  {
1290  if (!loading)
1291  throw new Exception("AddSound can only be called from Mod.Load or Mod.Autoload");
1292  int id = SoundLoader.ReserveSoundID(type);
1293  SoundLoader.sounds[type][soundPath] = id;
1294  if (modSound != null) {
1295  SoundLoader.modSounds[type][id] = modSound;
1296  modSound.sound = ModContent.GetSound(soundPath);
1297  }
1298  }

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AddSurfaceBgStyle ( string  name,
ModSurfaceBgStyle  surfaceBgStyle 
)

Adds the given surface background style with the given name to this mod.

Parameters
nameThe name.
surfaceBgStyleThe surface bg style.

Definition at line 1131 of file Mod.cs.

References Terraria.ModLoader.ModSurfaceBgStyle.mod, Terraria.ModLoader.ModSurfaceBgStyle.Name, and Terraria.ModLoader.ModSurfaceBgStyle.Slot.

1131  {
1132  if (!loading)
1133  throw new Exception("AddSurfaceBgStyle can only be called from Mod.Load or Mod.Autoload");
1134 
1135  surfaceBgStyle.mod = this;
1136  surfaceBgStyle.Name = name;
1137  surfaceBgStyle.Slot = SurfaceBgStyleLoader.ReserveBackgroundSlot();
1138 
1139  surfaceBgStyles[name] = surfaceBgStyle;
1140  SurfaceBgStyleLoader.surfaceBgStyles.Add(surfaceBgStyle);
1141  }
void Terraria.ModLoader.Mod.AddTexture ( string  name,
Texture2D  texture 
)

Shorthand for calling ModLoader.AddTexture(this.FileName(name), texture).

Parameters
nameThe name.
textureThe texture.
Exceptions
Terraria.ModLoader.Exceptions.ModNameExceptionTexture already exist: " + name

Definition at line 1520 of file Mod.cs.

1520  {
1521  if (TextureExists(name))
1522  throw new Exception("Texture already exist: " + name);
1523 
1524  textures[name] = texture;
1525  }
bool TextureExists(string name)
Shorthand for calling ModLoader.TextureExists(this.FileName(name)).
void Terraria.ModLoader.Mod.AddTile ( string  name,
ModTile  tile,
string  texture 
)

Adds a type of tile to the game with the specified name and texture.

Parameters
nameThe name.
tileThe tile.
textureThe texture.

Definition at line 508 of file Mod.cs.

References Terraria.ModLoader.ModTile.mod, Terraria.ModLoader.ModTile.Name, and Terraria.ModLoader.ModTile.Type.

508  {
509  if (!loading)
510  throw new Exception("AddItem can only be called from Mod.Load or Mod.Autoload");
511 
512  if (tiles.ContainsKey(name))
513  throw new Exception("You tried to add 2 ModTile with the same name: " + name + ". Maybe 2 classes share a classname but in different namespaces while autoloading or you manually called AddTile with 2 tiles of the same name.");
514 
515  tile.mod = this;
516  tile.Name = name;
517  tile.Type = (ushort)TileLoader.ReserveTileID();
518  tile.texture = texture;
519 
520  tiles[name] = tile;
521  TileLoader.tiles.Add(tile);
522  }
void Terraria.ModLoader.Mod.AddTileEntity ( string  name,
ModTileEntity  entity 
)

Manually add a tile entity during Load.

Definition at line 585 of file Mod.cs.

References Terraria.ModLoader.ModTileEntity.mod, Terraria.ModLoader.ModTileEntity.Name, and Terraria.ModLoader.ModTileEntity.Type.

585  {
586  if (!loading)
587  throw new Exception("AddTileEntity can only be called from Mod.Load or Mod.Autoload");
588 
589  int id = ModTileEntity.ReserveTileEntityID();
590  entity.mod = this;
591  entity.Name = name;
592  entity.Type = id;
593  entity.type = (byte)id;
594 
595  tileEntities[name] = entity;
596  ModTileEntity.tileEntities.Add(entity);
597  }
void Terraria.ModLoader.Mod.AddTranslation ( ModTranslation  translation)

Adds a ModTranslation to the game so that you can use Language.GetText to get a LocalizedText.

Definition at line 1466 of file Mod.cs.

References Terraria.ModLoader.ModTranslation.Key.

1466  {
1467  translations[translation.Key] = translation;
1468  }
void Terraria.ModLoader.Mod.AddUgBgStyle ( string  name,
ModUgBgStyle  ugBgStyle 
)

Adds the given underground background style with the given name to this mod.

Parameters
nameThe name.
ugBgStyleThe ug bg style.

Definition at line 1105 of file Mod.cs.

References Terraria.ModLoader.ModUgBgStyle.mod, Terraria.ModLoader.ModUgBgStyle.Name, and Terraria.ModLoader.ModUgBgStyle.Slot.

1105  {
1106  if (!loading)
1107  throw new Exception("AddUgBgStyle can only be called from Mod.Load or Mod.Autoload");
1108 
1109  ugBgStyle.mod = this;
1110  ugBgStyle.Name = name;
1111  ugBgStyle.Slot = UgBgStyleLoader.ReserveBackgroundSlot();
1112 
1113  ugBgStyles[name] = ugBgStyle;
1114  UgBgStyleLoader.ugBgStyles.Add(ugBgStyle);
1115  }
void Terraria.ModLoader.Mod.AddWall ( string  name,
ModWall  wall,
string  texture 
)

Adds a type of wall to the game with the specified name and texture.

Parameters
nameThe name.
wallThe wall.
textureThe texture.

Definition at line 634 of file Mod.cs.

References Terraria.ModLoader.ModWall.mod, Terraria.ModLoader.ModWall.Name, and Terraria.ModLoader.ModWall.Type.

634  {
635  if (!loading)
636  throw new Exception("AddWall can only be called from Mod.Load or Mod.Autoload");
637 
638  wall.mod = this;
639  wall.Name = name;
640  wall.Type = (ushort)WallLoader.ReserveWallID();
641  wall.texture = texture;
642 
643  walls[name] = wall;
644  WallLoader.walls.Add(wall);
645  }
void Terraria.ModLoader.Mod.AddWaterfallStyle ( string  name,
ModWaterfallStyle  waterfallStyle,
string  texture 
)

Adds the given waterfall style to the game with the given name and texture path.

Parameters
nameThe name.
waterfallStyleThe waterfall style.
textureThe texture.

Definition at line 1222 of file Mod.cs.

References Terraria.ModLoader.ModWaterfallStyle.mod, Terraria.ModLoader.ModWaterfallStyle.Name, and Terraria.ModLoader.ModWaterfallStyle.Type.

1222  {
1223  if (!loading)
1224  throw new Exception("AddWaterfallStyle can only be called from Mod.Load or Mod.Autoload");
1225 
1226  waterfallStyle.mod = this;
1227  waterfallStyle.Name = name;
1228  waterfallStyle.Type = WaterfallStyleLoader.ReserveStyle();
1229  waterfallStyle.texture = texture;
1230 
1231  waterfallStyles[name] = waterfallStyle;
1232  WaterfallStyleLoader.waterfallStyles.Add(waterfallStyle);
1233  }
void Terraria.ModLoader.Mod.AddWaterStyle ( string  name,
ModWaterStyle  waterStyle,
string  texture,
string  blockTexture 
)

Adds the given water style to the game with the given name, texture path, and block texture path.

Parameters
nameThe name.
waterStyleThe water style.
textureThe texture.
blockTextureThe block texture.

Definition at line 1193 of file Mod.cs.

References Terraria.ModLoader.ModWaterStyle.mod, Terraria.ModLoader.ModWaterStyle.Name, and Terraria.ModLoader.ModWaterStyle.Type.

1193  {
1194  if (!loading)
1195  throw new Exception("AddWaterStyle can only be called from Mod.Load or Mod.Autoload");
1196 
1197  waterStyle.mod = this;
1198  waterStyle.Name = name;
1199  waterStyle.Type = WaterStyleLoader.ReserveStyle();
1200  waterStyle.texture = texture;
1201  waterStyle.blockTexture = blockTexture;
1202 
1203  waterStyles[name] = waterStyle;
1204  WaterStyleLoader.waterStyles.Add(waterStyle);
1205  }
void Terraria.ModLoader.Mod.AutoloadBackgrounds ( )
private

Definition at line 576 of file ModInternals.cs.

576  {
577  foreach (string texture in textures.Keys.Where(t => t.StartsWith("Backgrounds/"))) {
578  AddBackgroundTexture(Name + '/' + texture);
579  }
580  }
virtual string Name
Stores the name of the mod. This name serves as the mod&#39;s identification, and also helps with saving ...
Definition: Mod.cs:45
void AddBackgroundTexture(string texture)
Adds a texture to the list of background textures and assigns it a background texture slot...
Definition: Mod.cs:1320
void Terraria.ModLoader.Mod.AutoloadBuff ( Type  type)
private

Definition at line 534 of file ModInternals.cs.

References Terraria.ModLoader.ModBuff.Autoload(), Terraria.ModLoader.ModBuff.mod, and Terraria.ModLoader.Mod.Name.

534  {
535  ModBuff buff = (ModBuff)Activator.CreateInstance(type);
536  buff.mod = this;
537  string name = type.Name;
538  string texture = (type.Namespace + "." + type.Name).Replace('.', '/');
539  if (buff.Autoload(ref name, ref texture)) {
540  AddBuff(name, buff, texture);
541  }
542  }
void AddBuff(string name, ModBuff buff, string texture)
Adds a type of buff to the game with the specified internal name and texture.
Definition: Mod.cs:924

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AutoloadCommand ( Type  type)
private

Definition at line 680 of file ModInternals.cs.

680  {
681  var mc = (ModCommand)Activator.CreateInstance(type);
682  mc.mod = this;
683  var name = type.Name;
684  if (mc.Autoload(ref name))
685  AddCommand(name, mc);
686  }
void AddCommand(string name, ModCommand mc)
Manually add a Command during Load
Definition: Mod.cs:1363
void Terraria.ModLoader.Mod.AutoloadDust ( Type  type)
private

Definition at line 422 of file ModInternals.cs.

References Terraria.ModLoader.ModDust.Autoload(), Terraria.ModLoader.ModDust.mod, and Terraria.ModLoader.Mod.Name.

422  {
423  ModDust dust = (ModDust)Activator.CreateInstance(type);
424  dust.mod = this;
425  string name = type.Name;
426  string texture = (type.Namespace + "." + type.Name).Replace('.', '/');
427  if (dust.Autoload(ref name, ref texture)) {
428  AddDust(name, dust, texture);
429  }
430  }
void AddDust(string name, ModDust dust, string texture="")
Adds a type of dust to your mod with the specified name. Create an instance of ModDust normally...
Definition: Mod.cs:461

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AutoloadGlobalBgStyle ( Type  type)
private

Definition at line 600 of file ModInternals.cs.

References Terraria.ModLoader.GlobalBgStyle.Autoload(), Terraria.ModLoader.GlobalBgStyle.mod, and Terraria.ModLoader.Mod.Name.

600  {
601  GlobalBgStyle globalBgStyle = (GlobalBgStyle)Activator.CreateInstance(type);
602  globalBgStyle.mod = this;
603  string name = type.Name;
604  if (globalBgStyle.Autoload(ref name)) {
605  AddGlobalBgStyle(name, globalBgStyle);
606  }
607  }
void AddGlobalBgStyle(string name, GlobalBgStyle globalBgStyle)
Adds the given global background style with the given name to this mod.
Definition: Mod.cs:1166

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AutoloadGlobalBuff ( Type  type)
private

Definition at line 544 of file ModInternals.cs.

References Terraria.ModLoader.GlobalBuff.Autoload(), Terraria.ModLoader.GlobalBuff.mod, and Terraria.ModLoader.Mod.Name.

544  {
545  GlobalBuff globalBuff = (GlobalBuff)Activator.CreateInstance(type);
546  globalBuff.mod = this;
547  string name = type.Name;
548  if (globalBuff.Autoload(ref name)) {
549  AddGlobalBuff(name, globalBuff);
550  }
551  }
void AddGlobalBuff(string name, GlobalBuff globalBuff)
Adds the given GlobalBuff instance to this mod using the provided name.
Definition: Mod.cs:970

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AutoloadGlobalItem ( Type  type)
private

Definition at line 404 of file ModInternals.cs.

References Terraria.ModLoader.GlobalItem.Autoload(), Terraria.ModLoader.GlobalItem.mod, and Terraria.ModLoader.Mod.Name.

404  {
405  GlobalItem globalItem = (GlobalItem)Activator.CreateInstance(type);
406  globalItem.mod = this;
407  string name = type.Name;
408  if (globalItem.Autoload(ref name)) {
409  AddGlobalItem(name, globalItem);
410  }
411  }
void AddGlobalItem(string name, GlobalItem globalItem)
Adds the given GlobalItem instance to this mod with the provided name.
Definition: Mod.cs:275

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AutoloadGlobalNPC ( Type  type)
private

Definition at line 516 of file ModInternals.cs.

References Terraria.ModLoader.GlobalNPC.Autoload(), Terraria.ModLoader.GlobalNPC.mod, and Terraria.ModLoader.Mod.Name.

516  {
517  GlobalNPC globalNPC = (GlobalNPC)Activator.CreateInstance(type);
518  globalNPC.mod = this;
519  string name = type.Name;
520  if (globalNPC.Autoload(ref name)) {
521  AddGlobalNPC(name, globalNPC);
522  }
523  }
void AddGlobalNPC(string name, GlobalNPC globalNPC)
Adds the given GlobalNPC instance to this mod with the provided name.
Definition: Mod.cs:823

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AutoloadGlobalProjectile ( Type  type)
private

Definition at line 488 of file ModInternals.cs.

References Terraria.ModLoader.GlobalProjectile.Autoload(), Terraria.ModLoader.GlobalProjectile.mod, and Terraria.ModLoader.Mod.Name.

488  {
489  GlobalProjectile globalProjectile = (GlobalProjectile)Activator.CreateInstance(type);
490  globalProjectile.mod = this;
491  string name = type.Name;
492  if (globalProjectile.Autoload(ref name)) {
493  AddGlobalProjectile(name, globalProjectile);
494  }
495  }
void AddGlobalProjectile(string name, GlobalProjectile globalProjectile)
Adds the given GlobalProjectile instance to this mod with the provided name.
Definition: Mod.cs:744

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AutoloadGlobalRecipe ( Type  type)
private

Definition at line 671 of file ModInternals.cs.

References Terraria.ModLoader.GlobalRecipe.Autoload(), Terraria.ModLoader.GlobalRecipe.mod, and Terraria.ModLoader.Mod.Name.

671  {
672  GlobalRecipe globalRecipe = (GlobalRecipe)Activator.CreateInstance(type);
673  globalRecipe.mod = this;
674  string name = type.Name;
675  if (globalRecipe.Autoload(ref name)) {
676  AddGlobalRecipe(name, globalRecipe);
677  }
678  }
void AddGlobalRecipe(string name, GlobalRecipe globalRecipe)
Manually add a Global Recipe during Load
Definition: Mod.cs:1340

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AutoloadGlobalTile ( Type  type)
private

Definition at line 442 of file ModInternals.cs.

References Terraria.ModLoader.GlobalTile.Autoload(), Terraria.ModLoader.GlobalTile.mod, and Terraria.ModLoader.Mod.Name.

442  {
443  GlobalTile globalTile = (GlobalTile)Activator.CreateInstance(type);
444  globalTile.mod = this;
445  string name = type.Name;
446  if (globalTile.Autoload(ref name)) {
447  AddGlobalTile(name, globalTile);
448  }
449  }
void AddGlobalTile(string name, GlobalTile globalTile)
Adds the given GlobalTile instance to this mod with the provided name.
Definition: Mod.cs:557

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AutoloadGlobalWall ( Type  type)
private

Definition at line 470 of file ModInternals.cs.

References Terraria.ModLoader.GlobalWall.Autoload(), Terraria.ModLoader.GlobalWall.mod, and Terraria.ModLoader.Mod.Name.

470  {
471  GlobalWall globalWall = (GlobalWall)Activator.CreateInstance(type);
472  globalWall.mod = this;
473  string name = type.Name;
474  if (globalWall.Autoload(ref name)) {
475  AddGlobalWall(name, globalWall);
476  }
477  }
void AddGlobalWall(string name, GlobalWall globalWall)
Adds the given GlobalWall instance to this mod with the provided name.
Definition: Mod.cs:675

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AutoloadGores ( IList< Type >  modGores)
private

Definition at line 630 of file ModInternals.cs.

630  {
631  var modGoreNames = modGores.ToDictionary(t => t.Namespace + "." + t.Name);
632  foreach (var texture in textures.Keys.Where(t => t.StartsWith("Gores/"))) {
633  ModGore modGore = null;
634  Type t;
635  if (modGoreNames.TryGetValue(Name + "." + texture.Replace('/', '.'), out t))
636  modGore = (ModGore)Activator.CreateInstance(t);
637 
638  AddGore(Name + '/' + texture, modGore);
639  }
640  }
void AddGore(string texture, ModGore modGore=null)
Adds the given texture to the game as a custom gore, with the given custom gore behavior. If no custom gore behavior is provided, the custom gore will have the default vanilla behavior.
Definition: Mod.cs:1258
virtual string Name
Stores the name of the mod. This name serves as the mod&#39;s identification, and also helps with saving ...
Definition: Mod.cs:45
void Terraria.ModLoader.Mod.AutoloadItem ( Type  type)
private

Definition at line 390 of file ModInternals.cs.

References Terraria.ModLoader.ModItem.Autoload(), Terraria.ModLoader.ModItem.mod, Terraria.ModLoader.ModItem.Name, Terraria.ModLoader.Mod.Name, and Terraria.ModLoader.ModItem.Texture.

390  {
391  ModItem item = (ModItem)Activator.CreateInstance(type);
392  item.mod = this;
393  string name = type.Name;
394  if (item.Autoload(ref name)) {
395  AddItem(name, item);
396  var autoloadEquip = type.GetAttribute<AutoloadEquip>();
397  if (autoloadEquip != null)
398  foreach (var equip in autoloadEquip.equipTypes)
399  AddEquipTexture(item, equip, item.Name, item.Texture + '_' + equip,
400  item.Texture + "_Arms", item.Texture + "_FemaleBody");
401  }
402  }
void AddItem(string name, ModItem item)
Adds a type of item to your mod with the specified internal name. This method should be called in Loa...
Definition: Mod.cs:223
int AddEquipTexture(ModItem item, EquipType type, string name, string texture, string armTexture="", string femaleTexture="")
Adds an equipment texture of the specified type, internal name, and associated item to your mod...
Definition: Mod.cs:324

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AutoloadLocalization ( )
private

Loads .lang files

Definition at line 691 of file ModInternals.cs.

691  {
692  var modTranslationDictionary = new Dictionary<string, ModTranslation>();
693  foreach (var translationFile in File.Where(name => Path.GetExtension(name) == ".lang")) {
694  // .lang files need to be UTF8 encoded.
695  string translationFileContents = System.Text.Encoding.UTF8.GetString(File.GetBytes(translationFile));
696  GameCulture culture = GameCulture.FromName(Path.GetFileNameWithoutExtension(translationFile));
697 
698  using (StringReader reader = new StringReader(translationFileContents)) {
699  string line;
700  while ((line = reader.ReadLine()) != null) {
701  int split = line.IndexOf('=');
702  if (split < 0)
703  continue; // lines witout a = are ignored
704  string key = line.Substring(0, split).Trim().Replace(" ", "_");
705  string value = line.Substring(split + 1).Trim();
706  if (value.Length == 0) {
707  continue;
708  }
709  value = value.Replace("\\n", "\n");
710  // TODO: Maybe prepend key with filename: en.US.ItemName.lang would automatically assume "ItemName." for all entries.
711  //string key = key;
712  if (!modTranslationDictionary.TryGetValue(key, out ModTranslation mt))
713  modTranslationDictionary[key] = mt = CreateTranslation(key);
714  mt.AddTranslation(culture, value);
715  }
716  }
717  }
718 
719  foreach (var value in modTranslationDictionary.Values) {
720  AddTranslation(value);
721  }
722  }
TmodFile File
The TmodFile object created when tModLoader reads this mod.
Definition: Mod.cs:32
void AddTranslation(int culture, string value)
void AddTranslation(ModTranslation translation)
Adds a ModTranslation to the game so that you can use Language.GetText to get a LocalizedText.
Definition: Mod.cs:1466
ModTranslation CreateTranslation(string key)
Creates a ModTranslation object that you can use in AddTranslation.
byte[] GetBytes(string fileName)
Definition: TmodFile.cs:71
void Terraria.ModLoader.Mod.AutoloadModWorld ( Type  type)
private

Definition at line 567 of file ModInternals.cs.

References Terraria.ModLoader.ModWorld.Autoload(), Terraria.ModLoader.ModWorld.mod, and Terraria.ModLoader.Mod.Name.

567  {
568  ModWorld modWorld = (ModWorld)Activator.CreateInstance(type);
569  modWorld.mod = this;
570  string name = type.Name;
571  if (modWorld.Autoload(ref name)) {
572  AddModWorld(name, modWorld);
573  }
574  }
void AddModWorld(string name, ModWorld modWorld)
Adds a ModWorld to this mod with the given name.
Definition: Mod.cs:1075

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AutoloadMountData ( Type  type)
private

Definition at line 553 of file ModInternals.cs.

References Terraria.ModLoader.ModMountData.mod, and Terraria.ModLoader.Mod.Name.

553  {
554  ModMountData mount = (ModMountData)Activator.CreateInstance(type);
555  mount.mod = this;
556  string name = type.Name;
557  string texture = (type.Namespace + "." + type.Name).Replace('.', '/');
558  var extraTextures = new Dictionary<MountTextureType, string>();
559  foreach (MountTextureType textureType in Enum.GetValues(typeof(MountTextureType))) {
560  extraTextures[textureType] = texture + "_" + textureType.ToString();
561  }
562  if (mount.Autoload(ref name, ref texture, extraTextures)) {
563  AddMount(name, mount, texture, extraTextures);
564  }
565  }
void AddMount(string name, ModMountData mount, string texture, IDictionary< MountTextureType, string > extraTextures=null)
Adds the given mount to the game with the given name and texture. The extraTextures dictionary should...
Definition: Mod.cs:994
MountTextureType
This is an enum of all possible types of extra mount textures for custom mounts. Use these as keys in...
void Terraria.ModLoader.Mod.AutoloadNPC ( Type  type)
private

Definition at line 497 of file ModInternals.cs.

References Terraria.ModLoader.ModNPC.Autoload(), Terraria.ModLoader.ModNPC.BossHeadTexture, Terraria.ModLoader.ModNPC.HeadTexture, Terraria.ModLoader.ModNPC.mod, Terraria.ModLoader.Mod.Name, and Terraria.ModLoader.ModNPC.npc.

497  {
498  ModNPC npc = (ModNPC)Activator.CreateInstance(type);
499  npc.mod = this;
500  string name = type.Name;
501  if (npc.Autoload(ref name)) {
502  AddNPC(name, npc);
503  var autoloadHead = type.GetAttribute<AutoloadHead>();
504  if (autoloadHead != null) {
505  string headTexture = npc.HeadTexture;
506  AddNPCHeadTexture(npc.npc.type, headTexture);
507  }
508  var autoloadBossHead = type.GetAttribute<AutoloadBossHead>();
509  if (autoloadBossHead != null) {
510  string headTexture = npc.BossHeadTexture;
511  AddBossHeadTexture(headTexture, npc.npc.type);
512  }
513  }
514  }
void AddNPCHeadTexture(int npcType, string texture)
Assigns a head texture to the given town NPC type.
Definition: Mod.cs:859
void AddNPC(string name, ModNPC npc)
Adds a type of NPC to the game with the specified name and texture. Also allows you to give the NPC a...
Definition: Mod.cs:779
void AddBossHeadTexture(string texture, int npcType=-1)
Assigns a head texture that can be used by NPCs on the map.
Definition: Mod.cs:881

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AutoloadPlayer ( Type  type)
private

Definition at line 525 of file ModInternals.cs.

References Terraria.ModLoader.ModPlayer.Autoload(), Terraria.ModLoader.ModPlayer.mod, and Terraria.ModLoader.Mod.Name.

525  {
526  ModPlayer player = (ModPlayer)Activator.CreateInstance(type);
527  player.mod = this;
528  string name = type.Name;
529  if (player.Autoload(ref name)) {
530  AddPlayer(name, player);
531  }
532  }
void AddPlayer(string name, ModPlayer player)
Adds a type of ModPlayer to this mod. All ModPlayer types will be newly created and attached to each ...
Definition: Mod.cs:898

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AutoloadPrefix ( Type  type)
private

Definition at line 413 of file ModInternals.cs.

References Terraria.ModLoader.ModPrefix.Autoload(), Terraria.ModLoader.ModPrefix.mod, and Terraria.ModLoader.Mod.Name.

413  {
414  ModPrefix prefix = (ModPrefix)Activator.CreateInstance(type);
415  prefix.mod = this;
416  string name = type.Name;
417  if (prefix.Autoload(ref name)) {
418  AddPrefix(name, prefix);
419  }
420  }
void AddPrefix(string name, ModPrefix prefix)
Adds a prefix to your mod with the specified internal name. This method should be called in Load...
Definition: Mod.cs:410

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AutoloadProjectile ( Type  type)
private

Definition at line 479 of file ModInternals.cs.

References Terraria.ModLoader.ModProjectile.Autoload(), Terraria.ModLoader.ModProjectile.mod, and Terraria.ModLoader.Mod.Name.

479  {
480  ModProjectile projectile = (ModProjectile)Activator.CreateInstance(type);
481  projectile.mod = this;
482  string name = type.Name;
483  if (projectile.Autoload(ref name)) {
484  AddProjectile(name, projectile);
485  }
486  }
void AddProjectile(string name, ModProjectile projectile)
Adds a type of projectile to the game with the specified name.
Definition: Mod.cs:700

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AutoloadSounds ( IList< Type >  modSounds)
private

Definition at line 642 of file ModInternals.cs.

642  {
643  var modSoundNames = modSounds.ToDictionary(t => t.Namespace + "." + t.Name);
644  foreach (var sound in sounds.Keys.Where(t => t.StartsWith("Sounds/"))) {
645  string substring = sound.Substring("Sounds/".Length);
646  SoundType soundType = SoundType.Custom;
647  if (substring.StartsWith("Item/")) {
648  soundType = SoundType.Item;
649  }
650  else if (substring.StartsWith("NPCHit/")) {
651  soundType = SoundType.NPCHit;
652  }
653  else if (substring.StartsWith("NPCKilled/")) {
654  soundType = SoundType.NPCKilled;
655  }
656  ModSound modSound = null;
657  Type t;
658  if (modSoundNames.TryGetValue((Name + '/' + sound).Replace('/', '.'), out t))
659  modSound = (ModSound)Activator.CreateInstance(t);
660 
661  AddSound(soundType, Name + '/' + sound, modSound);
662  }
663  foreach (var music in musics.Keys.Where(t => t.StartsWith("Sounds/"))) {
664  string substring = music.Substring("Sounds/".Length);
665  if (substring.StartsWith("Music/")) {
666  AddSound(SoundType.Music, Name + '/' + music);
667  }
668  }
669  }
SoundType
This is an enum of the types of sound you can add to the game. This is used for determining whether a...
Definition: SoundType.cs:12
virtual string Name
Stores the name of the mod. This name serves as the mod&#39;s identification, and also helps with saving ...
Definition: Mod.cs:45
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 play...
Definition: Mod.cs:1289
void Terraria.ModLoader.Mod.AutoloadSurfaceBgStyle ( Type  type)
private

Definition at line 591 of file ModInternals.cs.

References Terraria.ModLoader.ModSurfaceBgStyle.Autoload(), Terraria.ModLoader.ModSurfaceBgStyle.mod, and Terraria.ModLoader.Mod.Name.

591  {
592  ModSurfaceBgStyle surfaceBgStyle = (ModSurfaceBgStyle)Activator.CreateInstance(type);
593  surfaceBgStyle.mod = this;
594  string name = type.Name;
595  if (surfaceBgStyle.Autoload(ref name)) {
596  AddSurfaceBgStyle(name, surfaceBgStyle);
597  }
598  }
void AddSurfaceBgStyle(string name, ModSurfaceBgStyle surfaceBgStyle)
Adds the given surface background style with the given name to this mod.
Definition: Mod.cs:1131

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AutoloadTile ( Type  type)
private

Definition at line 432 of file ModInternals.cs.

References Terraria.ModLoader.ModTile.Autoload(), Terraria.ModLoader.ModTile.mod, and Terraria.ModLoader.Mod.Name.

432  {
433  ModTile tile = (ModTile)Activator.CreateInstance(type);
434  tile.mod = this;
435  string name = type.Name;
436  string texture = (type.Namespace + "." + type.Name).Replace('.', '/');
437  if (tile.Autoload(ref name, ref texture)) {
438  AddTile(name, tile, texture);
439  }
440  }
void AddTile(string name, ModTile tile, string texture)
Adds a type of tile to the game with the specified name and texture.
Definition: Mod.cs:508

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AutoloadTileEntity ( Type  type)
private

Definition at line 451 of file ModInternals.cs.

References Terraria.ModLoader.ModTileEntity.Autoload(), Terraria.ModLoader.ModTileEntity.mod, and Terraria.ModLoader.Mod.Name.

451  {
452  ModTileEntity tileEntity = (ModTileEntity)Activator.CreateInstance(type);
453  tileEntity.mod = this;
454  string name = type.Name;
455  if (tileEntity.Autoload(ref name)) {
456  AddTileEntity(name, tileEntity);
457  }
458  }
void AddTileEntity(string name, ModTileEntity entity)
Manually add a tile entity during Load.
Definition: Mod.cs:585

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AutoloadUgBgStyle ( Type  type)
private

Definition at line 582 of file ModInternals.cs.

References Terraria.ModLoader.ModUgBgStyle.Autoload(), Terraria.ModLoader.ModUgBgStyle.mod, and Terraria.ModLoader.Mod.Name.

582  {
583  ModUgBgStyle ugBgStyle = (ModUgBgStyle)Activator.CreateInstance(type);
584  ugBgStyle.mod = this;
585  string name = type.Name;
586  if (ugBgStyle.Autoload(ref name)) {
587  AddUgBgStyle(name, ugBgStyle);
588  }
589  }
void AddUgBgStyle(string name, ModUgBgStyle ugBgStyle)
Adds the given underground background style with the given name to this mod.
Definition: Mod.cs:1105

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AutoloadWall ( Type  type)
private

Definition at line 460 of file ModInternals.cs.

References Terraria.ModLoader.ModWall.Autoload(), Terraria.ModLoader.ModWall.mod, and Terraria.ModLoader.Mod.Name.

460  {
461  ModWall wall = (ModWall)Activator.CreateInstance(type);
462  wall.mod = this;
463  string name = type.Name;
464  string texture = (type.Namespace + "." + type.Name).Replace('.', '/');
465  if (wall.Autoload(ref name, ref texture)) {
466  AddWall(name, wall, texture);
467  }
468  }
void AddWall(string name, ModWall wall, string texture)
Adds a type of wall to the game with the specified name and texture.
Definition: Mod.cs:634

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AutoloadWaterfallStyle ( Type  type)
private

Definition at line 620 of file ModInternals.cs.

References Terraria.ModLoader.ModWaterfallStyle.Autoload(), Terraria.ModLoader.ModWaterfallStyle.mod, and Terraria.ModLoader.Mod.Name.

620  {
621  ModWaterfallStyle waterfallStyle = (ModWaterfallStyle)Activator.CreateInstance(type);
622  waterfallStyle.mod = this;
623  string name = type.Name;
624  string texture = (type.Namespace + "." + type.Name).Replace('.', '/');
625  if (waterfallStyle.Autoload(ref name, ref texture)) {
626  AddWaterfallStyle(name, waterfallStyle, texture);
627  }
628  }
void AddWaterfallStyle(string name, ModWaterfallStyle waterfallStyle, string texture)
Adds the given waterfall style to the game with the given name and texture path.
Definition: Mod.cs:1222

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.AutoloadWaterStyle ( Type  type)
private

Definition at line 609 of file ModInternals.cs.

References Terraria.ModLoader.ModWaterStyle.Autoload(), Terraria.ModLoader.ModWaterStyle.mod, and Terraria.ModLoader.Mod.Name.

609  {
610  ModWaterStyle waterStyle = (ModWaterStyle)Activator.CreateInstance(type);
611  waterStyle.mod = this;
612  string name = type.Name;
613  string texture = (type.Namespace + "." + type.Name).Replace('.', '/');
614  string blockTexture = texture + "_Block";
615  if (waterStyle.Autoload(ref name, ref texture, ref blockTexture)) {
616  AddWaterStyle(name, waterStyle, texture, blockTexture);
617  }
618  }
void AddWaterStyle(string name, ModWaterStyle waterStyle, string texture, string blockTexture)
Adds the given water style to the game with the given name, texture path, and block texture path...
Definition: Mod.cs:1193

+ Here is the call graph for this function:

int Terraria.ModLoader.Mod.BuffType ( string  name)

Gets the type of the ModBuff of this mod corresponding to the given name. Returns 0 if no ModBuff with the given name is found.

Parameters
nameThe name.
Returns

Same as the other BuffType, but assumes that the class name and internal name are the same.

Template Parameters
T
Returns
Type Constraints
T :ModBuff 
T :BuffType 
T :typeof 
T :T 
T :Name 
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.

Definition at line 1602 of file Mod.cs.

1602  {
1603  return null;
1604  }
ModTranslation Terraria.ModLoader.Mod.CreateTranslation ( string  key)

Creates a ModTranslation object that you can use in AddTranslation.

Parameters
keyThe key for the ModTranslation. The full key will be Mods.ModName.key
int Terraria.ModLoader.Mod.DustType ( string  name)

Gets the type of the ModDust of this mod with the given name. Returns 0 if no ModDust with the given name is found.

Parameters
nameThe name.
Returns

Same as the other DustType, but assumes that the class name and internal name are the same.

Template Parameters
T
Returns
Type Constraints
T :ModDust 
T :DustType 
T :typeof 
T :T 
T :Name 
bool Terraria.ModLoader.Mod.EffectExists ( string  name)

Used to check if a custom Effect exists

bool Terraria.ModLoader.Mod.FileExists ( string  name)

Shorthand for calling ModLoader.FileExists(this.FileName(name)). Note that file extensions are used here.

Parameters
nameThe name.
Returns

Referenced by Terraria.ModLoader.ModContent.FileExists().

+ Here is the caller graph for this function:

bool Terraria.ModLoader.Mod.FontExists ( string  name)

Used to check if a custom SpriteFont exists

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
int Terraria.ModLoader.Mod.GetBackgroundSlot ( string  name)

Gets the texture slot corresponding to the specified texture name. Shorthand for calling BackgroundTextureLoader.GetBackgroundSlot(this.Name + '/' + name).

Parameters
nameThe name.
Returns
ModBuff Terraria.ModLoader.Mod.GetBuff ( string  name)

Gets the ModBuff of this mod corresponding to the given name. Returns null if no ModBuff with the given name is found.

Parameters
nameThe name.
Returns
Type Constraints
T :ModBuff 
T :T 
T :GetBuff 
T :typeof 
T :T 
T :Name 
ModConfig Terraria.ModLoader.Mod.GetConfig ( string  name)

Definition at line 1626 of file Mod.cs.

1627  {
1628  List<ModConfig> configs;
1629  if (ConfigManager.Configs.TryGetValue(this, out configs))
1630  {
1631  return configs.Single(x => x.Name == name);
1632  }
1633  return null;
1634  }
Type Constraints
T :ModConfig 
T :T 
T :GetConfig 
T :typeof 
T :T 
T :Name 
ModDust Terraria.ModLoader.Mod.GetDust ( string  name)

Gets the ModDust of this mod corresponding to the given name. Returns null if no ModDust with the given name is found.

Parameters
nameThe name.
Returns

Same as the other GetDust, but assumes that the class name and internal name are the same.

Template Parameters
T
Returns
Type Constraints
T :ModDust 
T :T 
T :GetDust 
T :typeof 
T :T 
T :Name 
Effect Terraria.ModLoader.Mod.GetEffect ( string  name)

Gets an Effect loaded from the specified path.

Exceptions
MissingResourceException

Definition at line 1587 of file Mod.cs.

1587  {
1588  if (!effects.TryGetValue(name, out var effect))
1589  throw new MissingResourceException(name);
1590 
1591  return effect;
1592  }
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
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
byte [] Terraria.ModLoader.Mod.GetFileBytes ( string  name)

Retrieve contents of files within the tmod file

Parameters
nameThe name.
Returns

Referenced by Terraria.ModLoader.ModContent.GetFileBytes().

+ Here is the caller graph for this function:

Stream Terraria.ModLoader.Mod.GetFileSteam ( string  name)

Retrieve contents of files within the tmod file

Parameters
nameThe name.
Returns
DynamicSpriteFont Terraria.ModLoader.Mod.GetFont ( string  name)

Gets a SpriteFont loaded from the specified path.

Exceptions
MissingResourceException

Definition at line 1571 of file Mod.cs.

1571  {
1572  if (!fonts.TryGetValue(name, out var font))
1573  throw new MissingResourceException(name);
1574 
1575  return font;
1576  }
GlobalBgStyle Terraria.ModLoader.Mod.GetGlobalBgStyle ( string  name)

Returns the global background style corresponding to the given name.

Parameters
nameThe name.
Returns
Type Constraints
T :GlobalBgStyle 
T :T 
T :GetGlobalBgStyle 
T :typeof 
T :T 
T :Name 
GlobalBuff Terraria.ModLoader.Mod.GetGlobalBuff ( string  name)

Gets the GlobalBuff with the given name from this mod.

Parameters
nameThe name.
Returns
Type Constraints
T :GlobalBuff 
T :T 
T :GetGlobalBuff 
T :typeof 
T :T 
T :Name 
GlobalItem Terraria.ModLoader.Mod.GetGlobalItem ( string  name)

Gets the GlobalItem instance with the given name from this mod.

Parameters
nameThe name.
Returns

Referenced by Terraria.ModLoader.IO.ItemIO.Load(), and Terraria.ModLoader.IO.ItemIO.LoadLegacy().

+ Here is the caller graph for this function:

Same as the other GetGlobalItem, but assumes that the class name and internal name are the same.

Template Parameters
T
Returns
Type Constraints
T :GlobalItem 
T :T 
T :GetGlobalItem 
T :typeof 
T :T 
T :Name 
GlobalNPC Terraria.ModLoader.Mod.GetGlobalNPC ( string  name)

Gets the GlobalNPC instance with the given name from this mod.

Parameters
nameThe name.
Returns
Type Constraints
T :GlobalNPC 
T :T 
T :GetGlobalNPC 
T :typeof 
T :T 
T :Name 
GlobalProjectile Terraria.ModLoader.Mod.GetGlobalProjectile ( string  name)

Gets the GlobalProjectile instance with the given name from this mod.

Parameters
nameThe name.
Returns
Type Constraints
T :GlobalProjectile 
T :T 
T :GetGlobalProjectile 
T :typeof 
T :T 
T :Name 
GlobalRecipe Terraria.ModLoader.Mod.GetGlobalRecipe ( string  name)

Gets the global recipe corresponding to the specified name.

Parameters
nameThe name.
Returns
Type Constraints
T :GlobalRecipe 
T :T 
T :GetGlobalRecipe 
T :typeof 
T :T 
T :Name 
GlobalTile Terraria.ModLoader.Mod.GetGlobalTile ( string  name)

Gets the GlobalTile instance with the given name from this mod.

Parameters
nameThe name.
Returns

Same as the other GetGlobalTile, but assumes that the class name and internal name are the same.

Template Parameters
T
Returns
Type Constraints
T :GlobalTile 
T :T 
T :GetGlobalTile 
T :typeof 
T :T 
T :Name 
GlobalWall Terraria.ModLoader.Mod.GetGlobalWall ( string  name)

Gets the GlobalWall instance with the given name from this mod.

Parameters
nameThe name.
Returns
Type Constraints
T :GlobalWall 
T :T 
T :GetGlobalWall 
T :typeof 
T :T 
T :Name 
int Terraria.ModLoader.Mod.GetGoreSlot ( string  name)

Shorthand for calling ModGore.GetGoreSlot(this.Name + '/' + name).

Parameters
nameThe name.
Returns

Same as the other GetGoreSlot, but assumes that the class name and internal name are the same.

Template Parameters
T
Returns
Type Constraints
T :ModGore 
T :GetGoreSlot 
T :typeof 
T :T 
T :Name 
ModItem Terraria.ModLoader.Mod.GetItem ( string  name)

Gets the ModItem instance corresponding to the name. Because this method is in the Mod class, conflicts between mods are avoided. Returns null if no ModItem with the given name is found.

Parameters
nameThe name.
Returns

Referenced by Terraria.ModLoader.Config.ItemDefinition.GetID().

+ Here is the caller graph for this function:

Same as the other GetItem, but assumes that the class name and internal name are the same.

Template Parameters
T
Returns
Type Constraints
T :ModItem 
T :T 
T :GetItem 
T :typeof 
T :T 
T :Name 
LegacySoundStyle Terraria.ModLoader.Mod.GetLegacySoundSlot ( SoundType  type,
string  name 
)

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

Parameters
typeThe type.
nameThe name.
Returns
ModWorld Terraria.ModLoader.Mod.GetModWorld ( string  name)

Gets the ModWorld instance with the given name from this mod.

Parameters
nameThe name.
Returns

Same as the other GetModWorld, but assumes that the class name and internal name are the same.

Template Parameters
T
Returns
Type Constraints
T :ModWorld 
T :T 
T :GetModWorld 
T :typeof 
T :T 
T :Name 
ModMountData Terraria.ModLoader.Mod.GetMount ( string  name)

Gets the ModMountData instance of this mod corresponding to the given name. Returns null if no ModMountData has the given name.

Parameters
nameThe name.
Returns
Type Constraints
T :ModMountData 
T :T 
T :GetMount 
T :typeof 
T :T 
T :Name 
Music Terraria.ModLoader.Mod.GetMusic ( string  name)

Shorthand for calling ModContent.GetMusic(this.FileName(name)).

Parameters
nameThe name.
Returns
Exceptions
MissingResourceException

Definition at line 1553 of file Mod.cs.

References Terraria.ModLoader.Music.

Referenced by Terraria.ModLoader.ModContent.GetMusic().

1553  {
1554  if (!musics.TryGetValue(name, out var sound))
1555  throw new MissingResourceException(name);
1556 
1557  return sound.GetInstance();
1558  }

+ Here is the caller graph for this function:

ModNPC Terraria.ModLoader.Mod.GetNPC ( string  name)

Gets the ModNPC of this mod corresponding to the given name. Returns null if no ModNPC with the given name is found.

Parameters
nameThe name.
Returns
Type Constraints
T :ModNPC 
T :T 
T :GetNPC 
T :typeof 
T :T 
T :Name 
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

Definition at line 1612 of file Mod.cs.

References Terraria.ModLoader.ModNet.NetModCount.

1612  {
1613  if (netID < 0)
1614  throw new Exception("Cannot get packet for " + Name + " because it does not exist on the other side");
1615 
1616  var p = new ModPacket(MessageID.ModPacket, capacity + 5);
1617  if (ModNet.NetModCount < 256)
1618  p.Write((byte)netID);
1619  else
1620  p.Write(netID);
1621 
1622  p.netID = netID;
1623  return p;
1624  }
virtual string Name
Stores the name of the mod. This name serves as the mod&#39;s identification, and also helps with saving ...
Definition: Mod.cs:45
ModPlayer Terraria.ModLoader.Mod.GetPlayer ( string  name)

Gets the ModPlayer of this mod corresponding to the given name. Returns null if no ModPlayer with the given name is found.

Parameters
nameThe name.
Returns
Type Constraints
T :ModPlayer 
T :T 
T :GetPlayer 
T :typeof 
T :T 
T :Name 
ModPrefix Terraria.ModLoader.Mod.GetPrefix ( string  name)

Gets the ModPrefix instance corresponding to the name. Because this method is in the Mod class, conflicts between mods are avoided. Returns null if no ModPrefix with the given name is found.

Parameters
nameThe name.
Returns

Same as the other GetPrefix, but assumes that the class name and internal name are the same.

Template Parameters
T
Returns
Type Constraints
T :ModPrefix 
T :T 
T :GetPrefix 
T :typeof 
T :T 
T :Name 
ModProjectile Terraria.ModLoader.Mod.GetProjectile ( string  name)

Gets the ModProjectile of this mod corresponding to the given name. Returns null if no ModProjectile with the given name is found.

Parameters
nameThe name.
Returns
Type Constraints
T :ModProjectile 
T :T 
T :GetProjectile 
T :typeof 
T :T 
T :Name 
SoundEffect Terraria.ModLoader.Mod.GetSound ( string  name)

Shorthand for calling ModContent.GetSound(this.FileName(name)).

Parameters
nameThe name.
Returns
Exceptions
MissingResourceException

Definition at line 1533 of file Mod.cs.

Referenced by Terraria.ModLoader.ModContent.GetSound().

1533  {
1534  if (!sounds.TryGetValue(name, out var sound))
1535  throw new MissingResourceException(name);
1536 
1537  return sound;
1538  }

+ Here is the caller graph for this function:

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

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

Parameters
typeThe type.
nameThe name.
Returns
ModSurfaceBgStyle Terraria.ModLoader.Mod.GetSurfaceBgStyle ( string  name)

Returns the surface background style corresponding to the given name.

Parameters
nameThe name.
Returns
Type Constraints
T :ModSurfaceBgStyle 
T :T 
T :GetSurfaceBgStyle 
T :typeof 
T :T 
T :Name 
int Terraria.ModLoader.Mod.GetSurfaceBgStyleSlot ( string  name)

Returns the Slot of the surface background style corresponding to the given name.

Parameters
nameThe name.
Returns
Type Constraints
T :ModSurfaceBgStyle 
T :GetSurfaceBgStyleSlot 
T :typeof 
T :T 
T :Name 
Texture2D Terraria.ModLoader.Mod.GetTexture ( string  name)

Shorthand for calling ModContent.GetTexture(this.FileName(name)).

Exceptions
MissingResourceException

Definition at line 1500 of file Mod.cs.

1500  {
1501  if (!textures.TryGetValue(name, out var t))
1502  throw new MissingResourceException(name, textures.Keys);
1503 
1504  return t;
1505  }
ModTile Terraria.ModLoader.Mod.GetTile ( string  name)

Gets the ModTile of this mod corresponding to the given name. Returns null if no ModTile with the given name is found.

Parameters
nameThe name.
Returns

Same as the other GetTile, but assumes that the class name and internal name are the same.

Template Parameters
T
Returns
Type Constraints
T :ModTile 
T :T 
T :GetTile 
T :typeof 
T :T 
T :Name 
ModTileEntity Terraria.ModLoader.Mod.GetTileEntity ( string  name)

Gets the ModTileEntity of this mod corresponding to the given name. Returns null if no ModTileEntity with the given name is found.

Parameters
nameThe name.
Returns

Same as the other GetTileEntity, but assumes that the class name and internal name are the same.

Template Parameters
T
Returns
Type Constraints
T :ModTileEntity 
T :T 
T :GetTileEntity 
T :typeof 
T :T 
T :Name 
ModUgBgStyle Terraria.ModLoader.Mod.GetUgBgStyle ( string  name)

Returns the underground background style corresponding to the given name.

Parameters
nameThe name.
Returns
Type Constraints
T :ModUgBgStyle 
T :T 
T :GetUgBgStyle 
T :typeof 
T :T 
T :Name 
ModWall Terraria.ModLoader.Mod.GetWall ( string  name)

Gets the ModWall of this mod corresponding to the given name. Returns null if no ModWall with the given name is found.

Parameters
nameThe name.
Returns
Type Constraints
T :ModWall 
T :T 
T :GetWall 
T :typeof 
T :T 
T :Name 
ModWaterfallStyle Terraria.ModLoader.Mod.GetWaterfallStyle ( string  name)

Returns the waterfall style with the given name from this mod.

Parameters
nameThe name.
Returns
Type Constraints
T :ModWaterfallStyle 
T :T 
T :GetWaterfallStyle 
T :typeof 
T :T 
T :Name 
int Terraria.ModLoader.Mod.GetWaterfallStyleSlot ( string  name)

Returns the waterfall style corresponding to the given name.

Parameters
nameThe name.
Returns
Type Constraints
T :ModWaterfallStyle 
T :GetWaterfallStyleSlot 
T :typeof 
T :T 
T :Name 
ModWaterStyle Terraria.ModLoader.Mod.GetWaterStyle ( string  name)

Returns the water style with the given name from this mod.

Parameters
nameThe name.
Returns
Type Constraints
T :ModWaterStyle 
T :T 
T :GetWaterStyle 
T :typeof 
T :T 
T :Name 
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.

Definition at line 44 of file ModHooks.cs.

44  {
45  }
virtual bool Terraria.ModLoader.Mod.HijackGetData ( ref byte  messageType,
ref BinaryReader  reader,
int  playerNumber 
)
virtual

Allows you to modify net message / packet information that is received before the game can act on it.

Parameters
messageTypeType of the message.
readerThe reader.
playerNumberThe player number the message is from.
Returns

Definition at line 54 of file ModHooks.cs.

54  {
55  return false;
56  }
virtual bool Terraria.ModLoader.Mod.HijackSendData ( int  whoAmI,
int  msgType,
int  remoteClient,
int  ignoreClient,
NetworkText  text,
int  number,
float  number2,
float  number3,
float  number4,
int  number5,
int  number6,
int  number7 
)
virtual

Hijacks the send data method. Only use if you absolutely know what you are doing. If any hooks return true, the message is not sent.

Definition at line 61 of file ModHooks.cs.

Referenced by Terraria.ModLoader.ModNet.ReadNetIDs().

61  {
62  return false;
63  }

+ Here is the caller graph for this function:

virtual void Terraria.ModLoader.Mod.HotKeyPressed ( string  name)
virtual

Called when a hotkey is pressed. Check against the name to verify particular hotkey that was pressed. (Using the ModHotKey is more recommended.)

Parameters
nameThe display name of the hotkey.

Definition at line 36 of file ModHooks.cs.

36  {
37  }
int Terraria.ModLoader.Mod.ItemType ( string  name)

Gets the internal ID / type of the ModItem corresponding to the name. Returns 0 if no ModItem with the given name is found.

Parameters
nameThe name.
Returns

Referenced by Terraria.ModLoader.ModRecipe.AddIngredient(), Terraria.ModLoader.IO.ItemIO.Load(), Terraria.ModLoader.IO.ItemIO.LoadLegacy(), Terraria.ModLoader.ModRecipe.SetResult(), and Terraria.ModLoader.PlayerHooks.SetStartInventory().

+ Here is the caller graph for this function:

Same as the other ItemType, but assumes that the class name and internal name are the same.

Template Parameters
T
Returns
Type Constraints
T :ModItem 
T :ItemType 
T :typeof 
T :T 
T :Name 
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.

Definition at line 72 of file Mod.cs.

Referenced by Terraria.ModLoader.ModContent.SetLocalizedText().

72  {
73  }

+ Here is the caller graph for this function:

void Terraria.ModLoader.Mod.LoadEffect ( string  path,
BinaryReader  br 
)
private

Definition at line 135 of file ModInternals.cs.

References Terraria.ModLoader.ModPrefix.AutoDefaults(), Terraria.ModLoader.ModProjectile.AutoStaticDefaults(), Terraria.ModLoader.ModItem.AutoStaticDefaults(), Terraria.ModLoader.ModNPC.AutoStaticDefaults(), Terraria.ModLoader.ModTile.chest, Terraria.ModLoader.ModContent.GetTexture(), Terraria.ModLoader.ModTile.HighlightTexture, Terraria.ModLoader.ModItem.item, Terraria.ModLoader.ModMountData.mountData, Terraria.ModLoader.ModNPC.npc, Terraria.ModLoader.ModProjectile.projectile, Terraria.ModLoader.GlobalWall.SetDefaults(), Terraria.ModLoader.ModBuff.SetDefaults(), Terraria.ModLoader.GlobalTile.SetDefaults(), Terraria.ModLoader.ModDust.SetDefaults(), Terraria.ModLoader.ModWall.SetDefaults(), Terraria.ModLoader.ModPrefix.SetDefaults(), Terraria.ModLoader.ModProjectile.SetStaticDefaults(), Terraria.ModLoader.ModItem.SetStaticDefaults(), Terraria.ModLoader.ModNPC.SetStaticDefaults(), Terraria.ModLoader.ModBuff.Type, Terraria.ModLoader.ModWaterStyle.Type, Terraria.ModLoader.ModMountData.Type, Terraria.ModLoader.ModTile.Type, Terraria.ModLoader.ModWall.Type, and Terraria.ModLoader.ModWaterfallStyle.Type.

135  {
136  try {
137  char x = (char)br.ReadByte();//x
138  char n = (char)br.ReadByte();//n
139  char b = (char)br.ReadByte();//b
140  char w = (char)br.ReadByte();//w
141  byte xnbFormatVersion = br.ReadByte();//5
142  byte flags = br.ReadByte();//flags
143  UInt32 compressedDataSize = br.ReadUInt32();
144  if ((flags & 0x80) != 0) {
145  // TODO: figure out the compression used.
146  throw new Exception(Language.GetTextValue("tModLoader.LoadErrorCannotLoadCompressedEffects"));
147  //UInt32 decompressedDataSize = br.ReadUInt32();
148  }
149  int typeReaderCount = br.ReadVarInt();
150  string typeReaderName = br.ReadString();
151  int typeReaderVersion = br.ReadInt32();
152  int sharedResourceCount = br.ReadVarInt();
153  int typeid = br.ReadVarInt();
154  UInt32 size = br.ReadUInt32();
155  byte[] effectBytecode = br.ReadBytes((int)size);
156  effects[path] = new Effect(Main.instance.GraphicsDevice, effectBytecode);
157  }
158  catch (Exception e) {
159  throw new ResourceLoadException(Language.GetTextValue("tModLoader.LoadErrorEffectFailedToLoad", path), e);
160  }
161  }

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.LoadFont ( string  path,
byte[]  data 
)
private

Definition at line 120 of file ModInternals.cs.

120  {
121  string fontFilenameNoExtension = Name + "_" + path.Replace('/', '_') + "_" + Version;
122  string fontFilename = fontFilenameNoExtension + ".xnb";
123  FontCacheIO.DeleteIfOlder(File.path, fontFilename);
124  if (!FontCacheIO.FontCacheAvailable(fontFilename)) {
125  FileUtilities.WriteAllBytes(FontCacheIO.FontCachePath + Path.DirectorySeparatorChar + fontFilename, data, false);
126  }
127  try {
128  fonts[path] = Main.instance.OurLoad<DynamicSpriteFont>("Fonts" + Path.DirectorySeparatorChar + "ModFonts" + Path.DirectorySeparatorChar + fontFilenameNoExtension);
129  }
130  catch (Exception e) {
131  throw new ResourceLoadException(Language.GetTextValue("tModLoader.LoadErrorFontFailedToLoad", path), e);
132  }
133  }
TmodFile File
The TmodFile object created when tModLoader reads this mod.
Definition: Mod.cs:32
virtual Version Version
This version number of this mod.
Definition: Mod.cs:53
virtual string Name
Stores the name of the mod. This name serves as the mod&#39;s identification, and also helps with saving ...
Definition: Mod.cs:45
void Terraria.ModLoader.Mod.LoadMP3 ( string  path,
byte[]  bytes 
)
private

Definition at line 93 of file ModInternals.cs.

93  {
94  string wavCacheFilename = this.Name + "_" + path.Replace('/', '_') + "_" + Version + ".wav";
95  WAVCacheIO.DeleteIfOlder(File.path, wavCacheFilename);
96  try {
97  if (path.StartsWith("Sounds/Music/")) {
98  if (ModLoader.musicStreamMode != 1) {//no cache
99  musics[path] = new MusicData(bytes, true);
100  return;
101  }
102 
103  if (!WAVCacheIO.WAVCacheAvailable(wavCacheFilename)) {
104  WAVCacheIO.CacheMP3(wavCacheFilename, new MemoryStream(bytes));
105  }
106 
107  musics[path] = new MusicData(Path.Combine(WAVCacheIO.ModCachePath, wavCacheFilename));
108  return;
109  }
110 
111  sounds[path] = WAVCacheIO.WAVCacheAvailable(wavCacheFilename) ?
112  SoundEffect.FromStream(WAVCacheIO.GetWavStream(wavCacheFilename)) :
113  WAVCacheIO.CacheMP3(wavCacheFilename, new MemoryStream(bytes));
114  }
115  catch (Exception e) {
116  throw new ResourceLoadException(Language.GetTextValue("tModLoader.LoadErrorMP3SoundFailedToLoad", path) + (Main.engine == null ? "\n" + Language.GetTextValue("tModLoader.LoadErrorSoundFailedToLoadAudioDeviceHint") : ""), e);
117  }
118  }
TmodFile File
The TmodFile object created when tModLoader reads this mod.
Definition: Mod.cs:32
virtual Version Version
This version number of this mod.
Definition: Mod.cs:53
virtual string Name
Stores the name of the mod. This name serves as the mod&#39;s identification, and also helps with saving ...
Definition: Mod.cs:45
virtual bool Terraria.ModLoader.Mod.LoadResource ( string  path,
int  length,
Func< Stream >  getStream 
)
virtual

Hook for pre-loading resources

Parameters
pathThe path of the resource within the tmod
lengthThe length of the uncompressed resource
getStreamA function which returns a stream containing the file content
Returns
true if the file will no-longer be needed and should not be cached

Definition at line 135 of file Mod.cs.

135  {
136  if (tModLoaderVersion < new Version(0, 11) && LoadResourceLegacy(path, length, getStream))
137  return false;
138 
139  string extension = Path.GetExtension(path);
140  path = Path.ChangeExtension(path, null);
141  switch (extension) {
142  case ".png":
143  case ".rawimg":
144  if (!Main.dedServ)
145  LoadTexture(path, getStream(), extension == ".rawimg");
146  return true;
147  case ".wav":
148  if (!Main.dedServ)
149  LoadWav(path, getStream().ReadBytes(length));
150  return true;
151  case ".mp3":
152  if (!Main.dedServ)
153  LoadMP3(path, getStream().ReadBytes(length));
154  return true;
155  case ".xnb":
156  if (Main.dedServ) { }
157  else if (path.StartsWith("Fonts/"))
158  LoadFont(path, getStream().ReadBytes(length));
159  else if (path.StartsWith("Effects/"))
160  LoadEffect(path, new BinaryReader(getStream()));
161  else
162  throw new ResourceLoadException(Language.GetTextValue("tModLoader.LoadErrorUnknownXNBFileHint", path));
163  return true;
164  }
165 
166  return false;
167  }
void LoadFont(string path, byte[] data)
virtual Version Version
This version number of this mod.
Definition: Mod.cs:53
bool LoadResourceLegacy(string path, int length, Func< Stream > getStream)
Definition: Mod.cs:170
void LoadTexture(string path, Stream stream, bool rawimg)
Definition: ModInternals.cs:57
void LoadWav(string path, byte[] bytes)
Definition: ModInternals.cs:78
void LoadMP3(string path, byte[] bytes)
Definition: ModInternals.cs:93
Version tModLoaderVersion
The version of tModLoader that was being used when this mod was built.
Definition: Mod.cs:49
void LoadEffect(string path, BinaryReader br)
virtual void Terraria.ModLoader.Mod.LoadResourceFromStream ( string  path,
int  len,
BinaryReader  reader 
)
virtual

Definition at line 178 of file Mod.cs.

178  {
179  }
bool Terraria.ModLoader.Mod.LoadResourceLegacy ( string  path,
int  length,
Func< Stream >  getStream 
)
private

Definition at line 170 of file Mod.cs.

170  {
171  using (var stream = getStream()) {
172  LoadResourceFromStream(path, length, new BinaryReader(stream));
173  return stream.Position > 0;
174  }
175  }
virtual void LoadResourceFromStream(string path, int len, BinaryReader reader)
Definition: Mod.cs:178
virtual void Terraria.ModLoader.Mod.LoadResources ( )
virtual

Definition at line 105 of file Mod.cs.

Referenced by Terraria.ModLoader.ModContent.SetLocalizedText().

105  {
106  if (File == null)
107  return;
108 
109  var skipCache = new HashSet<string>();
110  File.EnsureOpen();
111  File.ForEach((path, len, getStream) => {
112  // wrap with a message which updates the UI
113  Stream _stream = null;
114  Stream _getStream() {
115  Interface.loadMods.SubProgressText = path;
116  return _stream = getStream();
117  };
118 
119  if (LoadResource(path, len, _getStream))
120  skipCache.Add(path);
121 
122  // cleanup for them because why not
123  _stream?.Dispose();
124  });
125  File.CacheFiles(skipCache);
126  }
void CacheFiles(ISet< string > skip=null)
Definition: TmodFile.cs:278
void ForEach(EntryIterator iterator)
Definition: TmodFile.cs:146
TmodFile File
The TmodFile object created when tModLoader reads this mod.
Definition: Mod.cs:32
virtual bool LoadResource(string path, int length, Func< Stream > getStream)
Hook for pre-loading resources
Definition: Mod.cs:135

+ Here is the caller graph for this function:

void Terraria.ModLoader.Mod.LoadTexture ( string  path,
Stream  stream,
bool  rawimg 
)
private

Definition at line 57 of file ModInternals.cs.

References Terraria.ModLoader.IO.ImageIO.PngToTexture2DAsync(), and Terraria.ModLoader.IO.ImageIO.RawToTexture2DAsync().

57  {
58  try {
59  var texTask = rawimg
60  ? ImageIO.RawToTexture2DAsync(Main.instance.GraphicsDevice, new BinaryReader(stream))
61  : ImageIO.PngToTexture2DAsync(Main.instance.GraphicsDevice, stream);
62 
63  AsyncLoadQueue.Enqueue(texTask.ContinueWith(t => {
64  var tex = t.Result;
65  tex.Name = Name + "/" + path;
66  lock (textures)
67  textures[path] = tex;
68  }));
69  }
70  catch (Exception e) {
71  throw new ResourceLoadException(Language.GetTextValue("tModLoader.LoadErrorTextureFailedToLoad", path), e);
72  }
73  finally {
74  stream.Close();
75  }
76  }
readonly Queue< Task > AsyncLoadQueue
Definition: ModInternals.cs:23
static Task< Texture2D > RawToTexture2DAsync(GraphicsDevice graphicsDevice, BinaryReader r)
Definition: ImageIO.cs:90
static Task< Texture2D > PngToTexture2DAsync(GraphicsDevice graphicsDevice, Stream stream)
Definition: ImageIO.cs:99

+ Here is the call graph for this function:

void Terraria.ModLoader.Mod.LoadWav ( string  path,
byte[]  bytes 
)
private

Definition at line 78 of file ModInternals.cs.

78  {
79  try {
80  if (path.StartsWith("Sounds/Music/")) {
81  musics[path] = new MusicData(bytes, false);
82  }
83  else {
84  //SoundEffect.FromStream needs a stream with a length
85  sounds[path] = SoundEffect.FromStream(new MemoryStream(bytes));
86  }
87  }
88  catch (Exception e) {
89  throw new ResourceLoadException(Language.GetTextValue("tModLoader.LoadErrorWavSoundFailedToLoad", path) + (Main.engine == null ? "\n" + Language.GetTextValue("tModLoader.LoadErrorSoundFailedToLoadAudioDeviceHint") : ""), e);
90  }
91  }
virtual void Terraria.ModLoader.Mod.MidUpdateDustTime ( )
virtual

Called after Dust got updated, but before Time (day/night, events, etc.) gets updated.

If you are looking to hook an earlier part of the update process, see MidUpdateItemDust. If you are looking to hook a later part of the update process, see MidUpdateTimeWorld.

Definition at line 139 of file ModHooks.cs.

139  {
140  }
virtual void Terraria.ModLoader.Mod.MidUpdateGoreProjectile ( )
virtual

Called after Gores got updated, but before any Projectiles get updated.

If you are looking to hook an earlier part of the update process, see MidUpdateNPCGore. If you are looking to hook a later part of the update process, see MidUpdateProjectileItem.

Definition at line 112 of file ModHooks.cs.

112  {
113  }
virtual void Terraria.ModLoader.Mod.MidUpdateInvasionNet ( )
virtual

Called after Invasions got updated. The only thing that is updated after this is the Network.

If you are looking to hook an earlier part of the update process, see MidUpdateTimeWorld. If you are looking to hook even after the Network is updated, see PostUpdateEverything.

Definition at line 157 of file ModHooks.cs.

157  {
158  }
virtual void Terraria.ModLoader.Mod.MidUpdateItemDust ( )
virtual

Called after Items got updated, but before any Dust gets updated.

If you are looking to hook an earlier part of the update process, see MidUpdateProjectileItem. If you are looking to hook a later part of the update process, see MidUpdateDustTime.

Definition at line 130 of file ModHooks.cs.

130  {
131  }
virtual void Terraria.ModLoader.Mod.MidUpdateNPCGore ( )
virtual

Called after NPCs got updated, but before any Gores get updated.

If you are looking to hook an earlier part of the update process, see MidUpdatePlayerNPC. If you are looking to hook a later part of the update process, see MidUpdateGoreProjectile.

Definition at line 103 of file ModHooks.cs.

103  {
104  }
virtual void Terraria.ModLoader.Mod.MidUpdatePlayerNPC ( )
virtual

Called after Players got updated, but before any NPCs get updated.

If you are looking to hook an earlier part of the update process, see PreUpdateEntities. If you are looking to hook a later part of the update process, see MidUpdateNPCGore.

Definition at line 94 of file ModHooks.cs.

94  {
95  }
virtual void Terraria.ModLoader.Mod.MidUpdateProjectileItem ( )
virtual

Gets called immediately after all Projectiles are updated, but before any Items get updated.

If you are looking to hook an earlier part of the update process, see MidUpdateGoreProjectile. If you are looking to hook a later part of the update process, see MidUpdateItemDust.

Definition at line 121 of file ModHooks.cs.

121  {
122  }
virtual void Terraria.ModLoader.Mod.MidUpdateTimeWorld ( )
virtual

Called after Time got updated, but before the World gets updated.

If you are looking to hook an earlier part of the update process, see MidUpdateDustTime. If you are looking to hook a later part of the update process, see MidUpdateInvasionNet.

Definition at line 148 of file ModHooks.cs.

148  {
149  }
virtual void Terraria.ModLoader.Mod.ModifyInterfaceLayers ( List< GameInterfaceLayer >  layers)
virtual

Allows you to modify the elements of the in-game interface that get drawn. GameInterfaceLayer can be found in the Terraria.UI namespace. Check https://github.com/blushiemagic/tModLoader/wiki/Vanilla-Interface-layers-values for vanilla interface layer names

Parameters
layersThe layers.

Definition at line 172 of file ModHooks.cs.

172  {
173  }
virtual void Terraria.ModLoader.Mod.ModifyLightingBrightness ( ref float  scale)
virtual

Allows you to modify overall brightness of lights. Can be used to create effects similiar to what night vision and darkness (de)buffs give you. Values too high or too low might result in glitches. For night vision effect use scale 1.03

Parameters
scaleBrightness scale

Definition at line 187 of file ModHooks.cs.

187  {
188  }
virtual void Terraria.ModLoader.Mod.ModifySunLightColor ( ref Color  tileColor,
ref Color  backgroundColor 
)
virtual

Allows you to modify color of light the sun emits.

Parameters
tileColorTile lighting color
backgroundColorBackground lighting color

Definition at line 180 of file ModHooks.cs.

180  {
181  }
virtual void Terraria.ModLoader.Mod.ModifyTransformMatrix ( ref SpriteViewMatrix  Transform)
virtual

Allows you to set the transformation of the screen that is drawn. (Translations, rotations, scales, etc.)

Definition at line 68 of file ModHooks.cs.

68  {
69  }
int Terraria.ModLoader.Mod.MountType ( string  name)

Gets the ID of the ModMountData instance corresponding to the given name. Returns 0 if no ModMountData has the given name.

Parameters
nameThe name.
Returns

Same as the other MountType, but assumes that the class name and internal name are the same.

Template Parameters
T
Returns
Type Constraints
T :ModMountData 
T :MountType 
T :typeof 
T :T 
T :Name 
bool Terraria.ModLoader.Mod.MusicExists ( string  name)

Shorthand for calling ModLoader.MusicExists(this.FileName(name)).

Parameters
nameThe name.
Returns

Referenced by Terraria.ModLoader.ModContent.MusicExists().

+ Here is the caller graph for this function:

int Terraria.ModLoader.Mod.NPCType ( string  name)

Gets the type of the ModNPC of this mod with the given name. Returns 0 if no ModNPC with the given name is found.

Parameters
nameThe name.
Returns

Same as the other NPCType, but assumes that the class name and internal name are the same.

Template Parameters
T
Returns
Type Constraints
T :ModNPC 
T :NPCType 
T :typeof 
T :T 
T :Name 
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.

Definition at line 102 of file Mod.cs.

102  {
103  }
virtual void Terraria.ModLoader.Mod.PostDrawFullscreenMap ( ref string  mouseText)
virtual

Called while the fullscreen map is active. Allows custom drawing to the map.

Parameters
mouseTextThe mouse text.

Definition at line 203 of file ModHooks.cs.

203  {
204  }
virtual void Terraria.ModLoader.Mod.PostDrawInterface ( SpriteBatch  spriteBatch)
virtual

Called after interface is drawn but right before mouse and mouse hover text is drawn. Allows for drawing interface.

Note: This hook should no longer be used. It is better to use the ModifyInterfaceLayers hook.

Parameters
spriteBatchThe sprite batch.

Definition at line 196 of file ModHooks.cs.

196  {
197  }
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).

Definition at line 78 of file Mod.cs.

Referenced by Terraria.ModLoader.ModContent.SetLocalizedText().

78  {
79  }

+ Here is the caller graph for this function:

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

Called after the Network got updated, this is the last hook that happens in an update.

If you are looking to hook an earlier part of the update process, see MidUpdateInvasionNet.

Definition at line 165 of file ModHooks.cs.

165  {
166  }
virtual void Terraria.ModLoader.Mod.PostUpdateInput ( )
virtual

Called after the input keys are polled. Allows for modifying things like scroll wheel if your custom drawing should capture that.

Definition at line 209 of file ModHooks.cs.

209  {
210  }
byte Terraria.ModLoader.Mod.PrefixType ( string  name)

Gets the internal ID / type of the ModPrefix corresponding to the name. Returns 0 if no ModPrefix with the given name is found.

Parameters
nameThe name.
Returns

Referenced by Terraria.ModLoader.IO.ItemIO.Load().

+ Here is the caller graph for this function:

Same as the other PrefixType, but assumes that the class name and internal name are the same.

Template Parameters
T
Returns
Type Constraints
T :ModPrefix 
T :PrefixType 
T :typeof 
T :T 
T :Name 
virtual void Terraria.ModLoader.Mod.PreSaveAndQuit ( )
virtual

Called in SP or Client when the Save and Quit button is pressed. One use for this hook is clearing out custom UI slots to return items to the player.

Definition at line 215 of file ModHooks.cs.

References Terraria.ModLoader.ModLoader.Mods.

215  {
216  }
virtual void Terraria.ModLoader.Mod.PreUpdateEntities ( )
virtual

Use this if you want to do something before anything in the World gets updated. Called after UI updates, but before anything in the World (Players, NPCs, Projectiles, Tiles) gets updated.

When Main.autoPause is true or Main.FrameSkipMode is 0 or 2, the game may do a partial update. This means that it only updates menus and some animations, but not the World or Entities. This hook - and every hook after it - only gets called on frames with a full update.

If you are looking to hook a later part of the update process, see MidUpdatePlayerNPC.

Definition at line 85 of file ModHooks.cs.

85  {
86  }
int Terraria.ModLoader.Mod.ProjectileType ( string  name)

Gets the type of the ModProjectile of this mod with the given name. Returns 0 if no ModProjectile with the given name is found.

Parameters
nameThe name.
Returns

Same as the other ProjectileType, but assumes that the class name and internal name are the same.

Template Parameters
T
Returns
Type Constraints
T :ModProjectile 
T :ProjectileType 
T :typeof 
T :T 
T :Name 
ModHotKey Terraria.ModLoader.Mod.RegisterHotKey ( string  name,
string  defaultKey 
)

Registers a hotkey with a name and defaultKey. Use the returned ModHotKey to detect when buttons are pressed. Do this in a ModPlayer.ProcessTriggers.

Parameters
nameThe name.
defaultKeyThe default key.
Returns

Definition at line 1449 of file Mod.cs.

1449  {
1450  if (!loading)
1451  throw new Exception("RegisterHotKey can only be called from Mod.Load or Mod.Autoload");
1452 
1453  return ModContent.RegisterHotKey(this, name, defaultKey);
1454  }
bool Terraria.ModLoader.Mod.SoundExists ( string  name)

Shorthand for calling ModLoader.SoundExists(this.FileName(name)).

Parameters
nameThe name.
Returns

Referenced by Terraria.ModLoader.ModContent.SoundExists().

+ Here is the caller graph for this function:

bool Terraria.ModLoader.Mod.TextureExists ( string  name)

Shorthand for calling ModLoader.TextureExists(this.FileName(name)).

Parameters
nameThe name.
Returns

Referenced by Terraria.ModLoader.ModContent.TextureExists().

+ Here is the caller graph for this function:

int Terraria.ModLoader.Mod.TileEntityType ( string  name)

Gets the type of the ModTileEntity of this mod with the given name. Returns -1 if no ModTileEntity with the given name is found.

Parameters
nameThe name.
Returns

Same as the other TileEntityType, but assumes that the class name and internal name are the same.

Template Parameters
T
Returns
Type Constraints
T :ModTileEntity 
T :TileEntityType 
T :typeof 
T :T 
T :Name 
int Terraria.ModLoader.Mod.TileType ( string  name)

Gets the type of the ModTile of this mod with the given name. Returns 0 if no ModTile with the given name is found.

Parameters
nameThe name.
Returns

Referenced by Terraria.ModLoader.ModRecipe.AddTile().

+ Here is the caller graph for this function:

Same as the other TileType, but assumes that the class name and internal name are the same.

Template Parameters
T
Returns
Type Constraints
T :ModTile 
T :TileType 
T :typeof 
T :T 
T :Name 
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.

Definition at line 84 of file Mod.cs.

84  {
85  }
virtual void Terraria.ModLoader.Mod.UpdateMusic ( ref int  music,
ref MusicPriority  priority 
)
virtual

Allows you to determine what music should currently play.

Parameters
musicThe music.
priorityThe music priority.

Definition at line 20 of file ModHooks.cs.

20  {
21  UpdateMusic(ref music);
22  }
virtual void UpdateMusic(ref int music, ref MusicPriority priority)
Allows you to determine what music should currently play.
Definition: ModHooks.cs:20
virtual void Terraria.ModLoader.Mod.UpdateMusic ( ref int  music)
virtual

A legacy hook that you should no longer use. Use the version with two parameters instead.

Parameters
music

Definition at line 29 of file ModHooks.cs.

29  {
30  }
virtual void Terraria.ModLoader.Mod.UpdateUI ( GameTime  gameTime)
virtual

Ran every update and suitable for calling Update for UserInterface classes

Definition at line 74 of file ModHooks.cs.

74  {
75  }
int Terraria.ModLoader.Mod.WallType ( string  name)

Gets the type of the ModWall of this mod with the given name. Returns 0 if no ModWall with the given name is found.

Parameters
nameThe name.
Returns

Same as the other WallType, but assumes that the class name and internal name are the same.

Template Parameters
T
Returns
Type Constraints
T :ModWall 
T :WallType 
T :typeof 
T :T 
T :Name 

Member Data Documentation

readonly Queue<Task> Terraria.ModLoader.Mod.AsyncLoadQueue = new Queue<Task>()
private

Definition at line 23 of file ModInternals.cs.

bool Terraria.ModLoader.Mod.IsNetSynced => netID >= 0

Definition at line 66 of file Mod.cs.

virtual string Terraria.ModLoader.Mod.Name => File.name

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.

Definition at line 45 of file Mod.cs.

Referenced by Terraria.ModLoader.PlayerHooks.AddHook< F >(), Terraria.ModLoader.ModRecipe.AddIngredient(), Terraria.ModLoader.ModRecipe.AddTile(), Terraria.ModLoader.Mod.AutoloadBuff(), Terraria.ModLoader.Mod.AutoloadDust(), Terraria.ModLoader.Mod.AutoloadGlobalBgStyle(), Terraria.ModLoader.Mod.AutoloadGlobalBuff(), Terraria.ModLoader.Mod.AutoloadGlobalItem(), Terraria.ModLoader.Mod.AutoloadGlobalNPC(), Terraria.ModLoader.Mod.AutoloadGlobalProjectile(), Terraria.ModLoader.Mod.AutoloadGlobalRecipe(), Terraria.ModLoader.Mod.AutoloadGlobalTile(), Terraria.ModLoader.Mod.AutoloadGlobalWall(), Terraria.ModLoader.Mod.AutoloadItem(), Terraria.ModLoader.Mod.AutoloadModWorld(), Terraria.ModLoader.Mod.AutoloadMountData(), Terraria.ModLoader.Mod.AutoloadNPC(), Terraria.ModLoader.Mod.AutoloadPlayer(), Terraria.ModLoader.Mod.AutoloadPrefix(), Terraria.ModLoader.Mod.AutoloadProjectile(), Terraria.ModLoader.Mod.AutoloadSurfaceBgStyle(), Terraria.ModLoader.Mod.AutoloadTile(), Terraria.ModLoader.Mod.AutoloadTileEntity(), Terraria.ModLoader.Mod.AutoloadUgBgStyle(), Terraria.ModLoader.Mod.AutoloadWall(), Terraria.ModLoader.Mod.AutoloadWaterfallStyle(), Terraria.ModLoader.Mod.AutoloadWaterStyle(), Terraria.ModLoader.Exceptions.CustomModDataException.CustomModDataException(), Terraria.ModLoader.IO.ItemIO.LoadLegacy(), Terraria.ModLoader.IO.ItemIO.Save(), Terraria.ModLoader.PlayerHooks.SendCustomBiomes(), Terraria.ModLoader.ModContent.SetLocalizedText(), Terraria.ModLoader.ModRecipe.SetResult(), Terraria.ModLoader.ModNet.SetupDiagnostics(), Terraria.ModLoader.MonoModHooks.StringRep(), and Terraria.ModLoader.TooltipLine.TooltipLine().

virtual Version Terraria.ModLoader.Mod.Version => File.version

This version number of this mod.

Definition at line 53 of file Mod.cs.

Property Documentation

Assembly Terraria.ModLoader.Mod.Code
getset

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

Definition at line 36 of file Mod.cs.

string Terraria.ModLoader.Mod.DisplayName
getset

The display name of this mod in the Mods menu.

Definition at line 63 of file Mod.cs.

TmodFile Terraria.ModLoader.Mod.File
getset

The TmodFile object created when tModLoader reads this mod.

Definition at line 32 of file Mod.cs.

ILog Terraria.ModLoader.Mod.Logger
getset

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

Definition at line 40 of file Mod.cs.

Referenced by Terraria.ModLoader.ErrorLogger.Log().

ModProperties Terraria.ModLoader.Mod.Properties
getprotected set

Definition at line 55 of file Mod.cs.

ModSide Terraria.ModLoader.Mod.Side = ModProperties.AutoLoadAll
getset

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

Definition at line 59 of file Mod.cs.

Version Terraria.ModLoader.Mod.tModLoaderVersion
getset

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

Definition at line 49 of file Mod.cs.