Terraria ModLoader  0.10.1.5
A framework for Terraria mods
Terraria.ModLoader.ModContent Class Reference

Manages content added by mods. Liasons between mod content and Terraria's arrays and oversees the Loader classes. More...

+ Collaboration diagram for Terraria.ModLoader.ModContent:

Static Public Member Functions

static bool FileExists (string name)
 Returns whether or not a file with the specified name exists. More...
 
static EquipTexture GetEquipTexture (EquipType type, int slot)
 Gets the equipment texture for the specified equipment type and ID. More...
 
static byte[] GetFileBytes (string name)
 Gets the byte representation of the file with the specified name. The name is in the format of "ModFolder/OtherFolders/FileNameWithExtension". Throws an ArgumentException if the file does not exist. More...
 
static int GetModBackgroundSlot (string texture)
 Returns the slot/ID of the background texture with the given name. More...
 
static int GetModBossHeadSlot (string texture)
 Gets the index of the boss head texture corresponding to the given texture path. More...
 
static ModBuff GetModBuff (int type)
 Gets the ModBuff instance with the given type. If no ModBuff with the given type exists, returns null. More...
 
static ModDust GetModDust (int type)
 Gets the ModDust instance with the given type. Returns null if no ModDust with the given type exists. More...
 
static int GetModHeadSlot (string texture)
 Gets the index of the head texture corresponding to the given texture path. More...
 
static ModItem GetModItem (int type)
 Gets the ModItem instance corresponding to the specified type. Returns null if no modded item has the given type. More...
 
static ModMountData GetModMountData (int type)
 Gets the ModMountData instance corresponding to the given type. Returns null if no ModMountData has the given type. More...
 
static ModNPC GetModNPC (int type)
 Gets the ModNPC instance corresponding to the specified type. More...
 
static ModProjectile GetModProjectile (int type)
 Gets the ModProjectile instance corresponding to the specified type. More...
 
static ModSurfaceBgStyle GetModSurfaceBgStyle (int style)
 Returns the ModSurfaceBgStyle object with the given ID. More...
 
static ModTile GetModTile (int type)
 Gets the ModTile instance with the given type. If no ModTile with the given type exists, returns null. More...
 
static ModUgBgStyle GetModUgBgStyle (int style)
 Returns the ModUgBgStyle object with the given ID. More...
 
static ModWall GetModWall (int type)
 Gets the ModWall instance with the given type. If no ModWall with the given type exists, returns null. More...
 
static ModWaterfallStyle GetModWaterfallStyle (int style)
 Returns the ModWaterfallStyle with the given ID. More...
 
static ModWaterStyle GetModWaterStyle (int style)
 Returns the ModWaterStyle with the given ID. More...
 
static Music GetMusic (string name)
 Gets the music with the specified name. The name is in the same format as for texture names. Throws an ArgumentException if the music does not exist. Note: SoundMP3 is in the Terraria.ModLoader namespace. More...
 
static SoundEffect GetSound (string name)
 Gets the sound with the specified name. The name is in the same format as for texture names. Throws an ArgumentException if the sound does not exist. Note: SoundEffect is in the Microsoft.Xna.Framework.Audio namespace. More...
 
static Texture2D GetTexture (string name)
 Gets the texture with the specified name. The name is in the format of "ModFolder/OtherFolders/FileNameWithoutExtension". Throws an ArgumentException if the texture does not exist. If a vanilla texture is desired, the format "Terraria/FileNameWithoutExtension" will reference an image from the "terraria/Content/Images" folder. Note: Texture2D is in the Microsoft.Xna.Framework.Graphics namespace. More...
 
static bool MusicExists (string name)
 Returns whether or not a sound with the specified name exists. More...
 
static Stream OpenRead (string assetName, bool newFileStream=false)
 
static void RefreshModLanguage (GameCulture culture)
 
static bool SoundExists (string name)
 Returns whether or not a sound with the specified name exists. More...
 
static void SplitName (string name, out string domain, out string subName)
 
static bool TextureExists (string name)
 Returns whether or not a texture with the specified name exists. More...
 

