Terraria ModLoader  0.11.5
A framework for Terraria mods
Mod.cs
Go to the documentation of this file.
1 using log4net;
2 using Microsoft.Xna.Framework.Audio;
3 using Microsoft.Xna.Framework.Graphics;
4 using ReLogic.Graphics;
5 using System;
6 using System.Collections.Generic;
7 using System.IO;
8 using System.Reflection;
9 using Terraria.Audio;
10 using Terraria.ID;
11 using Terraria.Localization;
13 using Terraria.ModLoader.Core;
15 using System.Linq;
17 using Terraria.ModLoader.UI;
18 
19 namespace Terraria.ModLoader
20 {
24  public abstract partial class Mod
25  {
29  internal TmodFile File { get; set; }
33  public Assembly Code { get; internal set; }
37  public ILog Logger { get; internal set; }
38 
42  public virtual string Name => File.name;
46  public Version tModLoaderVersion { get; internal set; }
50  public virtual Version Version => File.version;
51 
52  public ModProperties Properties { get; protected set; } = ModProperties.AutoLoadAll;
56  public ModSide Side { get; internal set; }
60  public string DisplayName { get; internal set; }
61 
62  internal short netID = -1;
63  public bool IsNetSynced => netID >= 0;
64 
65  private IDisposable fileHandle;
66 
67 
71  public virtual void Load() {
72  }
73 
77  public virtual void PostSetupContent() {
78  }
79 
83  public virtual void Unload() {
84  }
85 
89  public virtual uint ExtraPlayerBuffSlots { get; }
90 
94  public virtual void AddRecipeGroups() {
95  }
96 
100  public virtual void AddRecipes() {
101  }
102 
106  public virtual void PostAddRecipes() {
107  }
108 
109  public virtual void LoadResources() {
110  if (File == null)
111  return;
112 
113  fileHandle = File.Open();
114 
115  var skipCache = new HashSet<string>();
116  foreach (var entry in File) {
117  Interface.loadMods.SubProgressText = entry.Name;
118 
119  Stream _stream = null;
120  Stream GetStream() => _stream = File.GetStream(entry);
121 
122  if (LoadResource(entry.Name, entry.Length, GetStream))
123  skipCache.Add(entry.Name);
124 
125  _stream?.Dispose();
126  }
127  File.CacheFiles(skipCache);
128  }
129 
136  public virtual void Close() {
137  fileHandle?.Dispose();
138  if (File != null && File.IsOpen)
139  throw new IOException($"TModFile has open handles: {File.path}");
140  }
141 
149  public virtual bool LoadResource(string path, int length, Func<Stream> getStream) {
150  if (tModLoaderVersion < new Version(0, 11) && LoadResourceLegacy(path, length, getStream)) // TODO LoadResourceLegacy is marked obsolete
151  return false;
152 
153  string extension = Path.GetExtension(path).ToLower();
154  path = Path.ChangeExtension(path, null);
155  switch (extension) {
156  case ".png":
157  case ".rawimg":
158  if (!Main.dedServ)
159  LoadTexture(path, getStream(), extension == ".rawimg");
160  return true;
161  case ".wav":
162  case ".mp3":
163  case ".ogg":
164  //Main.engine == null would be more sensible, but only the waveBank fails on Linux when there is no audio hardware
165  if (Main.dedServ || Main.waveBank == null) { }
166  else if (path.Contains("Music/"))
167  musics[path] = LoadMusic(path, extension);
168  else
169  sounds[path] = LoadSound(getStream(), length, extension);
170  return true;
171  case ".xnb":
172  if (Main.dedServ) { }
173  else if (path.StartsWith("Fonts/"))
174  fonts[path] = Main.instance.OurLoad<DynamicSpriteFont>("tmod:"+Name+"/"+path);
175  else if (path.StartsWith("Effects/"))
176  effects[path] = Main.ShaderContentManager.Load<Effect>("tmod:"+Name+"/"+path);
177  else
178  throw new ResourceLoadException(Language.GetTextValue("tModLoader.LoadErrorUnknownXNBFileHint", path));
179  return true;
180  }
181 
182  return false;
183  }
184 
185  [Obsolete]
186  private bool LoadResourceLegacy(string path, int length, Func<Stream> getStream) {
187  using (var stream = getStream()) {
188  LoadResourceFromStream(path, length, new BinaryReader(stream));
189  return stream.Position > 0;
190  }
191  }
192 
193  [Obsolete("Use LoadResource instead", true)]
194  public virtual void LoadResourceFromStream(string path, int len, BinaryReader reader) {
195  }
196 
197  internal void AutoloadConfig()
198  {
199  if (Code == null)
200  return;
201 
202  // TODO: Attribute to specify ordering of ModConfigs
203  foreach (Type type in Code.GetTypes().OrderBy(type => type.FullName))
204  {
205  if (type.IsAbstract)
206  {
207  continue;
208  }
209  if (type.IsSubclassOf(typeof(ModConfig)))
210  {
211  var mc = (ModConfig)Activator.CreateInstance(type);
212  // Skip loading ClientSide on Main.dedServ?
213  if (mc.Mode == ConfigScope.ServerSide && (Side == ModSide.Client || Side == ModSide.NoSync)) // Client and NoSync mods can't have ServerSide ModConfigs. Server can, but won't be synced.
214  throw new Exception($"The ModConfig {mc.Name} can't be loaded because the config is ServerSide but this Mods ModSide isn't Both or Server");
215  if (mc.Mode == ConfigScope.ClientSide && Side == ModSide.Server) // Doesn't make sense.
216  throw new Exception($"The ModConfig {mc.Name} can't be loaded because the config is ClientSide but this Mods ModSide is Server");
217  mc.mod = this;
218  var name = type.Name;
219  if (mc.Autoload(ref name))
220  AddConfig(name, mc);
221  }
222  }
223  }
224 
225  public void AddConfig(string name, ModConfig mc)
226  {
227  mc.Name = name;
228  mc.mod = this;
229 
230  ConfigManager.Add(mc);
231  ContentInstance.Register(mc);
232  }
233 
240  public void AddItem(string name, ModItem item) {
241  if (!loading)
242  throw new Exception(Language.GetTextValue("tModLoader.LoadErrorAddItemOnlyInLoad"));
243 
244  if (items.ContainsKey(name))
245  throw new Exception(Language.GetTextValue("tModLoader.LoadError2ModItemSameName", name));
246 
247  item.mod = this;
248  item.Name = name;
249  item.DisplayName = GetOrCreateTranslation(string.Format("Mods.{0}.ItemName.{1}", Name, name));
250  item.Tooltip = GetOrCreateTranslation(string.Format("Mods.{0}.ItemTooltip.{1}", Name, name), true);
251 
252  item.item.ResetStats(ItemLoader.ReserveItemID());
253  item.item.modItem = item;
254 
255  items[name] = item;
256  ItemLoader.items.Add(item);
257  ContentInstance.Register(item);
258  }
259 
265  public ModItem GetItem(string name) => items.TryGetValue(name, out var item) ? item : null;
266 
272  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
273  public T GetItem<T>() where T : ModItem => ModContent.GetInstance<T>();
274 
280  public int ItemType(string name) => GetItem(name)?.item.type ?? 0;
281 
287  [Obsolete("Use ModContent.ItemType<T> instead", true)]
288  public int ItemType<T>() where T : ModItem => ModContent.ItemType<T>();
289 
295  public void AddGlobalItem(string name, GlobalItem globalItem) {
296  if (!loading)
297  throw new Exception("AddGlobalItem can only be called from Mod.Load or Mod.Autoload");
298 
299  ItemLoader.VerifyGlobalItem(globalItem);
300 
301  globalItem.mod = this;
302  globalItem.Name = name;
303 
304  globalItems[name] = globalItem;
305  globalItem.index = ItemLoader.globalItems.Count;
306  ItemLoader.globalIndexes[Name + ':' + name] = ItemLoader.globalItems.Count;
307  if (ItemLoader.globalIndexesByType.ContainsKey(globalItem.GetType())) {
308  ItemLoader.globalIndexesByType[globalItem.GetType()] = -1;
309  }
310  else {
311  ItemLoader.globalIndexesByType[globalItem.GetType()] = ItemLoader.globalItems.Count;
312  }
313  ItemLoader.globalItems.Add(globalItem);
314  ContentInstance.Register(globalItem);
315  }
316 
322  public GlobalItem GetGlobalItem(string name) => globalItems.TryGetValue(name, out var globalItem) ? globalItem : null;
323 
329  public T GetGlobalItem<T>() where T : GlobalItem => (T)GetGlobalItem(typeof(T).Name);
330 
345  public int AddEquipTexture(ModItem item, EquipType type, string name, string texture,
346  string armTexture = "", string femaleTexture = "") {
347  return AddEquipTexture(new EquipTexture(), item, type, name, texture, armTexture, femaleTexture);
348  }
349 
363  public int AddEquipTexture(EquipTexture equipTexture, ModItem item, EquipType type, string name, string texture,
364  string armTexture = "", string femaleTexture = "") {
365  if (!loading)
366  throw new Exception("AddEquipTexture can only be called from Mod.Load or Mod.Autoload");
367 
368  ModContent.GetTexture(texture); //ensure texture exists
369 
370  equipTexture.Texture = texture;
371  equipTexture.mod = this;
372  equipTexture.Name = name;
373  equipTexture.Type = type;
374  equipTexture.item = item;
375  int slot = equipTexture.Slot = EquipLoader.ReserveEquipID(type);
376 
377  EquipLoader.equipTextures[type][slot] = equipTexture;
378  equipTextures[Tuple.Create(name, type)] = equipTexture;
379 
380  if (type == EquipType.Body) {
381  if (femaleTexture == null || !ModContent.TextureExists(femaleTexture))
382  femaleTexture = texture;
383  EquipLoader.femaleTextures[slot] = femaleTexture;
384 
385  ModContent.GetTexture(armTexture); //ensure texture exists
386  EquipLoader.armTextures[slot] = armTexture;
387  }
388  if (item != null) {
389  IDictionary<EquipType, int> slots;
390  if (!EquipLoader.idToSlot.TryGetValue(item.item.type, out slots))
391  EquipLoader.idToSlot[item.item.type] = slots = new Dictionary<EquipType, int>();
392 
393  slots[type] = slot;
394  if (type == EquipType.Head || type == EquipType.Body || type == EquipType.Legs)
395  EquipLoader.slotToId[type][slot] = item.item.type;
396  }
397  return slot;
398  }
399 
406  public EquipTexture GetEquipTexture(string name, EquipType type) =>
407  equipTextures.TryGetValue(Tuple.Create(name, type), out var texture) ? texture : null;
408 
415  public int GetEquipSlot(string name, EquipType type) => GetEquipTexture(name, type)?.Slot ?? -1;
416 
423  public sbyte GetAccessorySlot(string name, EquipType type) => (sbyte)GetEquipSlot(name, type);
424 
431  public void AddPrefix(string name, ModPrefix prefix) {
432  if (!loading)
433  throw new Exception("AddPrefix can only be called from Mod.Load or Mod.Autoload");
434 
435  if (prefixes.ContainsKey(name))
436  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.");
437 
438  prefix.mod = this;
439  prefix.Name = name;
440  prefix.DisplayName = GetOrCreateTranslation(string.Format("Mods.{0}.Prefix.{1}", Name, name));
441  prefix.Type = ModPrefix.ReservePrefixID();
442 
443  prefixes[name] = prefix;
444  ModPrefix.prefixes.Add(prefix);
445  ModPrefix.categoryPrefixes[prefix.Category].Add(prefix);
446  ContentInstance.Register(prefix);
447  }
448 
454  public ModPrefix GetPrefix(string name) => prefixes.TryGetValue(name, out var prefix) ? prefix : null;
455 
461  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
462  public T GetPrefix<T>() where T : ModPrefix => ModContent.GetInstance<T>();
463 
469  public byte PrefixType(string name) => GetPrefix(name)?.Type ?? 0;
470 
476  [Obsolete("Use ModContent.PrefixType<T> instead", true)]
477  public byte PrefixType<T>() where T : ModPrefix => ModContent.PrefixType<T>();
478 
485  public void AddDust(string name, ModDust dust, string texture = "") {
486  if (!loading)
487  throw new Exception("AddDust can only be called from Mod.Load or Mod.Autoload");
488 
489  dust.mod = this;
490  dust.Name = name;
491  dust.Type = ModDust.ReserveDustID();
492  dust.Texture = !string.IsNullOrEmpty(texture) ? ModContent.GetTexture(texture) : Main.dustTexture;
493 
494  dusts[name] = dust;
495  ModDust.dusts.Add(dust);
496  ContentInstance.Register(dust);
497  }
498 
504  public ModDust GetDust(string name) => dusts.TryGetValue(name, out var dust) ? dust : null;
505 
511  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
512  public T GetDust<T>() where T : ModDust => ModContent.GetInstance<T>();
513 
519  public int DustType(string name) => GetDust(name)?.Type ?? 0;
520 
526  [Obsolete("Use ModContent.DustType<T> instead", true)]
527  public int DustType<T>() where T : ModDust => ModContent.DustType<T>();
528 
535  public void AddTile(string name, ModTile tile, string texture) {
536  if (!loading)
537  throw new Exception("AddItem can only be called from Mod.Load or Mod.Autoload");
538 
539  if (tiles.ContainsKey(name))
540  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.");
541 
542  tile.mod = this;
543  tile.Name = name;
544  tile.Type = (ushort)TileLoader.ReserveTileID();
545  tile.texture = texture;
546 
547  tiles[name] = tile;
548  TileLoader.tiles.Add(tile);
549  ContentInstance.Register(tile);
550  }
551 
557  public ModTile GetTile(string name) => tiles.TryGetValue(name, out var tile) ? tile : null;
558 
564  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
565  public T GetTile<T>() where T : ModTile => ModContent.GetInstance<T>();
566 
572  public int TileType(string name) => GetTile(name)?.Type ?? 0;
573 
579  [Obsolete("Use ModContent.TileType<T> instead", true)]
580  public int TileType<T>() where T : ModTile => ModContent.TileType<T>();
581 
587  public void AddGlobalTile(string name, GlobalTile globalTile) {
588  if (!loading)
589  throw new Exception("AddGlobalTile can only be called from Mod.Load or Mod.Autoload");
590 
591  globalTile.mod = this;
592  globalTile.Name = name;
593 
594  globalTiles[name] = globalTile;
595  TileLoader.globalTiles.Add(globalTile);
596  ContentInstance.Register(globalTile);
597  }
598 
604  public GlobalTile GetGlobalTile(string name) => globalTiles.TryGetValue(name, out var globalTile) ? globalTile : null;
605 
611  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
612  public T GetGlobalTile<T>() where T : GlobalTile => ModContent.GetInstance<T>();
613 
617  public void AddTileEntity(string name, ModTileEntity entity) {
618  if (!loading)
619  throw new Exception("AddTileEntity can only be called from Mod.Load or Mod.Autoload");
620 
621  int id = ModTileEntity.ReserveTileEntityID();
622  entity.mod = this;
623  entity.Name = name;
624  entity.Type = id;
625  entity.type = (byte)id;
626 
627  tileEntities[name] = entity;
628  ModTileEntity.tileEntities.Add(entity);
629  ContentInstance.Register(entity);
630  }
631 
637  public ModTileEntity GetTileEntity(string name) =>
638  tileEntities.TryGetValue(name, out var tileEntity) ? tileEntity : null;
639 
645  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
646  public T GetTileEntity<T>() where T : ModTileEntity => ModContent.GetInstance<T>();
647 
653  public int TileEntityType(string name) => GetTileEntity(name)?.Type ?? -1;
654 
660  [Obsolete("Use ModContent.TileEntityType<T> instead", true)]
661  public int TileEntityType<T>() where T : ModTileEntity => ModContent.TileEntityType<T>();
662 
669  public void AddWall(string name, ModWall wall, string texture) {
670  if (!loading)
671  throw new Exception("AddWall can only be called from Mod.Load or Mod.Autoload");
672 
673  wall.mod = this;
674  wall.Name = name;
675  wall.Type = (ushort)WallLoader.ReserveWallID();
676  wall.texture = texture;
677 
678  walls[name] = wall;
679  WallLoader.walls.Add(wall);
680  ContentInstance.Register(wall);
681  }
682 
688  public ModWall GetWall(string name) => walls.TryGetValue(name, out var wall) ? wall : null;
689 
690  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
691  public T GetWall<T>() where T : ModWall => ModContent.GetInstance<T>();
692 
698  public int WallType(string name) => GetWall(name)?.Type ?? 0;
699 
705  [Obsolete("Use ModContent.WallType<T> instead", true)]
706  public int WallType<T>() where T : ModWall => ModContent.WallType<T>();
707 
713  public void AddGlobalWall(string name, GlobalWall globalWall) {
714  if (!loading)
715  throw new Exception("AddGlobalWall can only be called from Mod.Load or Mod.Autoload");
716 
717  globalWall.mod = this;
718  globalWall.Name = name;
719 
720  globalWalls[name] = globalWall;
721  WallLoader.globalWalls.Add(globalWall);
722  ContentInstance.Register(globalWall);
723  }
724 
730  public GlobalWall GetGlobalWall(string name) => globalWalls.TryGetValue(name, out var globalWall) ? globalWall : null;
731 
732  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
733  public T GetGlobalWall<T>() where T : GlobalWall => ModContent.GetInstance<T>();
734 
740  public void AddProjectile(string name, ModProjectile projectile) {
741  if (!loading)
742  throw new Exception("AddProjectile can only be called from Mod.Load or Mod.Autoload");
743 
744  if (projectiles.ContainsKey(name))
745  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.");
746 
747  projectile.mod = this;
748  projectile.Name = name;
749  projectile.projectile.type = ProjectileLoader.ReserveProjectileID();
750  projectile.DisplayName = GetOrCreateTranslation(string.Format("Mods.{0}.ProjectileName.{1}", Name, name));
751 
752  projectiles[name] = projectile;
753  ProjectileLoader.projectiles.Add(projectile);
754  ContentInstance.Register(projectile);
755  }
756 
762  public ModProjectile GetProjectile(string name) => projectiles.TryGetValue(name, out var proj) ? proj : null;
763 
764  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
765  public T GetProjectile<T>() where T : ModProjectile => ModContent.GetInstance<T>();
766 
772  public int ProjectileType(string name) => GetProjectile(name)?.projectile.type ?? 0;
773 
779  [Obsolete("Use ModContent.ProjectileType<T> instead", true)]
780  public int ProjectileType<T>() where T : ModProjectile => ModContent.ProjectileType<T>();
781 
787  public void AddGlobalProjectile(string name, GlobalProjectile globalProjectile) {
788  if (!loading)
789  throw new Exception("AddGlobalProjectile can only be called from Mod.Load or Mod.Autoload");
790 
791  ProjectileLoader.VerifyGlobalProjectile(globalProjectile);
792 
793  globalProjectile.mod = this;
794  globalProjectile.Name = name;
795 
796  globalProjectiles[name] = globalProjectile;
797  globalProjectile.index = ProjectileLoader.globalProjectiles.Count;
798  ProjectileLoader.globalIndexes[Name + ':' + name] = ProjectileLoader.globalProjectiles.Count;
799  if (ProjectileLoader.globalIndexesByType.ContainsKey(globalProjectile.GetType())) {
800  ProjectileLoader.globalIndexesByType[globalProjectile.GetType()] = -1;
801  }
802  else {
803  ProjectileLoader.globalIndexesByType[globalProjectile.GetType()] = ProjectileLoader.globalProjectiles.Count;
804  }
805  ProjectileLoader.globalProjectiles.Add(globalProjectile);
806  ContentInstance.Register(globalProjectile);
807  }
808 
814  public GlobalProjectile GetGlobalProjectile(string name) => globalProjectiles.TryGetValue(name, out var globalProj) ? globalProj : null;
815 
816  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
817  public T GetGlobalProjectile<T>() where T : GlobalProjectile => ModContent.GetInstance<T>();
818 
824  public void AddNPC(string name, ModNPC npc) {
825  if (!loading)
826  throw new Exception("AddNPC can only be called from Mod.Load or Mod.Autoload");
827 
828  if (npcs.ContainsKey(name))
829  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.");
830 
831  npc.mod = this;
832  npc.Name = name;
833  npc.npc.type = NPCLoader.ReserveNPCID();
834  npc.DisplayName = GetOrCreateTranslation(string.Format("Mods.{0}.NPCName.{1}", Name, name));
835 
836  npcs[name] = npc;
837  NPCLoader.npcs.Add(npc);
838  ContentInstance.Register(npc);
839  }
840 
846  public ModNPC GetNPC(string name) => npcs.TryGetValue(name, out var npc) ? npc : null;
847 
848  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
849  public T GetNPC<T>() where T : ModNPC => ModContent.GetInstance<T>();
850 
856  public int NPCType(string name) => GetNPC(name)?.npc.type ?? 0;
857 
863  [Obsolete("Use ModContent.NPCType<T> instead", true)]
864  public int NPCType<T>() where T : ModNPC => ModContent.NPCType<T>();
865 
871  public void AddGlobalNPC(string name, GlobalNPC globalNPC) {
872  if (!loading)
873  throw new Exception("AddGlobalNPC can only be called from Mod.Load or Mod.Autoload");
874 
875  NPCLoader.VerifyGlobalNPC(globalNPC);
876 
877  globalNPC.mod = this;
878  globalNPC.Name = name;
879 
880  globalNPCs[name] = globalNPC;
881  globalNPC.index = NPCLoader.globalNPCs.Count;
882  NPCLoader.globalIndexes[Name + ':' + name] = NPCLoader.globalNPCs.Count;
883  if (NPCLoader.globalIndexesByType.ContainsKey(globalNPC.GetType())) {
884  NPCLoader.globalIndexesByType[globalNPC.GetType()] = -1;
885  }
886  else {
887  NPCLoader.globalIndexesByType[globalNPC.GetType()] = NPCLoader.globalNPCs.Count;
888  }
889  NPCLoader.globalNPCs.Add(globalNPC);
890  ContentInstance.Register(globalNPC);
891  }
892 
898  public GlobalNPC GetGlobalNPC(string name) => globalNPCs.TryGetValue(name, out var globalNPC) ? globalNPC : null;
899 
900  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
901  public T GetGlobalNPC<T>() where T : GlobalNPC => ModContent.GetInstance<T>();
902 
909  public void AddNPCHeadTexture(int npcType, string texture) {
910  if (!loading)
911  throw new Exception("AddNPCHeadTexture can only be called from Mod.Load or Mod.Autoload");
912 
913  int slot = NPCHeadLoader.ReserveHeadSlot();
914  NPCHeadLoader.heads[texture] = slot;
915  if (!Main.dedServ) {
916  ModContent.GetTexture(texture);
917  }
918  /*else if (Main.dedServ && !(ModLoader.FileExists(texture + ".png") || ModLoader.FileExists(texture + ".rawimg")))
919  {
920  throw new MissingResourceException(texture);
921  }*/
922  NPCHeadLoader.npcToHead[npcType] = slot;
923  NPCHeadLoader.headToNPC[slot] = npcType;
924  }
925 
931  public void AddBossHeadTexture(string texture, int npcType = -1) {
932  if (!loading)
933  throw new Exception("AddBossHeadTexture can only be called from Mod.Load or Mod.Autoload");
934 
935  int slot = NPCHeadLoader.ReserveBossHeadSlot(texture);
936  NPCHeadLoader.bossHeads[texture] = slot;
937  ModContent.GetTexture(texture);
938  if (npcType >= 0) {
939  NPCHeadLoader.npcToBossHead[npcType] = slot;
940  }
941  }
942 
948  public void AddPlayer(string name, ModPlayer player) {
949  if (!loading)
950  throw new Exception("AddPlayer can only be called from Mod.Load or Mod.Autoload");
951 
952  player.mod = this;
953  player.Name = name;
954 
955  players[name] = player;
956  PlayerHooks.Add(player);
957  ContentInstance.Register(player);
958  }
959 
965  public ModPlayer GetPlayer(string name) => players.TryGetValue(name, out var player) ? player : null;
966 
967  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
968  public T GetPlayer<T>() where T : ModPlayer => ModContent.GetInstance<T>();
969 
976  public void AddBuff(string name, ModBuff buff, string texture) {
977  if (!loading)
978  throw new Exception("AddBuff can only be called from Mod.Load or Mod.Autoload");
979 
980  if (buffs.ContainsKey(name))
981  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.");
982 
983  buff.mod = this;
984  buff.Name = name;
985  buff.Type = BuffLoader.ReserveBuffID();
986  buff.texture = texture;
987  buff.DisplayName = GetOrCreateTranslation(string.Format("Mods.{0}.BuffName.{1}", Name, name));
988  buff.Description = GetOrCreateTranslation(string.Format("Mods.{0}.BuffDescription.{1}", Name, name));
989 
990  buffs[name] = buff;
991  BuffLoader.buffs.Add(buff);
992  ContentInstance.Register(buff);
993  }
994 
1000  public ModBuff GetBuff(string name) => buffs.TryGetValue(name, out var buff) ? buff : null;
1001 
1002  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
1003  public T GetBuff<T>() where T : ModBuff => ModContent.GetInstance<T>();
1004 
1010  public int BuffType(string name) => GetBuff(name)?.Type ?? 0;
1011 
1017  [Obsolete("Use ModContent.BuffType<T> instead", true)]
1018  public int BuffType<T>() where T : ModBuff => ModContent.BuffType<T>();
1019 
1025  public void AddGlobalBuff(string name, GlobalBuff globalBuff) {
1026  globalBuff.mod = this;
1027  globalBuff.Name = name;
1028 
1029  globalBuffs[name] = globalBuff;
1030  BuffLoader.globalBuffs.Add(globalBuff);
1031  ContentInstance.Register(globalBuff);
1032  }
1033 
1039  public GlobalBuff GetGlobalBuff(string name) => globalBuffs.TryGetValue(name, out var globalBuff) ? globalBuff : null;
1040 
1041  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
1042  public T GetGlobalBuff<T>() where T : GlobalBuff => ModContent.GetInstance<T>();
1043 
1051  public void AddMount(string name, ModMountData mount, string texture,
1052  IDictionary<MountTextureType, string> extraTextures = null) {
1053  if (!loading)
1054  throw new Exception("AddMount can only be called from Mod.Load or Mod.Autoload");
1055 
1056  if (Mount.mounts == null || Mount.mounts.Length == MountID.Count)
1057  Mount.Initialize();
1058 
1059  mount.mod = this;
1060  mount.Name = name;
1061  mount.Type = MountLoader.ReserveMountID();
1062  mount.texture = texture;
1063 
1064  mountDatas[name] = mount;
1065  MountLoader.mountDatas[mount.Type] = mount;
1066  ContentInstance.Register(mount);
1067 
1068  if (extraTextures == null)
1069  return;
1070 
1071  foreach (var entry in extraTextures) {
1072  if (!ModContent.TextureExists(entry.Value))
1073  continue;
1074 
1075  Texture2D extraTexture = ModContent.GetTexture(entry.Value);
1076  switch (entry.Key) {
1077  case MountTextureType.Back:
1078  mount.mountData.backTexture = extraTexture;
1079  break;
1080  case MountTextureType.BackGlow:
1081  mount.mountData.backTextureGlow = extraTexture;
1082  break;
1083  case MountTextureType.BackExtra:
1084  mount.mountData.backTextureExtra = extraTexture;
1085  break;
1086  case MountTextureType.BackExtraGlow:
1087  mount.mountData.backTextureExtraGlow = extraTexture;
1088  break;
1089  case MountTextureType.Front:
1090  mount.mountData.frontTexture = extraTexture;
1091  break;
1092  case MountTextureType.FrontGlow:
1093  mount.mountData.frontTextureGlow = extraTexture;
1094  break;
1095  case MountTextureType.FrontExtra:
1096  mount.mountData.frontTextureExtra = extraTexture;
1097  break;
1098  case MountTextureType.FrontExtraGlow:
1099  mount.mountData.frontTextureExtraGlow = extraTexture;
1100  break;
1101  }
1102  }
1103  }
1104 
1110  public ModMountData GetMount(string name) => mountDatas.TryGetValue(name, out var modMountData) ? modMountData : null;
1111 
1112  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
1113  public T GetMount<T>() where T : ModMountData => ModContent.GetInstance<T>();
1114 
1120  public int MountType(string name) => GetMount(name)?.Type ?? 0;
1121 
1127  [Obsolete("Use ModContent.MountType<T> instead", true)]
1128  public int MountType<T>() where T : ModMountData => ModContent.MountType<T>();
1129 
1135  public void AddModWorld(string name, ModWorld modWorld) {
1136  if (!loading)
1137  throw new Exception("AddModWorld can only be called from Mod.Load or Mod.Autoload");
1138 
1139  modWorld.mod = this;
1140  modWorld.Name = name;
1141 
1142  worlds[name] = modWorld;
1143  WorldHooks.Add(modWorld);
1144  ContentInstance.Register(modWorld);
1145  }
1146 
1152  public ModWorld GetModWorld(string name) => worlds.TryGetValue(name, out var world) ? world : null;
1153 
1159  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
1160  public T GetModWorld<T>() where T : ModWorld => ModContent.GetInstance<T>();
1161 
1167  public void AddUgBgStyle(string name, ModUgBgStyle ugBgStyle) {
1168  if (!loading)
1169  throw new Exception("AddUgBgStyle can only be called from Mod.Load or Mod.Autoload");
1170 
1171  ugBgStyle.mod = this;
1172  ugBgStyle.Name = name;
1173  ugBgStyle.Slot = UgBgStyleLoader.ReserveBackgroundSlot();
1174 
1175  ugBgStyles[name] = ugBgStyle;
1176  UgBgStyleLoader.ugBgStyles.Add(ugBgStyle);
1177  ContentInstance.Register(ugBgStyle);
1178  }
1179 
1185  public ModUgBgStyle GetUgBgStyle(string name) => ugBgStyles.TryGetValue(name, out var bgStyle) ? bgStyle : null;
1186 
1187  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
1188  public T GetUgBgStyle<T>() where T : ModUgBgStyle => ModContent.GetInstance<T>();
1189 
1195  public void AddSurfaceBgStyle(string name, ModSurfaceBgStyle surfaceBgStyle) {
1196  if (!loading)
1197  throw new Exception("AddSurfaceBgStyle can only be called from Mod.Load or Mod.Autoload");
1198 
1199  surfaceBgStyle.mod = this;
1200  surfaceBgStyle.Name = name;
1201  surfaceBgStyle.Slot = SurfaceBgStyleLoader.ReserveBackgroundSlot();
1202 
1203  surfaceBgStyles[name] = surfaceBgStyle;
1204  SurfaceBgStyleLoader.surfaceBgStyles.Add(surfaceBgStyle);
1205  ContentInstance.Register(surfaceBgStyle);
1206  }
1207 
1213  public ModSurfaceBgStyle GetSurfaceBgStyle(string name) => surfaceBgStyles.TryGetValue(name, out var bgStyle) ? bgStyle : null;
1214 
1215  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
1216  public T GetSurfaceBgStyle<T>() where T : ModSurfaceBgStyle => ModContent.GetInstance<T>();
1217 
1223  public int GetSurfaceBgStyleSlot(string name) => GetSurfaceBgStyle(name)?.Slot ?? -1;
1224 
1225  public int GetSurfaceBgStyleSlot<T>() where T : ModSurfaceBgStyle => GetSurfaceBgStyleSlot(typeof(T).Name);
1226 
1232  public void AddGlobalBgStyle(string name, GlobalBgStyle globalBgStyle) {
1233  if (!loading)
1234  throw new Exception("AddGlobalBgStyle can only be called from Mod.Load or Mod.Autoload");
1235 
1236  globalBgStyle.mod = this;
1237  globalBgStyle.Name = name;
1238 
1239  globalBgStyles[name] = globalBgStyle;
1240  GlobalBgStyleLoader.globalBgStyles.Add(globalBgStyle);
1241  ContentInstance.Register(globalBgStyle);
1242  }
1243 
1249  public GlobalBgStyle GetGlobalBgStyle(string name) => globalBgStyles.TryGetValue(name, out var bgStyle) ? bgStyle : null;
1250 
1251  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
1252  public T GetGlobalBgStyle<T>() where T : GlobalBgStyle => ModContent.GetInstance<T>();
1253 
1261  public void AddWaterStyle(string name, ModWaterStyle waterStyle, string texture, string blockTexture) {
1262  if (!loading)
1263  throw new Exception("AddWaterStyle can only be called from Mod.Load or Mod.Autoload");
1264 
1265  waterStyle.mod = this;
1266  waterStyle.Name = name;
1267  waterStyle.Type = WaterStyleLoader.ReserveStyle();
1268  waterStyle.texture = texture;
1269  waterStyle.blockTexture = blockTexture;
1270 
1271  waterStyles[name] = waterStyle;
1272  WaterStyleLoader.waterStyles.Add(waterStyle);
1273  ContentInstance.Register(waterStyle);
1274  }
1275 
1281  public ModWaterStyle GetWaterStyle(string name) => waterStyles.TryGetValue(name, out var waterStyle) ? waterStyle : null;
1282 
1283  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
1284  public T GetWaterStyle<T>() where T : ModWaterStyle => ModContent.GetInstance<T>();
1285 
1292  public void AddWaterfallStyle(string name, ModWaterfallStyle waterfallStyle, string texture) {
1293  if (!loading)
1294  throw new Exception("AddWaterfallStyle can only be called from Mod.Load or Mod.Autoload");
1295 
1296  waterfallStyle.mod = this;
1297  waterfallStyle.Name = name;
1298  waterfallStyle.Type = WaterfallStyleLoader.ReserveStyle();
1299  waterfallStyle.texture = texture;
1300 
1301  waterfallStyles[name] = waterfallStyle;
1302  WaterfallStyleLoader.waterfallStyles.Add(waterfallStyle);
1303  ContentInstance.Register(waterfallStyle);
1304  }
1305 
1311  public ModWaterfallStyle GetWaterfallStyle(string name) => waterfallStyles.TryGetValue(name, out var waterfallStyle) ? waterfallStyle : null;
1312 
1313  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
1314  public T GetWaterfallStyle<T>() where T : ModWaterfallStyle => ModContent.GetInstance<T>();
1315 
1321  public int GetWaterfallStyleSlot(string name) => GetWaterfallStyle(name)?.Type ?? -1;
1322 
1323  public int GetWaterfallStyleSlot<T>() where T : ModWaterfallStyle => GetWaterfallStyleSlot(typeof(T).Name);
1324 
1330  public void AddGore(string texture, ModGore modGore = null) {
1331  if (!loading)
1332  throw new Exception("AddGore can only be called from Mod.Load or Mod.Autoload");
1333 
1334  int id = ModGore.ReserveGoreID();
1335  ModGore.gores[texture] = id;
1336  if (modGore != null) {
1337  ModGore.modGores[id] = modGore;
1338  ContentInstance.Register(modGore);
1339  }
1340  }
1341 
1347  public int GetGoreSlot(string name) => ModGore.GetGoreSlot(Name + '/' + name);
1348 
1354  public int GetGoreSlot<T>() where T : ModGore => GetGoreSlot(typeof(T).Name);
1355 
1362  public void AddSound(SoundType type, string soundPath, ModSound modSound = null) {
1363  if (!loading)
1364  throw new Exception("AddSound can only be called from Mod.Load or Mod.Autoload");
1365  int id = SoundLoader.ReserveSoundID(type);
1366  SoundLoader.sounds[type][soundPath] = id;
1367  if (modSound != null) {
1368  SoundLoader.modSounds[type][id] = modSound;
1369  modSound.sound = ModContent.GetSound(soundPath);
1370  }
1371  }
1372 
1379  public int GetSoundSlot(SoundType type, string name) => SoundLoader.GetSoundSlot(type, Name + '/' + name);
1380 
1387  public LegacySoundStyle GetLegacySoundSlot(SoundType type, string name) => SoundLoader.GetLegacySoundSlot(type, Name + '/' + name);
1388 
1393  public void AddBackgroundTexture(string texture) {
1394  if (!loading)
1395  throw new Exception("AddBackgroundTexture can only be called from Mod.Load or Mod.Autoload");
1396 
1397  BackgroundTextureLoader.backgrounds[texture] = BackgroundTextureLoader.ReserveBackgroundSlot();
1398  ModContent.GetTexture(texture);
1399  }
1400 
1406  public int GetBackgroundSlot(string name) => BackgroundTextureLoader.GetBackgroundSlot(Name + '/' + name);
1407 
1413  public void AddGlobalRecipe(string name, GlobalRecipe globalRecipe) {
1414  if (!loading)
1415  throw new Exception("AddGlobalRecipe can only be called from Mod.Load or Mod.Autoload");
1416 
1417  globalRecipe.mod = this;
1418  globalRecipe.Name = name;
1419 
1420  globalRecipes[name] = globalRecipe;
1421  RecipeHooks.Add(globalRecipe);
1422  ContentInstance.Register(globalRecipe);
1423  }
1424 
1430  public GlobalRecipe GetGlobalRecipe(string name) => globalRecipes.TryGetValue(name, out var globalRecipe) ? globalRecipe : null;
1431 
1432  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
1433  public T GetGlobalRecipe<T>() where T : GlobalRecipe => ModContent.GetInstance<T>();
1434 
1438  public void AddCommand(string name, ModCommand mc) {
1439  if (!loading)
1440  throw new Exception("AddCommand can only be called from Mod.Load or Mod.Autoload");
1441 
1442  mc.mod = this;
1443  mc.Name = name;
1444  CommandManager.Add(mc);
1445  }
1446 
1475  public void AddMusicBox(int musicSlot, int itemType, int tileType, int tileFrameY = 0) {
1476  if (!loading)
1477  throw new Exception("AddMusicBox can only be called from Mod.Load or Mod.Autoload");
1478 
1479  if (Main.waveBank == null)
1480  return;
1481 
1482  if (musicSlot < Main.maxMusic) {
1483  throw new ArgumentOutOfRangeException("Cannot assign music box to vanilla music ID " + musicSlot);
1484  }
1485  if (musicSlot >= SoundLoader.SoundCount(SoundType.Music)) {
1486  throw new ArgumentOutOfRangeException("Music ID " + musicSlot + " does not exist");
1487  }
1488  if (itemType < ItemID.Count) {
1489  throw new ArgumentOutOfRangeException("Cannot assign music box to vanilla item ID " + itemType);
1490  }
1491  if (ItemLoader.GetItem(itemType) == null) {
1492  throw new ArgumentOutOfRangeException("Item ID " + itemType + " does not exist");
1493  }
1494  if (tileType < TileID.Count) {
1495  throw new ArgumentOutOfRangeException("Cannot assign music box to vanilla tile ID " + tileType);
1496  }
1497  if (TileLoader.GetTile(tileType) == null) {
1498  throw new ArgumentOutOfRangeException("Tile ID " + tileType + " does not exist");
1499  }
1500  if (SoundLoader.musicToItem.ContainsKey(musicSlot)) {
1501  throw new ArgumentException("Music ID " + musicSlot + " has already been assigned a music box");
1502  }
1503  if (SoundLoader.itemToMusic.ContainsKey(itemType)) {
1504  throw new ArgumentException("Item ID " + itemType + " has already been assigned a music");
1505  }
1506  if (!SoundLoader.tileToMusic.ContainsKey(tileType)) {
1507  SoundLoader.tileToMusic[tileType] = new Dictionary<int, int>();
1508  }
1509  if (SoundLoader.tileToMusic[tileType].ContainsKey(tileFrameY)) {
1510  string message = "Y-frame " + tileFrameY + " of tile type " + tileType + " has already been assigned a music";
1511  throw new ArgumentException(message);
1512  }
1513  if (tileFrameY % 36 != 0) {
1514  throw new ArgumentException("Y-frame must be divisible by 36");
1515  }
1516  SoundLoader.musicToItem[musicSlot] = itemType;
1517  SoundLoader.itemToMusic[itemType] = musicSlot;
1518  SoundLoader.tileToMusic[tileType][tileFrameY] = musicSlot;
1519  }
1520 
1527  public ModHotKey RegisterHotKey(string name, string defaultKey) {
1528  if (!loading)
1529  throw new Exception("RegisterHotKey can only be called from Mod.Load or Mod.Autoload");
1530 
1531  return HotKeyLoader.RegisterHotKey(new ModHotKey(this, name, defaultKey));
1532  }
1533 
1538  public ModTranslation CreateTranslation(string key) =>
1539  new ModTranslation(string.Format("Mods.{0}.{1}", Name, key));
1540 
1544  public void AddTranslation(ModTranslation translation) {
1545  translations[translation.Key] = translation;
1546  }
1547 
1548  internal ModTranslation GetOrCreateTranslation(string key, bool defaultEmpty = false) {
1549  key = key.Replace(" ", "_");
1550  return translations.TryGetValue(key, out var translation) ? translation : new ModTranslation(key, defaultEmpty);
1551  }
1552 
1558  public byte[] GetFileBytes(string name) => File?.GetBytes(name);
1559 
1565  public Stream GetFileStream(string name, bool newFileStream = false) => File?.GetStream(name, newFileStream);
1566 
1572  public bool FileExists(string name) => File != null && File.HasFile(name);
1573 
1578  public Texture2D GetTexture(string name) {
1579  if (!textures.TryGetValue(name, out var t))
1580  throw new MissingResourceException(name, textures.Keys);
1581 
1582  return t;
1583  }
1584 
1590  public bool TextureExists(string name) => textures.ContainsKey(name);
1591 
1598  public void AddTexture(string name, Texture2D texture) {
1599  if (Main.dedServ)
1600  return;
1601 
1602  if (TextureExists(name))
1603  throw new Exception("Texture already exist: " + name);
1604 
1605  textures[name] = texture;
1606  }
1607 
1614  public SoundEffect GetSound(string name) {
1615  if (!sounds.TryGetValue(name, out var sound))
1616  throw new MissingResourceException(name);
1617 
1618  return sound;
1619  }
1620 
1626  public bool SoundExists(string name) => sounds.ContainsKey(name);
1627 
1634  public Music GetMusic(string name) {
1635  if (!musics.TryGetValue(name, out var music))
1636  throw new MissingResourceException(name);
1637 
1638  return music;
1639  }
1640 
1646  public bool MusicExists(string name) => musics.ContainsKey(name);
1647 
1652  public DynamicSpriteFont GetFont(string name) {
1653  if (!fonts.TryGetValue(name, out var font))
1654  throw new MissingResourceException(name);
1655 
1656  return font;
1657  }
1658 
1662  public bool FontExists(string name) => fonts.ContainsKey(name);
1663 
1668  public Effect GetEffect(string name) {
1669  if (!effects.TryGetValue(name, out var effect))
1670  throw new MissingResourceException(name);
1671 
1672  return effect;
1673  }
1674 
1678  public bool EffectExists(string name) => effects.ContainsKey(name);
1679 
1683  public virtual object Call(params object[] args) {
1684  return null;
1685  }
1686 
1693  public ModPacket GetPacket(int capacity = 256) {
1694  if (netID < 0)
1695  throw new Exception("Cannot get packet for " + Name + " because it does not exist on the other side");
1696 
1697  var p = new ModPacket(MessageID.ModPacket, capacity + 5);
1698  if (ModNet.NetModCount < 256)
1699  p.Write((byte)netID);
1700  else
1701  p.Write(netID);
1702 
1703  p.netID = netID;
1704  return p;
1705  }
1706 
1707  public ModConfig GetConfig(string name)
1708  {
1709  List<ModConfig> configs;
1710  if (ConfigManager.Configs.TryGetValue(this, out configs))
1711  {
1712  return configs.Single(x => x.Name == name);
1713  }
1714  return null;
1715  }
1716 
1717  [Obsolete("Use ModContent.GetInstance<T> instead", true)]
1718  public T GetConfig<T>() where T : ModConfig => (T)GetConfig(typeof(T).Name);
1719  }
1720 }
string Name
The name of this GlobalProjectile instance.
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:948
virtual void Unload()
This is called whenever this mod is unloaded from the game. Use it to undo changes that you&#39;ve made i...
Definition: Mod.cs:83
string Name
The name of this ModPlayer. Used for distinguishing between multiple ModPlayers added by a single Mod...
Definition: ModPlayer.cs:28
int Type
The ID of this type of dust.
Definition: ModDust.cs:47
void AddGlobalProjectile(string name, GlobalProjectile globalProjectile)
Adds the given GlobalProjectile instance to this mod with the provided name.
Definition: Mod.cs:787
void AddModWorld(string name, ModWorld modWorld)
Adds a ModWorld to this mod with the given name.
Definition: Mod.cs:1135
virtual void LoadResources()
Definition: Mod.cs:109
Represents a loaded hotkey. It is suggested to access the hotkey status only in ModPlayer.ProcessTriggers.
Definition: ModHotkey.cs:11
int Type
The index of this ModMountData in the Mount.mounts array.
Definition: ModMountData.cs:37
Texture2D Texture
The sprite sheet that this type of dust uses. Normally a sprite sheet will consist of a vertical alig...
Definition: ModDust.cs:31
void AddGlobalTile(string name, GlobalTile globalTile)
Adds the given GlobalTile instance to this mod with the provided name.
Definition: Mod.cs:587
int Slot
The ID of this underground background style.
A ModPlayer instance represents an extension of a Player instance. You can store fields in the ModPla...
Definition: ModPlayer.cs:15
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...
Definition: Mod.cs:1475
string Name
The internal name of this NPC.
Definition: ModNPC.cs:37
ModTranslation DisplayName
The translations for the display name of this NPC.
Definition: ModNPC.cs:45
string Name
The internal name of this waterfall style.
This class represents a type of tile that can be added by a mod. Only one instance of this class will...
Definition: ModTile.cs:12
int Type
The numeric type used to identify this kind of tile entity.
This class serves as a place for you to place all your properties and hooks for each NPC...
Definition: ModNPC.cs:14
ModTranslation Description
The translations of this buff&#39;s description.
Definition: ModBuff.cs:43
Each background style determines in its own way how exactly the background is drawn. This class serves as a collection of functions for above-ground backgrounds.
void AddNPCHeadTexture(int npcType, string texture)
Assigns a head texture to the given town NPC type.
Definition: Mod.cs:909
string Name
The internal name of this ModTileEntity.
This is the class that keeps track of all modded background textures and their slots/IDs.
Mod mod
The mod which has added this type of ModTile.
Definition: ModTile.cs:17
ModHotKey RegisterHotKey(string name, string defaultKey)
Registers a hotkey with a name and defaultKey. Use the returned ModHotKey to detect when buttons are ...
Definition: Mod.cs:1527
This serves as the central class from which projectile-related functions are carried out...
static int GetSoundSlot(SoundType type, string sound)
Returns the style (last parameter passed to Main.PlaySound) of the sound corresponding to the given S...
Definition: SoundLoader.cs:47
Mod mod
The mod that added this style of waterfall.
virtual object Call(params object[] args)
Used for weak inter-mod communication. This allows you to interact with other mods without having to ...
Definition: Mod.cs:1683
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:1330
Mod mod
The mod to which this GlobalWall belongs.
Definition: GlobalWall.cs:13
This is where all ModPlayer hooks are gathered and called.
Definition: PlayerHooks.cs:20
This is where all ModRecipe and GlobalRecipe hooks are gathered and called.
Definition: RecipeHooks.cs:9
Tile Entities are Entities tightly coupled with tiles, allowing the possibility of tiles to exhibit c...
static Texture2D GetTexture(string name)
Gets the texture with the specified name. The name is in the format of "ModFolder/OtherFolders/FileNa...
Definition: ModContent.cs:71
This serves as the central class from which ModUgBgStyle functions are supported and carried out...
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:824
Mod mod
That mod that added this global background style.
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...
Definition: Mod.cs:363
This class allows you to modify the behavior of any tile in the game. Create an instance of an overri...
Definition: GlobalTile.cs:10
This is a struct that stores the properties of a mod. Without setting it in your Mod constructor...
Definition: ModProperties.cs:6
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:1292
Mod mod
The mod that added this ModBuff.
Definition: ModBuff.cs:11
Mod mod
The mod that added this ModNPC.
Definition: ModNPC.cs:29
virtual void PostSetupContent()
Allows you to load things in your mod after its content has been setup (arrays have been resized to f...
Definition: Mod.cs:77
ModTranslation DisplayName
Definition: ModPrefix.cs:97
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:431
bool LoadResourceLegacy(string path, int length, Func< Stream > getStream)
Definition: Mod.cs:186
This serves as a place for you to program behaviors of equipment textures. This is useful for equipme...
Definition: EquipTexture.cs:8
Mod mod
The mod to which this GlobalTile belongs to.
Definition: GlobalTile.cs:15
string Name
The internal name of this equipment texture.
Definition: EquipTexture.cs:29
static ModTile GetTile(int type)
Gets the ModTile instance with the given type. If no ModTile with the given type exists, returns null.
Definition: TileLoader.cs:102
Item item
The item object that this ModItem controls.
Definition: ModItem.cs:26
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:485
void AddProjectile(string name, ModProjectile projectile)
Adds a type of projectile to the game with the specified name.
Definition: Mod.cs:740
string Name
The name of this GlobaRecipe.
Definition: GlobalRecipe.cs:19
Music GetMusic(string name)
Shorthand for calling ModContent.GetMusic(this.FileName(name)).
Definition: Mod.cs:1634
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:1051
This serves as the central class from which tile-related functions are supported and carried out...
Definition: TileLoader.cs:14
Mod mod
The mod to which this GlobalItem belongs.
Definition: GlobalItem.cs:20
This is where all ModWorld hooks are gathered and called.
Definition: WorldHooks.cs:12
void AddTileEntity(string name, ModTileEntity entity)
Manually add a tile entity during Load.
Definition: Mod.cs:617
Mod mod
The mod that added this type of dust.
Definition: ModDust.cs:39
virtual void Close()
Close is called before Unload, and may be called at any time when mod unloading is imminent (such as ...
Definition: Mod.cs:136
ushort Type
The internal ID of this type of wall.
Definition: ModWall.cs:33
This class allows you to customize the behavior of a custom gore. Create a new instance of this and p...
Definition: ModGore.cs:12
NPC npc
The NPC object that this ModNPC controls.
Definition: ModNPC.cs:21
string Name
The name of this ModWorld. Used for distinguishing between multiple ModWorlds added by a single Mod...
Definition: ModWorld.cs:24
Mod mod
The mod which has added this ModMountData.
Definition: ModMountData.cs:29
int Slot
The ID of this surface background style.
string Name
The internal name of this global background style.
ModConfig provides a way for mods to be configurable. ModConfigs can either be Client specific or Ser...
Definition: ModConfig.cs:18
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:669
This class serves to collect functions that operate on any kind of background style, without being specific to one single background style.
Mod mod
The Mod this ModCommand belongs to.
Definition: ModCommand.cs:34
string Texture
The name and folders of the texture file used by this equipment texture.
Definition: EquipTexture.cs:13
static int GetBackgroundSlot(string texture)
Returns the slot/ID of the background texture with the given name.
Mod mod
The mod that added this type of ModPlayer.
Definition: ModPlayer.cs:20
string Name
The name of this type of wall.
Definition: ModWall.cs:25
Represents a style of water that gets drawn, based on factors such as the background. This is used to determine the color of the water, as well as other things as determined by the hooks below.
Definition: ModWaterStyle.cs:8
This class serves as a central place from which NPC head slots are stored and NPC head textures are a...
static ModItem GetItem(int type)
Gets the ModItem instance corresponding to the specified type. Returns null if no modded item has the...
Definition: ItemLoader.cs:76
Mod mod
The mod that added this style of water.
This serves as a central place to store equipment slots and their corresponding textures. You will use this to obtain the IDs for your equipment textures.
Definition: EquipLoader.cs:11
DynamicSpriteFont GetFont(string name)
Gets a SpriteFont loaded from the specified path.
Definition: Mod.cs:1652
ModConfig GetConfig(string name)
Definition: Mod.cs:1707
string Name
The name of this GlobalTile instance.
Definition: GlobalTile.cs:23
static int NetModCount
Definition: ModNet.cs:66
Manages content added by mods. Liasons between mod content and Terraria&#39;s arrays and oversees the Loa...
Definition: ModContent.cs:25
ModPacket GetPacket(int capacity=256)
Creates a ModPacket object that you can write to and then send between servers and clients...
Definition: Mod.cs:1693
static bool TextureExists(string name)
Returns whether or not a texture with the specified name exists.
Definition: ModContent.cs:91
Mod mod
The mod which has added this type of ModWall.
Definition: ModWall.cs:17
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
Projectile projectile
The projectile object that this ModProjectile controls.
This class is used to keep track of and support the existence of custom sounds that have been added t...
Definition: SoundLoader.cs:11
This class allows you to modify the behavior of any wall in the game (although admittedly walls don&#39;t...
Definition: GlobalWall.cs:8
This class inherits from BinaryWriter. This means that you can use all of its writing functions to se...
Definition: ModPacket.cs:13
Mod mod
The mod object that this ModProjectile originates from.
This class allows you to modify and use hooks for all items, including vanilla items. Create an instance of an overriding class then call Mod.AddGlobalItem to use this.
Definition: GlobalItem.cs:15
Mod mod
Gets the mod.
Definition: ModItem.cs:37
This class allows you to customize how a sound you add is played. To use this, pass an instance to Mo...
Definition: ModSound.cs:8
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:1261
ModTranslation DisplayName
The translations for the display name of this item.
Definition: ModItem.cs:53
virtual void AddRecipes()
Override this method to add recipes to the game. It is recommended that you do so through instances o...
Definition: Mod.cs:100
string Name
The name of this GlobalWall instance.
Definition: GlobalWall.cs:21
string Name
The internal name of this type of dust.
Definition: ModDust.cs:23
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:240
virtual void Load()
Override this method to add most of your content to your mod. Here you will call other methods such a...
Definition: Mod.cs:71
Mod mod
The mod to which this GlobalNPC belongs.
Definition: GlobalNPC.cs:16
This class represents a type of wall that can be added by a mod. Only one instance of this class will...
Definition: ModWall.cs:12
virtual PrefixCategory Category
The category your prefix belongs to, PrefixCategory.Custom by default
Definition: ModPrefix.cs:124
EquipType Type
The type of equipment that this equipment texture is used as.
Definition: EquipTexture.cs:37
virtual bool LoadResource(string path, int length, Func< Stream > getStream)
Hook for pre-loading resources
Definition: Mod.cs:149
This serves as the central class from which item-related functions are carried out. It also stores a list of mod items by ID.
Definition: ItemLoader.cs:21
void AddUgBgStyle(string name, ModUgBgStyle ugBgStyle)
Adds the given underground background style with the given name to this mod.
Definition: Mod.cs:1167
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:976
This class serves as a place for you to place all your properties and hooks for each mount...
Definition: ModMountData.cs:14
void AddCommand(string name, ModCommand mc)
Manually add a Command during Load
Definition: Mod.cs:1438
This class allows you to modify and use hooks for all NPCs, including vanilla mobs. Create an instance of an overriding class then call Mod.AddGlobalNPC to use this.
Definition: GlobalNPC.cs:11
ushort Type
The internal ID of this type of tile.
Definition: ModTile.cs:33
ModItem item
The item that is associated with this equipment texture. Null if no item is associated with this...
Definition: EquipTexture.cs:53
virtual void PostAddRecipes()
This provides a hook into the mod-loading process immediately after recipes have been added...
Definition: Mod.cs:106
Represents a style of waterfalls that gets drawn. This is mostly used to determine the color of the w...
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:345
string Name
The internal name of this water style.
SoundEffect GetSound(string name)
Shorthand for calling ModContent.GetSound(this.FileName(name)).
Definition: Mod.cs:1614
This serves as the central class from which WaterStyle functions are supported and carried out...
int Type
The ID of this waterfall style.
void AddTranslation(ModTranslation translation)
Adds a ModTranslation to the game so that you can use Language.GetText to get a LocalizedText.
Definition: Mod.cs:1544
MountTextureType
This is an enum of all possible types of extra mount textures for custom mounts. Use these as keys in...
This serves as the central class from which ModCommand functions are supported and carried out...
This class serves as a place for you to define a new buff and how that buff behaves.
Definition: ModBuff.cs:6
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
IDisposable fileHandle
Definition: Mod.cs:65
Texture2D GetTexture(string name)
Shorthand for calling ModContent.GetTexture(this.FileName(name)).
Definition: Mod.cs:1578
void AddGlobalItem(string name, GlobalItem globalItem)
Adds the given GlobalItem instance to this mod with the provided name.
Definition: Mod.cs:295
static ModProperties AutoLoadAll
Automatically return a ModProperties object which has all AutoLoad values set to true.
string Name
The name of this type of mount.
Definition: ModMountData.cs:45
static SoundEffect GetSound(string name)
Gets the sound with the specified name. The name is in the same format as for texture names...
Definition: ModContent.cs:141
void AddGlobalWall(string name, GlobalWall globalWall)
Adds the given GlobalWall instance to this mod with the provided name.
Definition: Mod.cs:713
string Name
Internal name of this command.
Definition: ModCommand.cs:36
ModTranslation DisplayName
The translations of this buff&#39;s display name.
Definition: ModBuff.cs:35
This serves as the central class from which NPC-related functions are carried out. It also stores a list of mod NPCs by ID.
Definition: NPCLoader.cs:19
string Name
The internal name of this underground background style.
Mod mod
The mod that added this type of ModWorld.
Definition: ModWorld.cs:16
This serves as the central class from which buff-related functions are supported and carried out...
Definition: BuffLoader.cs:14
void AddSurfaceBgStyle(string name, ModSurfaceBgStyle surfaceBgStyle)
Adds the given surface background style with the given name to this mod.
Definition: Mod.cs:1195
void AddConfig(string name, ModConfig mc)
Definition: Mod.cs:225
void AddBossHeadTexture(string texture, int npcType=-1)
Assigns a head texture that can be used by NPCs on the map.
Definition: Mod.cs:931
This class serves as a place for you to place all your properties and hooks for each projectile...
A ModWorld instance represents an extension of a World. You can store fields in the ModWorld classes ...
Definition: ModWorld.cs:11
virtual void AddRecipeGroups()
Override this method to add recipe groups to this mod. You must add recipe groups by calling the Reci...
Definition: Mod.cs:94
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:535
void AddGlobalRecipe(string name, GlobalRecipe globalRecipe)
Manually add a Global Recipe during Load
Definition: Mod.cs:1413
This serves as the central class from which wall-related functions are supported and carried out...
Definition: WallLoader.cs:13
void AddGlobalNPC(string name, GlobalNPC globalNPC)
Adds the given GlobalNPC instance to this mod with the provided name.
Definition: Mod.cs:871
Mod mod
The mod to which this GlobalProjectile belongs.
Mod is an abstract class that you will override. It serves as a central place from which the mod&#39;s co...
Definition: Mod.cs:24
This class represents a chat or console command. Use the CommandType to specify the scope of the comm...
Definition: ModCommand.cs:31
Mod mod
The mod that added this equipment texture.
Definition: EquipTexture.cs:21
This class allows you to modify the behavior of any buff in the game.
Definition: GlobalBuff.cs:10
ModTranslation DisplayName
The translations for the display name of this projectile.
static int GetGoreSlot(string texture)
Gets the type of the custom gore corresponding to the given texture. Returns 0 if the texture does no...
Definition: ModGore.cs:31
void AddTexture(string name, Texture2D texture)
Shorthand for calling ModLoader.AddTexture(this.FileName(name), texture).
Definition: Mod.cs:1598
string Name
The name of this GlobalItem instance.
Definition: GlobalItem.cs:28
This class provides hooks that control all recipes in the game.
Definition: GlobalRecipe.cs:6
This class serves as a place for you to place all your properties and hooks for each item...
Definition: ModItem.cs:16
ModTranslation Tooltip
The translations for the display name of this tooltip.
Definition: ModItem.cs:61
virtual void LoadResourceFromStream(string path, int len, BinaryReader reader)
Definition: Mod.cs:194
This class represents a type of dust that is added by a mod. Only one instance of this class will eve...
Definition: ModDust.cs:13
string Name
The internal name of this ModProjectile.
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:1362
Mod mod
The mod which added this GlobalRecipe.
Definition: GlobalRecipe.cs:11
int Type
The buff id of this buff.
Definition: ModBuff.cs:27
void AddBackgroundTexture(string texture)
Adds a texture to the list of background textures and assigns it a background texture slot...
Definition: Mod.cs:1393
Mod mod
The mod that added this ModTileEntity.
ModSide
A ModSide enum defines how mods are synced between clients and servers. You can set your mod&#39;s ModSid...
Definition: ModSide.cs:4
Mod mod
The mod that added this surface background style.
ConfigScope
Each ModConfig class has a different scope. Failure to use the correct mode will lead to bugs...
Definition: ModConfig.cs:91
Mod mod
The mod that added this underground background style.
string Name
The internal name of this surface background style.
int Slot
The slot (internal ID) of this equipment texture.
Definition: EquipTexture.cs:45
This class allows you to modify and use hooks for all projectiles, including vanilla projectiles...
string Name
The name of this GlobalNPC instance.
Definition: GlobalNPC.cs:24
string Name
The internal name of this ModItem.
Definition: ModItem.cs:45
This serves as the central place from which mounts are stored and mount-related functions are carried...
Definition: MountLoader.cs:13
string Name
The internal name of this type of buff.
Definition: ModBuff.cs:19
Mod mod
The mod to which this GlobalBuff belongs.
Definition: GlobalBuff.cs:15
string Name
The internal name of this GlobalBuff instance.
Definition: GlobalBuff.cs:23
int Type
The ID of the water style.
Effect GetEffect(string name)
Gets an Effect loaded from the specified path.
Definition: Mod.cs:1668
Each background style determines in its own way how exactly the background is drawn. This class serves as a collection of functions for underground backgrounds.
void AddGlobalBuff(string name, GlobalBuff globalBuff)
Adds the given GlobalBuff instance to this mod using the provided name.
Definition: Mod.cs:1025
static int SoundCount(SoundType type)
Definition: SoundLoader.cs:40
string Name
The name of this type of tile.
Definition: ModTile.cs:25
void AddGlobalBgStyle(string name, GlobalBgStyle globalBgStyle)
Adds the given global background style with the given name to this mod.
Definition: Mod.cs:1232