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 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 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 void RefreshModLanguage (GameCulture culture)
 
static bool SoundExists (string name)
 Returns whether or not a sound with the specified name exists. More...
 
static bool TextureExists (string name)
 Returns whether or not a texture with the specified name exists. More...
 
static void Unload ()
 

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 void SplitName (string name, out string domain, out string subName)
 

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 240 of file ModContent.cs.

240  {
241  EffectsTracker.CacheVanillaState();
242  }
static void Terraria.ModLoader.ModContent.DisposeMusic ( )
staticprivate

Definition at line 415 of file ModContent.cs.

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

415  {
416  for (int i = 0; i < Main.music.Length; i++) {
417  MusicStreaming music = Main.music[i] as MusicStreaming;
418  if (music != null) {
419  if (i < Main.maxMusic) {
420  Main.music[i] = Main.soundBank.GetCue("Music_" + i);
421  }
422  else {
423  Main.music[i] = null;
424  }
425  music.Stop(AudioStopOptions.Immediate);
426  music.Dispose();
427  }
428  }
429  }
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 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 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.BackgroundTextureLoader.GetBackgroundSlot(), Terraria.ModLoader.NPCHeadLoader.GetBossHeadSlot(), Terraria.ModLoader.EquipLoader.GetEquipTexture(), Terraria.ModLoader.ModGore.GetGoreSlot(), and Terraria.ModLoader.Mod.LoadEffect().

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 245 of file ModContent.cs.

References Terraria.ModLoader.ModLoader.Mods.

245  {
246  int num = 0;
247  foreach (var mod in ModLoader.Mods) {
248  Interface.loadMods.SetCurrentMod(num++, mod.Name);
249  try {
250  LoadingMod = mod;
251  loadAction(mod);
252  }
253  catch (Exception e) {
254  e.Data["mod"] = mod.Name;
255  throw;
256  }
257  finally {
258  LoadingMod = null;
259  }
260  }
261  }
static bool Terraria.ModLoader.ModContent.MusicExists ( string  name)
static

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

Definition at line 182 of file ModContent.cs.

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

182  {
183  if (!name.Contains('/')) { return false; }
184  string modName, subName;
185  SplitName(name, out modName, out subName);
186  Mod mod = ModLoader.GetMod(modName);
187  return mod != null && mod.MusicExists(subName);
188  }
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.RefreshModLanguage ( GameCulture  culture)
static

Definition at line 361 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.

361  {
362  Dictionary<string, LocalizedText> dict = LanguageManager.Instance._localizedTexts;
363  foreach (ModItem item in ItemLoader.items) {
364  LocalizedText text = new LocalizedText(item.DisplayName.Key, item.DisplayName.GetTranslation(culture));
365  Lang._itemNameCache[item.item.type] = SetLocalizedText(dict, text);
366  text = new LocalizedText(item.Tooltip.Key, item.Tooltip.GetTranslation(culture));
367  if (text.Value != null) {
368  text = SetLocalizedText(dict, text);
369  Lang._itemTooltipCache[item.item.type] = ItemTooltip.FromLanguageKey(text.Key);
370  }
371  }
372  foreach (ModPrefix prefix in ModPrefix.prefixes) {
373  LocalizedText text = new LocalizedText(prefix.DisplayName.Key, prefix.DisplayName.GetTranslation(culture));
374  Lang.prefix[prefix.Type] = SetLocalizedText(dict, text);
375  }
376  foreach (var keyValuePair in MapLoader.tileEntries) {
377  foreach (MapEntry entry in keyValuePair.Value) {
378  if (entry.translation != null) {
379  LocalizedText text = new LocalizedText(entry.translation.Key, entry.translation.GetTranslation(culture));
380  SetLocalizedText(dict, text);
381  }
382  }
383  }
384  foreach (var keyValuePair in MapLoader.wallEntries) {
385  foreach (MapEntry entry in keyValuePair.Value) {
386  if (entry.translation != null) {
387  LocalizedText text = new LocalizedText(entry.translation.Key, entry.translation.GetTranslation(culture));
388  SetLocalizedText(dict, text);
389  }
390  }
391  }
392  foreach (ModProjectile proj in ProjectileLoader.projectiles) {
393  LocalizedText text = new LocalizedText(proj.DisplayName.Key, proj.DisplayName.GetTranslation(culture));
394  Lang._projectileNameCache[proj.projectile.type] = SetLocalizedText(dict, text);
395  }
396  foreach (ModNPC npc in NPCLoader.npcs) {
397  LocalizedText text = new LocalizedText(npc.DisplayName.Key, npc.DisplayName.GetTranslation(culture));
398  Lang._npcNameCache[npc.npc.type] = SetLocalizedText(dict, text);
399  }
400  foreach (ModBuff buff in BuffLoader.buffs) {
401  LocalizedText text = new LocalizedText(buff.DisplayName.Key, buff.DisplayName.GetTranslation(culture));
402  Lang._buffNameCache[buff.Type] = SetLocalizedText(dict, text);
403  text = new LocalizedText(buff.Description.Key, buff.Description.GetTranslation(culture));
404  Lang._buffDescriptionCache[buff.Type] = SetLocalizedText(dict, text);
405  }
406  foreach (Mod mod in ModLoader.Mods) {
407  foreach (ModTranslation translation in mod.translations.Values) {
408  LocalizedText text = new LocalizedText(translation.Key, translation.GetTranslation(culture));
409  SetLocalizedText(dict, text);
410  }
411  }
412  LanguageManager.Instance.ProcessCopyCommandsInTexts();
413  }
static LocalizedText SetLocalizedText(Dictionary< string, LocalizedText > dict, LocalizedText value)
Definition: ModContent.cs:190