Static Private Member Functions

static void CacheVanillaState ()
 
static void DisposeMusic ()
 
static void LoadModContent (Action< Mod > loadAction)
 
static void ResizeArrays (bool unloading=false)
 
static LocalizedText SetLocalizedText (Dictionary< string, LocalizedText > dict, LocalizedText value)
 
static void SetupRecipes ()
 

Static Private Attributes

static readonly string ImagePath = "Content" + Path.DirectorySeparatorChar + "Images"
 

Detailed Description

Manages content added by mods. Liasons between mod content and Terraria's arrays and oversees the Loader classes.

Definition at line 21 of file ModContent.cs.

Member Function Documentation

static void Terraria.ModLoader.ModContent.CacheVanillaState ( )
staticprivate

Definition at line 338 of file ModContent.cs.

338  {
339  EffectsTracker.CacheVanillaState();
340  }
static void Terraria.ModLoader.ModContent.DisposeMusic ( )
staticprivate

Definition at line 516 of file ModContent.cs.

References Terraria.ModLoader.ModItem.item, and Terraria.ModLoader.ModNPC.npc.

516  {
517  foreach (var music in Main.music.OfType<MusicStreaming>())
518  music.Dispose();
519  }
static bool Terraria.ModLoader.ModContent.FileExists ( string  name)
static

Returns whether or not a file with the specified name exists.

Definition at line 54 of file ModContent.cs.

References Terraria.ModLoader.Mod.FileExists(), and Terraria.ModLoader.ModLoader.GetMod().

54  {
55  if (!name.Contains('/'))
56  return false;
57 
58  string modName, subName;
59  SplitName(name, out modName, out subName);
60 
61  Mod mod = ModLoader.GetMod(modName);
62  return mod != null && mod.FileExists(subName);
63  }
static void SplitName(string name, out string domain, out string subName)
Definition: ModContent.cs:27

+ Here is the call graph for this function:

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

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

Parameters
type
slot
Returns
static byte [] Terraria.ModLoader.ModContent.GetFileBytes ( string  name)
static

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

Exceptions
MissingResourceExceptionMissing mod: " + name

Definition at line 40 of file ModContent.cs.

References Terraria.ModLoader.Mod.GetFileBytes(), and Terraria.ModLoader.ModLoader.GetMod().

40  {
41  string modName, subName;
42  SplitName(name, out modName, out subName);
43 
44  Mod mod = ModLoader.GetMod(modName);
45  if (mod == null)
46  throw new MissingResourceException("Missing mod: " + name);
47 
48  return mod.GetFileBytes(subName);
49  }
static void SplitName(string name, out string domain, out string subName)
Definition: ModContent.cs:27

+ Here is the call graph for this function:

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

Returns the slot/ID of the background texture with the given name.

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

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

Parameters
texture
Returns
static ModBuff Terraria.ModLoader.ModContent.GetModBuff ( int  type)
static

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

static ModDust Terraria.ModLoader.ModContent.GetModDust ( int  type)
static

Gets the ModDust instance with the given type. Returns null if no ModDust with the given type exists.

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

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

Parameters
textureRelative texture path
Returns
The index of the texture in the heads array, -1 if not found.
static ModItem Terraria.ModLoader.ModContent.GetModItem ( int  type)
static

Gets the ModItem instance corresponding to the specified type. Returns null if no modded item has the given type.

static ModMountData Terraria.ModLoader.ModContent.GetModMountData ( int  type)
static

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

Parameters
typeThe type of the mount.
Returns
Null if not found, otherwise the ModMountData associated with the mount.
static ModNPC Terraria.ModLoader.ModContent.GetModNPC ( int  type)
static

Gets the ModNPC instance corresponding to the specified type.

Parameters
typeThe type of the npc
Returns
The ModNPC instance in the npcs array, null if not found.
static ModProjectile Terraria.ModLoader.ModContent.GetModProjectile ( int  type)
static

Gets the ModProjectile instance corresponding to the specified type.

Parameters
typeThe type of the projectile
Returns
The ModProjectile instance in the projectiles array, null if not found.
static ModSurfaceBgStyle Terraria.ModLoader.ModContent.GetModSurfaceBgStyle ( int  style)
static

Returns the ModSurfaceBgStyle object with the given ID.

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

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

Parameters
typeThe type of the ModTile
Returns
The ModTile instance in the tiles array, null if not found.
static ModUgBgStyle Terraria.ModLoader.ModContent.GetModUgBgStyle ( int  style)
static

Returns the ModUgBgStyle object with the given ID.

static ModWall Terraria.ModLoader.ModContent.GetModWall ( int  type)
static

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

static ModWaterfallStyle Terraria.ModLoader.ModContent.GetModWaterfallStyle ( int  style)
static

Returns the ModWaterfallStyle with the given ID.

static ModWaterStyle Terraria.ModLoader.ModContent.GetModWaterStyle ( int  style)
static

Returns the ModWaterStyle with the given ID.

static Music Terraria.ModLoader.ModContent.GetMusic ( string  name)
static

Gets the music with the specified name. The name is in the same format as for texture names. Throws an ArgumentException if the music does not exist. Note: SoundMP3 is in the Terraria.ModLoader namespace.

Exceptions
MissingResourceExceptionMissing mod: " + name

Definition at line 170 of file ModContent.cs.

References Terraria.ModLoader.ModLoader.GetMod(), Terraria.ModLoader.Mod.GetMusic(), and Terraria.ModLoader.Music.

Referenced by Terraria.ModLoader.SoundLoader.GetSoundSlot().

170  {
171  if (Main.dedServ) { return null; }
172  string modName, subName;
173  SplitName(name, out modName, out subName);
174  Mod mod = ModLoader.GetMod(modName);
175  if (mod == null) { throw new MissingResourceException("Missing mod: " + name); }
176  return mod.GetMusic(subName);
177  }
static void SplitName(string name, out string domain, out string subName)
Definition: ModContent.cs:27

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static SoundEffect Terraria.ModLoader.ModContent.GetSound ( string  name)
static

Gets the sound with the specified name. The name is in the same format as for texture names. Throws an ArgumentException if the sound does not exist. Note: SoundEffect is in the Microsoft.Xna.Framework.Audio namespace.

Exceptions
MissingResourceExceptionMissing mod: " + name

Definition at line 138 of file ModContent.cs.

References Terraria.ModLoader.ModLoader.GetMod(), and Terraria.ModLoader.Mod.GetSound().

Referenced by Terraria.ModLoader.Mod.AddSound(), and Terraria.ModLoader.SoundLoader.GetSoundSlot().

138  {
139  if (Main.dedServ)
140  return null;
141 
142  string modName, subName;
143  SplitName(name, out modName, out subName);
144 
145  Mod mod = ModLoader.GetMod(modName);
146  if (mod == null)
147  throw new MissingResourceException("Missing mod: " + name);
148 
149  return mod.GetSound(subName);
150  }
static void SplitName(string name, out string domain, out string subName)
Definition: ModContent.cs:27

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static Texture2D Terraria.ModLoader.ModContent.GetTexture ( string  name)
static

Gets the texture with the specified name. The name is in the format of "ModFolder/OtherFolders/FileNameWithoutExtension". Throws an ArgumentException if the texture does not exist. If a vanilla texture is desired, the format "Terraria/FileNameWithoutExtension" will reference an image from the "terraria/Content/Images" folder. Note: Texture2D is in the Microsoft.Xna.Framework.Graphics namespace.

Exceptions
MissingResourceExceptionMissing mod: " + name

Definition at line 69 of file ModContent.cs.

References Terraria.ModLoader.ModLoader.GetMod().