+ Here is the call graph for this function:

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

Definition at line 333 of file ModContent.cs.

333  {
334  ItemLoader.ResizeArrays(unloading);
335  EquipLoader.ResizeAndFillArrays();
336  ModPrefix.ResizeArrays();
337  Main.InitializeItemAnimations();
338  ModDust.ResizeArrays();
339  TileLoader.ResizeArrays(unloading);
340  WallLoader.ResizeArrays(unloading);
341  ProjectileLoader.ResizeArrays();
342  NPCLoader.ResizeArrays(unloading);
343  NPCHeadLoader.ResizeAndFillArrays();
344  ModGore.ResizeAndFillArrays();
345  SoundLoader.ResizeAndFillArrays();
346  MountLoader.ResizeArrays();
347  BuffLoader.ResizeArrays();
348  PlayerHooks.RebuildHooks();
349  BackgroundTextureLoader.ResizeAndFillArrays();
350  UgBgStyleLoader.ResizeAndFillArrays();
351  SurfaceBgStyleLoader.ResizeAndFillArrays();
352  GlobalBgStyleLoader.ResizeAndFillArrays(unloading);
353  WaterStyleLoader.ResizeArrays();
354  WaterfallStyleLoader.ResizeArrays();
355  WorldHooks.ResizeArrays();
356  foreach (LocalizedText text in LanguageManager.Instance._localizedTexts.Values) {
357  text.Override = null;
358  }
359  }
static LocalizedText Terraria.ModLoader.ModContent.SetLocalizedText ( Dictionary< string, LocalizedText >  dict,
LocalizedText  value 
)
staticprivate

Definition at line 190 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().

190  {
191  if (dict.ContainsKey(value.Key)) {
192  dict[value.Key].SetValue(value.Value);
193  }
194  else {
195  dict[value.Key] = value;
196  }
197  return dict[value.Key];
198  }

+ Here is the call graph for this function:

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

Definition at line 263 of file ModContent.cs.

References Terraria.ModLoader.ModLoader.Mods.

263  {
264  Interface.loadMods.SetLoadStage("tModLoader.MSAddingRecipes");
265  for (int k = 0; k < Recipe.maxRecipes; k++)
266  Main.recipe[k] = new Recipe();
267 
268  Recipe.numRecipes = 0;
269  RecipeGroupHelper.ResetRecipeGroups();
270  Recipe.SetupRecipes();
271  }
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 
)
staticprivate

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:

static void Terraria.ModLoader.ModContent.Unload ( )
static

Definition at line 289 of file ModContent.cs.

Referenced by Terraria.ModLoader.ModLoader.Unload().

289  {
290  ItemLoader.Unload();
291  EquipLoader.Unload();
292  ModPrefix.Unload();
293  ModDust.Unload();
294  TileLoader.Unload();
295  ModTileEntity.Unload();
296  WallLoader.Unload();
297  ProjectileLoader.Unload();
298  NPCLoader.Unload();
299  NPCHeadLoader.Unload();
300  PlayerHooks.Unload();
301  BuffLoader.Unload();
302  MountLoader.Unload();
303  ModGore.Unload();
304  SoundLoader.Unload();
305  DisposeMusic();
306  BackgroundTextureLoader.Unload();
307  UgBgStyleLoader.Unload();
308  SurfaceBgStyleLoader.Unload();
309  GlobalBgStyleLoader.Unload();
310  WaterStyleLoader.Unload();
311  WaterfallStyleLoader.Unload();
312  WorldHooks.Unload();
313  ResizeArrays(true);
314  for (int k = 0; k < Recipe.maxRecipes; k++) {
315  Main.recipe[k] = new Recipe();
316  }
317  Recipe.numRecipes = 0;
318  RecipeGroupHelper.ResetRecipeGroups();
319  Recipe.SetupRecipes();
320  MapLoader.UnloadModMap();
321  ItemSorting.SetupWhiteLists();
322  modHotKeys.Clear();
323  RecipeHooks.Unload();
324  CommandManager.Unload();
325  TagSerializer.Reload();
326  ModNet.Unload();
327  CustomCurrencyManager.Initialize();
328  EffectsTracker.RemoveModEffects();
329 
330  CleanupModReferences();
331  }
static void ResizeArrays(bool unloading=false)
Definition: ModContent.cs:333

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