Referenced by Terraria.ModLoader.Mod.AddBackgroundTexture(), Terraria.ModLoader.Mod.AddBossHeadTexture(), Terraria.ModLoader.Mod.AddDust(), Terraria.ModLoader.Mod.AddEquipTexture(), Terraria.ModLoader.Mod.AddMount(), Terraria.ModLoader.Mod.AddNPCHeadTexture(), Terraria.ModLoader.ModProjectile.AutoStaticDefaults(), Terraria.ModLoader.ModItem.AutoStaticDefaults(), Terraria.ModLoader.ModNPC.AutoStaticDefaults(), Terraria.ModLoader.EquipLoader.GetEquipTexture(), Terraria.ModLoader.ModGore.GetGoreSlot(), and Terraria.ModLoader.Mod.LoadMusic().

69  {
70  if (Main.dedServ)
71  return null;
72 
73  string modName, subName;
74  SplitName(name, out modName, out subName);
75  if (modName == "Terraria")
76  return Main.instance.Content.Load<Texture2D>("Images" + Path.DirectorySeparatorChar + subName);
77 
78  Mod mod = ModLoader.GetMod(modName);
79  if (mod == null)
80  throw new MissingResourceException("Missing mod: " + name);
81 
82  return mod.GetTexture(subName);
83  }
static void SplitName(string name, out string domain, out string subName)
Definition: ModContent.cs:27

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void Terraria.ModLoader.ModContent.LoadModContent ( Action< Mod loadAction)
staticprivate

Definition at line 343 of file ModContent.cs.

References Terraria.ModLoader.ModLoader.Mods.

343  {
344  MemoryTracking.Checkpoint();
345  int num = 0;
346  foreach (var mod in ModLoader.Mods) {
347  Interface.loadMods.SetCurrentMod(num++, mod.Name);
348  try {
349  LoadingMod = mod;
350  loadAction(mod);
351  }
352  catch (Exception e) {
353  e.Data["mod"] = mod.Name;
354  throw;
355  }
356  finally {
357  LoadingMod = null;
358  MemoryTracking.Update(mod.Name);
359  }
360  }
361  }
static Stream Terraria.ModLoader.ModContent.OpenRead ( string  assetName,
bool  newFileStream = false 
)
static

Definition at line 550 of file ModContent.cs.

References Terraria.ModLoader.Mod.GetFileStream(), and Terraria.ModLoader.ModLoader.GetMod().

Referenced by Terraria.ModLoader.IO.TMLContentManager.OpenStream().

550  {
551  if (!assetName.StartsWith("tmod:"))
552  return File.OpenRead(assetName);
553 
554  SplitName(assetName.Substring(5).Replace('\\', '/'), out var modName, out var entryPath);
555  return ModLoader.GetMod(modName).GetFileStream(entryPath, newFileStream);
556  }
static void SplitName(string name, out string domain, out string subName)
Definition: ModContent.cs:27

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void Terraria.ModLoader.ModContent.RefreshModLanguage ( GameCulture  culture)
static

Definition at line 462 of file ModContent.cs.

References Terraria.ModLoader.ModBuff.Description, Terraria.ModLoader.ModBuff.DisplayName, Terraria.ModLoader.ModNPC.DisplayName, Terraria.ModLoader.ModItem.DisplayName, Terraria.ModLoader.ModProjectile.DisplayName, Terraria.ModLoader.ModPrefix.DisplayName, Terraria.ModLoader.ModTranslation.GetTranslation(), Terraria.ModLoader.ModItem.item, Terraria.ModLoader.ModTranslation.Key, Terraria.ModLoader.ModLoader.Mods, Terraria.ModLoader.ModNPC.npc, Terraria.ModLoader.ModProjectile.projectile, Terraria.ModLoader.ModItem.Tooltip, Terraria.ModLoader.ModBuff.Type, and Terraria.ModLoader.ModPrefix.Type.

462  {
463  Dictionary<string, LocalizedText> dict = LanguageManager.Instance._localizedTexts;
464  foreach (ModItem item in ItemLoader.items) {
465  LocalizedText text = new LocalizedText(item.DisplayName.Key, item.DisplayName.GetTranslation(culture));
466  Lang._itemNameCache[item.item.type] = SetLocalizedText(dict, text);
467  text = new LocalizedText(item.Tooltip.Key, item.Tooltip.GetTranslation(culture));
468  if (text.Value != null) {
469  text = SetLocalizedText(dict, text);
470  Lang._itemTooltipCache[item.item.type] = ItemTooltip.FromLanguageKey(text.Key);
471  }
472  }
473  foreach (ModPrefix prefix in ModPrefix.prefixes) {
474  LocalizedText text = new LocalizedText(prefix.DisplayName.Key, prefix.DisplayName.GetTranslation(culture));
475  Lang.prefix[prefix.Type] = SetLocalizedText(dict, text);
476  }
477  foreach (var keyValuePair in MapLoader.tileEntries) {
478  foreach (MapEntry entry in keyValuePair.Value) {
479  if (entry.translation != null) {
480  LocalizedText text = new LocalizedText(entry.translation.Key, entry.translation.GetTranslation(culture));
481  SetLocalizedText(dict, text);
482  }
483  }
484  }
485  foreach (var keyValuePair in MapLoader.wallEntries) {
486  foreach (MapEntry entry in keyValuePair.Value) {
487  if (entry.translation != null) {
488  LocalizedText text = new LocalizedText(entry.translation.Key, entry.translation.GetTranslation(culture));
489  SetLocalizedText(dict, text);
490  }
491  }
492  }
493  foreach (ModProjectile proj in ProjectileLoader.projectiles) {
494  LocalizedText text = new LocalizedText(proj.DisplayName.Key, proj.DisplayName.GetTranslation(culture));
495  Lang._projectileNameCache[proj.projectile.type] = SetLocalizedText(dict, text);
496  }
497  foreach (ModNPC npc in NPCLoader.npcs) {
498  LocalizedText text = new LocalizedText(npc.DisplayName.Key, npc.DisplayName.GetTranslation(culture));
499  Lang._npcNameCache[npc.npc.type] = SetLocalizedText(dict, text);
500  }
501  foreach (ModBuff buff in BuffLoader.buffs) {
502  LocalizedText text = new LocalizedText(buff.DisplayName.Key, buff.DisplayName.GetTranslation(culture));
503  Lang._buffNameCache[buff.Type] = SetLocalizedText(dict, text);
504  text = new LocalizedText(buff.Description.Key, buff.Description.GetTranslation(culture));
505  Lang._buffDescriptionCache[buff.Type] = SetLocalizedText(dict, text);
506  }
507  foreach (Mod mod in ModLoader.Mods) {
508  foreach (ModTranslation translation in mod.translations.Values) {
509  LocalizedText text = new LocalizedText(translation.Key, translation.GetTranslation(culture));
510  SetLocalizedText(dict, text);
511  }
512  }
513  LanguageManager.Instance.ProcessCopyCommandsInTexts();
514  }
static LocalizedText SetLocalizedText(Dictionary< string, LocalizedText > dict, LocalizedText value)
Definition: ModContent.cs:285

+ Here is the call graph for this function:

static void Terraria.ModLoader.ModContent.ResizeArrays ( bool  unloading = false)
staticprivate

Definition at line 434 of file ModContent.cs.

434  {
435  ItemLoader.ResizeArrays(unloading);
436  EquipLoader.ResizeAndFillArrays();
437  ModPrefix.ResizeArrays();
438  Main.InitializeItemAnimations();
439  ModDust.ResizeArrays();
440  TileLoader.ResizeArrays(unloading);
441  WallLoader.ResizeArrays(unloading);
442  ProjectileLoader.ResizeArrays();
443  NPCLoader.ResizeArrays(unloading);
444  NPCHeadLoader.ResizeAndFillArrays();
445  ModGore.ResizeAndFillArrays();
446  SoundLoader.ResizeAndFillArrays();
447  MountLoader.ResizeArrays();
448  BuffLoader.ResizeArrays();
449  PlayerHooks.RebuildHooks();
450  BackgroundTextureLoader.ResizeAndFillArrays();
451  UgBgStyleLoader.ResizeAndFillArrays();
452  SurfaceBgStyleLoader.ResizeAndFillArrays();
453  GlobalBgStyleLoader.ResizeAndFillArrays(unloading);
454  WaterStyleLoader.ResizeArrays();
455  WaterfallStyleLoader.ResizeArrays();
456  WorldHooks.ResizeArrays();
457  foreach (LocalizedText text in LanguageManager.Instance._localizedTexts.Values) {
458  text.Override = null;
459  }
460  }
static LocalizedText Terraria.ModLoader.ModContent.SetLocalizedText ( Dictionary< string, LocalizedText >  dict,
LocalizedText  value 
)
staticprivate

Definition at line 285 of file ModContent.cs.

References Terraria.ModLoader.Mod.Load(), Terraria.ModLoader.Mod.LoadResources(), Terraria.ModLoader.ModLoader.Mods, Terraria.ModLoader.Mod.Name, and Terraria.ModLoader.Mod.PostSetupContent().

285  {
286  if (dict.ContainsKey(value.Key)) {
287  dict[value.Key].SetValue(value.Value);
288  }
289  else {
290  dict[value.Key] = value;
291  }
292  return dict[value.Key];
293  }

+ Here is the call graph for this function:

static void Terraria.ModLoader.ModContent.SetupRecipes ( )
staticprivate

Definition at line 363 of file ModContent.cs.

References Terraria.ModLoader.ModLoader.Mods.

363  {
364  Interface.loadMods.SetLoadStage("tModLoader.MSAddingRecipes");
365  for (int k = 0; k < Recipe.maxRecipes; k++)
366  Main.recipe[k] = new Recipe();
367 
368  Recipe.numRecipes = 0;
369  RecipeGroupHelper.ResetRecipeGroups();
370  Recipe.SetupRecipes();
371  }
static bool Terraria.ModLoader.ModContent.SoundExists ( string  name)
static

Returns whether or not a sound with the specified name exists.

Definition at line 155 of file ModContent.cs.

References Terraria.ModLoader.ModLoader.GetMod(), and Terraria.ModLoader.Mod.SoundExists().

155  {
156  if (!name.Contains('/'))
157  return false;
158 
159  string modName, subName;
160  SplitName(name, out modName, out subName);
161 
162  Mod mod = ModLoader.GetMod(modName);
163  return mod != null && mod.SoundExists(subName);
164  }
static void SplitName(string name, out string domain, out string subName)
Definition: ModContent.cs:27

+ Here is the call graph for this function:

static void Terraria.ModLoader.ModContent.SplitName ( string  name,
out string  domain,
out string  subName 
)
static

Definition at line 27 of file ModContent.cs.

27  {
28  int slash = name.IndexOf('/');
29  if (slash < 0)
30  throw new MissingResourceException("Missing mod qualifier: " + name);
31 
32  domain = name.Substring(0, slash);
33  subName = name.Substring(slash + 1);
34  }
static bool Terraria.ModLoader.ModContent.TextureExists ( string  name)
static

Returns whether or not a texture with the specified name exists.

Definition at line 88 of file ModContent.cs.

References Terraria.ModLoader.ModLoader.GetMod(), and Terraria.ModLoader.Mod.TextureExists().

Referenced by Terraria.ModLoader.Mod.AddEquipTexture(), Terraria.ModLoader.Mod.AddMount(), and Terraria.ModLoader.ModItem.AutoStaticDefaults().

88  {
89  if (!name.Contains('/'))
90  return false;
91 
92  string modName, subName;
93  SplitName(name, out modName, out subName);
94 
95  if (modName == "Terraria")
96  return File.Exists(ImagePath + Path.DirectorySeparatorChar + subName + ".xnb");
97 
98  Mod mod = ModLoader.GetMod(modName);
99  return mod != null && mod.TextureExists(subName);
100  }
static void SplitName(string name, out string domain, out string subName)
Definition: ModContent.cs:27
static readonly string ImagePath
Definition: ModContent.cs:23

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

readonly string Terraria.ModLoader.ModContent.ImagePath = "Content" + Path.DirectorySeparatorChar + "Images"
staticprivate

Definition at line 23 of file ModContent.cs.