Terraria ModLoader  0.11.4
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 
18 namespace Terraria.ModLoader
19 {
23  public abstract partial class Mod
24  {
28  internal TmodFile File { get; set; }
32  public Assembly Code { get; internal set; }
36  public ILog Logger { get; internal set; }
37 
41  public virtual string Name => File.name;
45  public Version tModLoaderVersion { get; internal set; }
49  public virtual Version Version => File.version;
50 
51  public ModProperties Properties { get; protected set; } = ModProperties.AutoLoadAll;
55  public ModSide Side { get; internal set; }
59  public string DisplayName { get; internal set; }
60 
61  internal short netID = -1;
62  public bool IsNetSynced => netID >= 0;
63 
64  private IDisposable fileHandle;
65 
66 
70  public virtual void Load() {
71  }
72 
76  public virtual void PostSetupContent() {
77  }
78 
82  public virtual void Unload() {
83  }
84 
88  public virtual uint ExtraBuffSlots { get; }
89 
93  public virtual void AddRecipeGroups() {
94  }
95 
99  public virtual void AddRecipes() {
100  }
101 
105  public virtual void PostAddRecipes() {
106  }
107 
108  public virtual void LoadResources() {
109  if (File == null)
110  return;
111 
112  fileHandle = File.Open();
113 
114  var skipCache = new HashSet<string>();
115  foreach (var entry in File) {
116  Interface.loadMods.SubProgressText = entry.Name;
117 
118  Stream _stream = null;
119  Stream GetStream() => _stream = File.GetStream(entry);
120 
121  if (LoadResource(entry.Name, entry.Length, GetStream))
122  skipCache.Add(entry.Name);
123 
124  _stream?.Dispose();
125  }
126  File.CacheFiles(skipCache);
127  }
128 
135  public virtual void Close() {
136  fileHandle?.Dispose();
137  if (File != null && File.IsOpen)
138  throw new IOException($"TModFile has open handles: {File.path}");
139  }
140 
148  public virtual bool LoadResource(string path, int length, Func<Stream> getStream) {
149  if (tModLoaderVersion < new Version(0, 11) && LoadResourceLegacy(path, length, getStream)) // TODO LoadResourceLegacy is marked obsolete
150  return false;
151 
152  string extension = Path.GetExtension(path).ToLower();
153  path = Path.ChangeExtension(path, null);
154  switch (extension) {
155  case ".png":
156  case ".rawimg":
157  if (!Main.dedServ)
158  LoadTexture(path, getStream(), extension == ".rawimg");
159  return true;
160  case ".wav":
161  case ".mp3":
162  case ".ogg":
163  //Main.engine == null would be more sensible, but only the waveBank fails on Linux when there is no audio hardware
164  if (Main.dedServ || Main.waveBank == null) { }
165  else if (path.Contains("Music/"))
166  musics[path] = LoadMusic(path, extension);
167  else
168  sounds[path] = LoadSound(getStream(), length, extension);
169  return true;
170  case ".xnb":
171  if (Main.dedServ) { }
172  else if (path.StartsWith("Fonts/"))
173  fonts[path] = Main.instance.OurLoad<DynamicSpriteFont>("tmod:"+Name+"/"+path);
174  else if (path.StartsWith("Effects/"))
175  effects[path] = Main.ShaderContentManager.Load<Effect>("tmod:"+Name+"/"+path);
176  else
177  throw new ResourceLoadException(Language.GetTextValue("tModLoader.LoadErrorUnknownXNBFileHint", path));
178  return true;
179  }
180 
181  return false;
182  }
183 
184  [Obsolete]
185  private bool LoadResourceLegacy(string path, int length, Func<Stream> getStream) {
186  using (var stream = getStream()) {
187  LoadResourceFromStream(path, length, new BinaryReader(stream));
188  return stream.Position > 0;
189  }
190  }
191 
192  [Obsolete("Use LoadResource instead", true)]
193  public virtual void LoadResourceFromStream(string path, int len, BinaryReader reader) {
194  }
195 
196  internal void AutoloadConfig()
197  {
198  if (Code == null)
199  return;
200 
201  // TODO: Attribute to specify ordering of ModConfigs
202  foreach (Type type in Code.GetTypes().OrderBy(type => type.FullName))
203  {
204  if (type.IsAbstract)
205  {
206  continue;
207  }
208  if (type.IsSubclassOf(typeof(ModConfig)))
209  {
210  var mc = (ModConfig)Activator.CreateInstance(type);
211  // Skip loading ClientSide on Main.dedServ?
212  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.
213  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");
214  if (mc.Mode == ConfigScope.ClientSide && Side == ModSide.Server) // Doesn't make sense.
215  throw new Exception($"The ModConfig {mc.Name} can't be loaded because the config is ClientSide but this Mods ModSide is Server");
216  mc.mod = this;
217  var name = type.Name;
218  if (mc.Autoload(ref name))
219  AddConfig(name, mc);
220  }
221  }
222  }
223 
224  public void AddConfig(string name, ModConfig mc)
225  {
226  mc.Name = name;
227  mc.mod = this;
228 
229  ConfigManager.Add(mc);
230  }
231 
238  public void AddItem(string name, ModItem item) {
239  if (!loading)
240  throw new Exception(Language.GetTextValue("tModLoader.LoadErrorAddItemOnlyInLoad"));
241 
242  if (items.ContainsKey(name))
243  throw new Exception(Language.GetTextValue("tModLoader.LoadError2ModItemSameName", name));
244 
245  item.mod = this;
246  item.Name = name;
247  item.DisplayName = GetOrCreateTranslation(string.Format("Mods.{0}.ItemName.{1}", Name, name));
248  item.Tooltip = GetOrCreateTranslation(string.Format("Mods.{0}.ItemTooltip.{1}", Name, name), true);
249 
250  item.item.ResetStats(ItemLoader.ReserveItemID());
251  item.item.modItem = item;
252 
253  items[name] = item;
254  ItemLoader.items.Add(item);
255  }
256 
262  public ModItem GetItem(string name) => items.TryGetValue(name, out var item) ? item : null;
263 
269  public T GetItem<T>() where T : ModItem => (T)GetItem(typeof(T).Name);
270 
276  public int ItemType(string name) => GetItem(name)?.item.type ?? 0;
277 
283  public int ItemType<T>() where T : ModItem => ItemType(typeof(T).Name);
284 
290  public void AddGlobalItem(string name, GlobalItem globalItem) {
291  if (!loading)
292  throw new Exception("AddGlobalItem can only be called from Mod.Load or Mod.Autoload");
293 
294  ItemLoader.VerifyGlobalItem(globalItem);
295 
296  globalItem.mod = this;
297  globalItem.Name = name;
298 
299  globalItems[name] = globalItem;
300  globalItem.index = ItemLoader.globalItems.Count;
301  ItemLoader.globalIndexes[Name + ':' + name] = ItemLoader.globalItems.Count;
302  if (ItemLoader.globalIndexesByType.ContainsKey(globalItem.GetType())) {
303  ItemLoader.globalIndexesByType[globalItem.GetType()] = -1;
304  }
305  else {
306  ItemLoader.globalIndexesByType[globalItem.GetType()] = ItemLoader.globalItems.Count;
307  }
308  ItemLoader.globalItems.Add(globalItem);
309  }
310 
316  public GlobalItem GetGlobalItem(string name) => globalItems.TryGetValue(name, out var globalItem) ? globalItem : null;
317 
323  public T GetGlobalItem<T>() where T : GlobalItem => (T)GetGlobalItem(typeof(T).Name);
324 
339  public int AddEquipTexture(ModItem item, EquipType type, string name, string texture,
340  string armTexture = "", string femaleTexture = "") {
341  return AddEquipTexture(new EquipTexture(), item, type, name, texture, armTexture, femaleTexture);
342  }
343 
357  public int AddEquipTexture(EquipTexture equipTexture, ModItem item, EquipType type, string name, string texture,
358  string armTexture = "", string femaleTexture = "") {
359  if (!loading)
360  throw new Exception("AddEquipTexture can only be called from Mod.Load or Mod.Autoload");
361 
362  ModContent.GetTexture(texture); //ensure texture exists
363 
364  equipTexture.Texture = texture;
365  equipTexture.mod = this;
366  equipTexture.Name = name;
367  equipTexture.Type = type;
368  equipTexture.item = item;
369  int slot = equipTexture.Slot = EquipLoader.ReserveEquipID(type);
370 
371  EquipLoader.equipTextures[type][slot] = equipTexture;
372  equipTextures[Tuple.Create(name, type)] = equipTexture;
373 
374  if (type == EquipType.Body) {
375  if (femaleTexture == null || !ModContent.TextureExists(femaleTexture))
376  femaleTexture = texture;
377  EquipLoader.femaleTextures[slot] = femaleTexture;
378 
379  ModContent.GetTexture(armTexture); //ensure texture exists
380  EquipLoader.armTextures[slot] = armTexture;
381  }
382  if (item != null) {
383  IDictionary<EquipType, int> slots;
384  if (!EquipLoader.idToSlot.TryGetValue(item.item.type, out slots))
385  EquipLoader.idToSlot[item.item.type] = slots = new Dictionary<EquipType, int>();
386 
387  slots[type] = slot;
388  if (type == EquipType.Head || type == EquipType.Body || type == EquipType.Legs)
389  EquipLoader.slotToId[type][slot] = item.item.type;
390  }
391  return slot;
392  }
393 
400  public EquipTexture GetEquipTexture(string name, EquipType type) =>
401  equipTextures.TryGetValue(Tuple.Create(name, type), out var texture) ? texture : null;
402 
409  public int GetEquipSlot(string name, EquipType type) => GetEquipTexture(name, type)?.Slot ?? -1;
410 
417  public sbyte GetAccessorySlot(string name, EquipType type) => (sbyte)GetEquipSlot(name, type);
418 
425  public void AddPrefix(string name, ModPrefix prefix) {
426  if (!loading)
427  throw new Exception("AddPrefix can only be called from Mod.Load or Mod.Autoload");
428 
429  if (prefixes.ContainsKey(name))
430  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.");
431 
432  prefix.mod = this;
433  prefix.Name = name;
434  prefix.DisplayName = GetOrCreateTranslation(string.Format("Mods.{0}.Prefix.{1}", Name, name));
435  prefix.Type = ModPrefix.ReservePrefixID();
436 
437  prefixes[name] = prefix;
438  ModPrefix.prefixes.Add(prefix);
439  ModPrefix.categoryPrefixes[prefix.Category].Add(prefix);
440  }
441 
447  public ModPrefix GetPrefix(string name) => prefixes.TryGetValue(name, out var prefix) ? prefix : null;
448 
454  public T GetPrefix<T>() where T : ModPrefix => (T)GetPrefix(typeof(T).Name);
455 
461  public byte PrefixType(string name) => GetPrefix(name)?.Type ?? 0;
462 
468  public byte PrefixType<T>() where T : ModPrefix => PrefixType(typeof(T).Name);
469 
476  public void AddDust(string name, ModDust dust, string texture = "") {
477  if (!loading)
478  throw new Exception("AddDust can only be called from Mod.Load or Mod.Autoload");
479 
480  dust.mod = this;
481  dust.Name = name;
482  dust.Type = ModDust.ReserveDustID();
483  dust.Texture = !string.IsNullOrEmpty(texture) ? ModContent.GetTexture(texture) : Main.dustTexture;
484 
485  dusts[name] = dust;
486  ModDust.dusts.Add(dust);
487  }
488 
494  public ModDust GetDust(string name) => dusts.TryGetValue(name, out var dust) ? dust : null;
495 
501  public T GetDust<T>() where T : ModDust => (T)GetDust(typeof(T).Name);
502 
508  public int DustType(string name) => GetDust(name)?.Type ?? 0;
509 
515  public int DustType<T>() where T : ModDust => DustType(typeof(T).Name);
516 
523  public void AddTile(string name, ModTile tile, string texture) {
524  if (!loading)
525  throw new Exception("AddItem can only be called from Mod.Load or Mod.Autoload");
526 
527  if (tiles.ContainsKey(name))
528  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.");
529 
530  tile.mod = this;
531  tile.Name = name;
532  tile.Type = (ushort)TileLoader.ReserveTileID();
533  tile.texture = texture;
534 
535  tiles[name] = tile;
536  TileLoader.tiles.Add(tile);
537  }
538 
544  public ModTile GetTile(string name) => tiles.TryGetValue(name, out var tile) ? tile : null;
545 
551  public T GetTile<T>() where T : ModTile => (T)GetTile(typeof(T).Name);
552 
558  public int TileType(string name) => GetTile(name)?.Type ?? 0;
559 
565  public int TileType<T>() where T : ModTile => TileType(typeof(T).Name);
566 
572  public void AddGlobalTile(string name, GlobalTile globalTile) {
573  if (!loading)
574  throw new Exception("AddGlobalTile can only be called from Mod.Load or Mod.Autoload");
575 
576  globalTile.mod = this;
577  globalTile.Name = name;
578 
579  globalTiles[name] = globalTile;
580  TileLoader.globalTiles.Add(globalTile);
581  }
582 
588  public GlobalTile GetGlobalTile(string name) => globalTiles.TryGetValue(name, out var globalTile) ? globalTile : null;
589 
595  public T GetGlobalTile<T>() where T : GlobalTile => (T)GetGlobalTile(typeof(T).Name);
596 
600  public void AddTileEntity(string name, ModTileEntity entity) {
601  if (!loading)
602  throw new Exception("AddTileEntity can only be called from Mod.Load or Mod.Autoload");
603 
604  int id = ModTileEntity.ReserveTileEntityID();
605  entity.mod = this;
606  entity.Name = name;
607  entity.Type = id;
608  entity.type = (byte)id;
609 
610  tileEntities[name] = entity;
611  ModTileEntity.tileEntities.Add(entity);
612  }
613 
619  public ModTileEntity GetTileEntity(string name) =>
620  tileEntities.TryGetValue(name, out var tileEntity) ? tileEntity : null;
621 
627  public T GetTileEntity<T>() where T : ModTileEntity => (T)GetTileEntity(typeof(T).Name);
628 
634  public int TileEntityType(string name) => GetTileEntity(name)?.Type ?? -1;
635 
641  public int TileEntityType<T>() where T : ModTileEntity => TileEntityType(typeof(T).Name);
642 
649  public void AddWall(string name, ModWall wall, string texture) {
650  if (!loading)
651  throw new Exception("AddWall can only be called from Mod.Load or Mod.Autoload");
652 
653  wall.mod = this;
654  wall.Name = name;
655  wall.Type = (ushort)WallLoader.ReserveWallID();
656  wall.texture = texture;
657 
658  walls[name] = wall;
659  WallLoader.walls.Add(wall);
660  }
661 
667  public ModWall GetWall(string name) => walls.TryGetValue(name, out var wall) ? wall : null;
668 
669  public T GetWall<T>() where T : ModWall => (T)GetWall(typeof(T).Name);
670 
676  public int WallType(string name) => GetWall(name)?.Type ?? 0;
677 
683  public int WallType<T>() where T : ModWall => WallType(typeof(T).Name);
684 
690  public void AddGlobalWall(string name, GlobalWall globalWall) {
691  if (!loading)
692  throw new Exception("AddGlobalWall can only be called from Mod.Load or Mod.Autoload");
693 
694  globalWall.mod = this;
695  globalWall.Name = name;
696 
697  globalWalls[name] = globalWall;
698  WallLoader.globalWalls.Add(globalWall);
699  }
700 
706  public GlobalWall GetGlobalWall(string name) => globalWalls.TryGetValue(name, out var globalWall) ? globalWall : null;
707 
708  public T GetGlobalWall<T>() where T : GlobalWall => (T)GetGlobalWall(typeof(T).Name);
709 
715  public void AddProjectile(string name, ModProjectile projectile) {
716  if (!loading)
717  throw new Exception("AddProjectile can only be called from Mod.Load or Mod.Autoload");
718 
719  if (projectiles.ContainsKey(name))
720  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.");
721 
722  projectile.mod = this;
723  projectile.Name = name;
724  projectile.projectile.type = ProjectileLoader.ReserveProjectileID();
725  projectile.DisplayName = GetOrCreateTranslation(string.Format("Mods.{0}.ProjectileName.{1}", Name, name));
726 
727  projectiles[name] = projectile;
728  ProjectileLoader.projectiles.Add(projectile);
729  }
730 
736  public ModProjectile GetProjectile(string name) => projectiles.TryGetValue(name, out var proj) ? proj : null;
737 
738  public T GetProjectile<T>() where T : ModProjectile => (T)GetProjectile(typeof(T).Name);
739 
745  public int ProjectileType(string name) => GetProjectile(name)?.projectile.type ?? 0;
746 
752  public int ProjectileType<T>() where T : ModProjectile => ProjectileType(typeof(T).Name);
753 
759  public void AddGlobalProjectile(string name, GlobalProjectile globalProjectile) {
760  if (!loading)
761  throw new Exception("AddGlobalProjectile can only be called from Mod.Load or Mod.Autoload");
762 
763  ProjectileLoader.VerifyGlobalProjectile(globalProjectile);
764 
765  globalProjectile.mod = this;
766  globalProjectile.Name = name;
767 
768  globalProjectiles[name] = globalProjectile;
769  globalProjectile.index = ProjectileLoader.globalProjectiles.Count;
770  ProjectileLoader.globalIndexes[Name + ':' + name] = ProjectileLoader.globalProjectiles.Count;
771  if (ProjectileLoader.globalIndexesByType.ContainsKey(globalProjectile.GetType())) {
772  ProjectileLoader.globalIndexesByType[globalProjectile.GetType()] = -1;
773  }
774  else {
775  ProjectileLoader.globalIndexesByType[globalProjectile.GetType()] = ProjectileLoader.globalProjectiles.Count;
776  }
777  ProjectileLoader.globalProjectiles.Add(globalProjectile);
778  }
779 
785  public GlobalProjectile GetGlobalProjectile(string name) => globalProjectiles.TryGetValue(name, out var globalProj) ? globalProj : null;
786 
787  public T GetGlobalProjectile<T>() where T : GlobalProjectile => (T)GetGlobalProjectile(typeof(T).Name);
788 
794  public void AddNPC(string name, ModNPC npc) {
795  if (!loading)
796  throw new Exception("AddNPC can only be called from Mod.Load or Mod.Autoload");
797 
798  if (npcs.ContainsKey(name))
799  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.");
800 
801  npc.mod = this;
802  npc.Name = name;
803  npc.npc.type = NPCLoader.ReserveNPCID();
804  npc.DisplayName = GetOrCreateTranslation(string.Format("Mods.{0}.NPCName.{1}", Name, name));
805 
806  npcs[name] = npc;
807  NPCLoader.npcs.Add(npc);
808  }
809 
815  public ModNPC GetNPC(string name) => npcs.TryGetValue(name, out var npc) ? npc : null;
816 
817  public T GetNPC<T>() where T : ModNPC => (T)GetNPC(typeof(T).Name);
818 
824  public int NPCType(string name) => GetNPC(name)?.npc.type ?? 0;
825 
831  public int NPCType<T>() where T : ModNPC => NPCType(typeof(T).Name);
832 
838  public void AddGlobalNPC(string name, GlobalNPC globalNPC) {
839  if (!loading)
840  throw new Exception("AddGlobalNPC can only be called from Mod.Load or Mod.Autoload");
841 
842  NPCLoader.VerifyGlobalNPC(globalNPC);
843 
844  globalNPC.mod = this;
845  globalNPC.Name = name;
846 
847  globalNPCs[name] = globalNPC;
848  globalNPC.index = NPCLoader.globalNPCs.Count;
849  NPCLoader.globalIndexes[Name + ':' + name] = NPCLoader.globalNPCs.Count;
850  if (NPCLoader.globalIndexesByType.ContainsKey(globalNPC.GetType())) {
851  NPCLoader.globalIndexesByType[globalNPC.GetType()] = -1;
852  }
853  else {
854  NPCLoader.globalIndexesByType[globalNPC.GetType()] = NPCLoader.globalNPCs.Count;
855  }
856  NPCLoader.globalNPCs.Add(globalNPC);
857  }
858 
864  public GlobalNPC GetGlobalNPC(string name) => globalNPCs.TryGetValue(name, out var globalNPC) ? globalNPC : null;
865 
866  public T GetGlobalNPC<T>() where T : GlobalNPC => (T)GetGlobalNPC(typeof(T).Name);
867 
874  public void AddNPCHeadTexture(int npcType, string texture) {
875  if (!loading)
876  throw new Exception("AddNPCHeadTexture can only be called from Mod.Load or Mod.Autoload");
877 
878  int slot = NPCHeadLoader.ReserveHeadSlot();
879  NPCHeadLoader.heads[texture] = slot;
880  if (!Main.dedServ) {
881  ModContent.GetTexture(texture);
882  }
883  /*else if (Main.dedServ && !(ModLoader.FileExists(texture + ".png") || ModLoader.FileExists(texture + ".rawimg")))
884  {
885  throw new MissingResourceException(texture);
886  }*/
887  NPCHeadLoader.npcToHead[npcType] = slot;
888  NPCHeadLoader.headToNPC[slot] = npcType;
889  }
890 
896  public void AddBossHeadTexture(string texture, int npcType = -1) {
897  if (!loading)
898  throw new Exception("AddBossHeadTexture can only be called from Mod.Load or Mod.Autoload");
899 
900  int slot = NPCHeadLoader.ReserveBossHeadSlot(texture);
901  NPCHeadLoader.bossHeads[texture] = slot;
902  ModContent.GetTexture(texture);
903  if (npcType >= 0) {
904  NPCHeadLoader.npcToBossHead[npcType] = slot;
905  }
906  }
907 
913  public void AddPlayer(string name, ModPlayer player) {
914  if (!loading)
915  throw new Exception("AddPlayer can only be called from Mod.Load or Mod.Autoload");
916 
917  player.mod = this;
918  player.Name = name;
919 
920  players[name] = player;
921  PlayerHooks.Add(player);
922  }
923 
929  public ModPlayer GetPlayer(string name) => players.TryGetValue(name, out var player) ? player : null;
930 
931  public T GetPlayer<T>() where T : ModPlayer => (T)GetPlayer(typeof(T).Name);
932 
939  public void AddBuff(string name, ModBuff buff, string texture) {
940  if (!loading)
941  throw new Exception("AddBuff can only be called from Mod.Load or Mod.Autoload");
942 
943  if (buffs.ContainsKey(name))
944  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.");
945 
946  buff.mod = this;
947  buff.Name = name;
948  buff.Type = BuffLoader.ReserveBuffID();
949  buff.texture = texture;
950  buff.DisplayName = GetOrCreateTranslation(string.Format("Mods.{0}.BuffName.{1}", Name, name));
951  buff.Description = GetOrCreateTranslation(string.Format("Mods.{0}.BuffDescription.{1}", Name, name));
952 
953  buffs[name] = buff;
954  BuffLoader.buffs.Add(buff);
955  }
956 
962  public ModBuff GetBuff(string name) => buffs.TryGetValue(name, out var buff) ? buff : null;
963 
964  public T GetBuff<T>() where T : ModBuff => (T)GetBuff(typeof(T).Name);
965 
971  public int BuffType(string name) => GetBuff(name)?.Type ?? 0;
972 
978  public int BuffType<T>() where T : ModBuff => BuffType(typeof(T).Name);
979 
985  public void AddGlobalBuff(string name, GlobalBuff globalBuff) {
986  globalBuff.mod = this;
987  globalBuff.Name = name;
988 
989  globalBuffs[name] = globalBuff;
990  BuffLoader.globalBuffs.Add(globalBuff);
991  }
992 
998  public GlobalBuff GetGlobalBuff(string name) => globalBuffs.TryGetValue(name, out var globalBuff) ? globalBuff : null;
999 
1000  public T GetGlobalBuff<T>() where T : GlobalBuff => (T)GetGlobalBuff(typeof(T).Name);
1001 
1009  public void AddMount(string name, ModMountData mount, string texture,
1010  IDictionary<MountTextureType, string> extraTextures = null) {
1011  if (!loading)
1012  throw new Exception("AddMount can only be called from Mod.Load or Mod.Autoload");
1013 
1014  if (Mount.mounts == null || Mount.mounts.Length == MountID.Count)
1015  Mount.Initialize();
1016 
1017  mount.mod = this;
1018  mount.Name = name;
1019  mount.Type = MountLoader.ReserveMountID();
1020  mount.texture = texture;
1021 
1022  mountDatas[name] = mount;
1023  MountLoader.mountDatas[mount.Type] = mount;
1024 
1025  if (extraTextures == null)
1026  return;
1027 
1028  foreach (var entry in extraTextures) {
1029  if (!ModContent.TextureExists(entry.Value))
1030  continue;
1031 
1032  Texture2D extraTexture = ModContent.GetTexture(entry.Value);
1033  switch (entry.Key) {
1034  case MountTextureType.Back:
1035  mount.mountData.backTexture = extraTexture;
1036  break;
1037  case MountTextureType.BackGlow:
1038  mount.mountData.backTextureGlow = extraTexture;
1039  break;
1040  case MountTextureType.BackExtra:
1041  mount.mountData.backTextureExtra = extraTexture;
1042  break;
1043  case MountTextureType.BackExtraGlow:
1044  mount.mountData.backTextureExtraGlow = extraTexture;
1045  break;
1046  case MountTextureType.Front:
1047  mount.mountData.frontTexture = extraTexture;
1048  break;
1049  case MountTextureType.FrontGlow:
1050  mount.mountData.frontTextureGlow = extraTexture;
1051  break;
1052  case MountTextureType.FrontExtra:
1053  mount.mountData.frontTextureExtra = extraTexture;
1054  break;
1055  case MountTextureType.FrontExtraGlow:
1056  mount.mountData.frontTextureExtraGlow = extraTexture;
1057  break;
1058  }
1059  }
1060  }
1061 
1067  public ModMountData GetMount(string name) => mountDatas.TryGetValue(name, out var modMountData) ? modMountData : null;
1068 
1069  public T GetMount<T>() where T : ModMountData => (T)GetMount(typeof(T).Name);
1070 
1076  public int MountType(string name) => GetMount(name)?.Type ?? 0;
1077 
1083  public int MountType<T>() where T : ModMountData => MountType(typeof(T).Name);
1084 
1090  public void AddModWorld(string name, ModWorld modWorld) {
1091  if (!loading)
1092  throw new Exception("AddModWorld can only be called from Mod.Load or Mod.Autoload");
1093 
1094  modWorld.mod = this;
1095  modWorld.Name = name;
1096 
1097  worlds[name] = modWorld;
1098  WorldHooks.Add(modWorld);
1099  }
1100 
1106  public ModWorld GetModWorld(string name) => worlds.TryGetValue(name, out var world) ? world : null;
1107 
1113  public T GetModWorld<T>() where T : ModWorld => (T)GetModWorld(typeof(T).Name);
1114 
1120  public void AddUgBgStyle(string name, ModUgBgStyle ugBgStyle) {
1121  if (!loading)
1122  throw new Exception("AddUgBgStyle can only be called from Mod.Load or Mod.Autoload");
1123 
1124  ugBgStyle.mod = this;
1125  ugBgStyle.Name = name;
1126  ugBgStyle.Slot = UgBgStyleLoader.ReserveBackgroundSlot();
1127 
1128  ugBgStyles[name] = ugBgStyle;
1129  UgBgStyleLoader.ugBgStyles.Add(ugBgStyle);
1130  }
1131 
1137  public ModUgBgStyle GetUgBgStyle(string name) => ugBgStyles.TryGetValue(name, out var bgStyle) ? bgStyle : null;
1138 
1139  public T GetUgBgStyle<T>() where T : ModUgBgStyle => (T)GetUgBgStyle(typeof(T).Name);
1140 
1146  public void AddSurfaceBgStyle(string name, ModSurfaceBgStyle surfaceBgStyle) {
1147  if (!loading)
1148  throw new Exception("AddSurfaceBgStyle can only be called from Mod.Load or Mod.Autoload");
1149 
1150  surfaceBgStyle.mod = this;
1151  surfaceBgStyle.Name = name;
1152  surfaceBgStyle.Slot = SurfaceBgStyleLoader.ReserveBackgroundSlot();
1153 
1154  surfaceBgStyles[name] = surfaceBgStyle;
1155  SurfaceBgStyleLoader.surfaceBgStyles.Add(surfaceBgStyle);
1156  }
1157 
1163  public ModSurfaceBgStyle GetSurfaceBgStyle(string name) => surfaceBgStyles.TryGetValue(name, out var bgStyle) ? bgStyle : null;
1164 
1165  public T GetSurfaceBgStyle<T>() where T : ModSurfaceBgStyle => (T)GetSurfaceBgStyle(typeof(T).Name);
1166 
1172  public int GetSurfaceBgStyleSlot(string name) => GetSurfaceBgStyle(name)?.Slot ?? -1;
1173 
1174  public int GetSurfaceBgStyleSlot<T>() where T : ModSurfaceBgStyle => GetSurfaceBgStyleSlot(typeof(T).Name);
1175 
1181  public void AddGlobalBgStyle(string name, GlobalBgStyle globalBgStyle) {
1182  if (!loading)
1183  throw new Exception("AddGlobalBgStyle can only be called from Mod.Load or Mod.Autoload");
1184 
1185  globalBgStyle.mod = this;
1186  globalBgStyle.Name = name;
1187 
1188  globalBgStyles[name] = globalBgStyle;
1189  GlobalBgStyleLoader.globalBgStyles.Add(globalBgStyle);
1190  }
1191 
1197  public GlobalBgStyle GetGlobalBgStyle(string name) => globalBgStyles.TryGetValue(name, out var bgStyle) ? bgStyle : null;
1198 
1199  public T GetGlobalBgStyle<T>() where T : GlobalBgStyle => (T)GetGlobalBgStyle(typeof(T).Name);
1200 
1208  public void AddWaterStyle(string name, ModWaterStyle waterStyle, string texture, string blockTexture) {
1209  if (!loading)
1210  throw new Exception("AddWaterStyle can only be called from Mod.Load or Mod.Autoload");
1211 
1212  waterStyle.mod = this;
1213  waterStyle.Name = name;
1214  waterStyle.Type = WaterStyleLoader.ReserveStyle();
1215  waterStyle.texture = texture;
1216  waterStyle.blockTexture = blockTexture;
1217 
1218  waterStyles[name] = waterStyle;
1219  WaterStyleLoader.waterStyles.Add(waterStyle);
1220  }
1221 
1227  public ModWaterStyle GetWaterStyle(string name) => waterStyles.TryGetValue(name, out var waterStyle) ? waterStyle : null;
1228 
1229  public T GetWaterStyle<T>() where T : ModWaterStyle => (T)GetWaterStyle(typeof(T).Name);
1230 
1237  public void AddWaterfallStyle(string name, ModWaterfallStyle waterfallStyle, string texture) {
1238  if (!loading)
1239  throw new Exception("AddWaterfallStyle can only be called from Mod.Load or Mod.Autoload");
1240 
1241  waterfallStyle.mod = this;
1242  waterfallStyle.Name = name;
1243  waterfallStyle.Type = WaterfallStyleLoader.ReserveStyle();
1244  waterfallStyle.texture = texture;
1245 
1246  waterfallStyles[name] = waterfallStyle;
1247  WaterfallStyleLoader.waterfallStyles.Add(waterfallStyle);
1248  }
1249 
1255  public ModWaterfallStyle GetWaterfallStyle(string name) => waterfallStyles.TryGetValue(name, out var waterfallStyle) ? waterfallStyle : null;
1256 
1257  public T GetWaterfallStyle<T>() where T : ModWaterfallStyle => (T)GetWaterfallStyle(typeof(T).Name);
1258 
1264  public int GetWaterfallStyleSlot(string name) => GetWaterfallStyle(name)?.Type ?? -1;
1265 
1266  public int GetWaterfallStyleSlot<T>() where T : ModWaterfallStyle => GetWaterfallStyleSlot(typeof(T).Name);
1267 
1273  public void AddGore(string texture, ModGore modGore = null) {
1274  if (!loading)
1275  throw new Exception("AddGore can only be called from Mod.Load or Mod.Autoload");
1276 
1277  int id = ModGore.ReserveGoreID();
1278  ModGore.gores[texture] = id;
1279  if (modGore != null) {
1280  ModGore.modGores[id] = modGore;
1281  }
1282  }
1283 
1289  public int GetGoreSlot(string name) => ModGore.GetGoreSlot(Name + '/' + name);
1290 
1296  public int GetGoreSlot<T>() where T : ModGore => GetGoreSlot(typeof(T).Name);
1297 
1304  public void AddSound(SoundType type, string soundPath, ModSound modSound = null) {
1305  if (!loading)
1306  throw new Exception("AddSound can only be called from Mod.Load or Mod.Autoload");
1307  int id = SoundLoader.ReserveSoundID(type);
1308  SoundLoader.sounds[type][soundPath] = id;
1309  if (modSound != null) {
1310  SoundLoader.modSounds[type][id] = modSound;
1311  modSound.sound = ModContent.GetSound(soundPath);
1312  }
1313  }
1314 
1321  public int GetSoundSlot(SoundType type, string name) => SoundLoader.GetSoundSlot(type, Name + '/' + name);
1322 
1329  public LegacySoundStyle GetLegacySoundSlot(SoundType type, string name) => SoundLoader.GetLegacySoundSlot(type, Name + '/' + name);
1330 
1335  public void AddBackgroundTexture(string texture) {
1336  if (!loading)
1337  throw new Exception("AddBackgroundTexture can only be called from Mod.Load or Mod.Autoload");
1338 
1339  BackgroundTextureLoader.backgrounds[texture] = BackgroundTextureLoader.ReserveBackgroundSlot();
1340  ModContent.GetTexture(texture);
1341  }
1342 
1348  public int GetBackgroundSlot(string name) => BackgroundTextureLoader.GetBackgroundSlot(Name + '/' + name);
1349 
1355  public void AddGlobalRecipe(string name, GlobalRecipe globalRecipe) {
1356  if (!loading)
1357  throw new Exception("AddGlobalRecipe can only be called from Mod.Load or Mod.Autoload");
1358 
1359  globalRecipe.mod = this;
1360  globalRecipe.Name = name;
1361 
1362  globalRecipes[name] = globalRecipe;
1363  RecipeHooks.Add(globalRecipe);
1364  }
1365 
1371  public GlobalRecipe GetGlobalRecipe(string name) => globalRecipes.TryGetValue(name, out var globalRecipe) ? globalRecipe : null;
1372 
1373  public T GetGlobalRecipe<T>() where T : GlobalRecipe => (T)GetGlobalRecipe(typeof(T).Name);
1374 
1378  public void AddCommand(string name, ModCommand mc) {
1379  if (!loading)
1380  throw new Exception("AddCommand can only be called from Mod.Load or Mod.Autoload");
1381 
1382  mc.mod = this;
1383  mc.Name = name;
1384  CommandManager.Add(mc);
1385  }
1386 
1415  public void AddMusicBox(int musicSlot, int itemType, int tileType, int tileFrameY = 0) {
1416  if (!loading)
1417  throw new Exception("AddMusicBox can only be called from Mod.Load or Mod.Autoload");
1418 
1419  if (Main.waveBank == null)
1420  return;
1421 
1422  if (musicSlot < Main.maxMusic) {
1423  throw new ArgumentOutOfRangeException("Cannot assign music box to vanilla music ID " + musicSlot);
1424  }
1425  if (musicSlot >= SoundLoader.SoundCount(SoundType.Music)) {
1426  throw new ArgumentOutOfRangeException("Music ID " + musicSlot + " does not exist");
1427  }
1428  if (itemType < ItemID.Count) {
1429  throw new ArgumentOutOfRangeException("Cannot assign music box to vanilla item ID " + itemType);
1430  }
1431  if (ItemLoader.GetItem(itemType) == null) {
1432  throw new ArgumentOutOfRangeException("Item ID " + itemType + " does not exist");
1433  }
1434  if (tileType < TileID.Count) {
1435  throw new ArgumentOutOfRangeException("Cannot assign music box to vanilla tile ID " + tileType);
1436  }
1437  if (TileLoader.GetTile(tileType) == null) {
1438  throw new ArgumentOutOfRangeException("Tile ID " + tileType + " does not exist");
1439  }
1440  if (SoundLoader.musicToItem.ContainsKey(musicSlot)) {
1441  throw new ArgumentException("Music ID " + musicSlot + " has already been assigned a music box");
1442  }
1443  if (SoundLoader.itemToMusic.ContainsKey(itemType)) {
1444  throw new ArgumentException("Item ID " + itemType + " has already been assigned a music");
1445  }
1446  if (!SoundLoader.tileToMusic.ContainsKey(tileType)) {
1447  SoundLoader.tileToMusic[tileType] = new Dictionary<int, int>();
1448  }
1449  if (SoundLoader.tileToMusic[tileType].ContainsKey(tileFrameY)) {
1450  string message = "Y-frame " + tileFrameY + " of tile type " + tileType + " has already been assigned a music";
1451  throw new ArgumentException(message);
1452  }
1453  if (tileFrameY % 36 != 0) {
1454  throw new ArgumentException("Y-frame must be divisible by 36");
1455  }
1456  SoundLoader.musicToItem[musicSlot] = itemType;
1457  SoundLoader.itemToMusic[itemType] = musicSlot;
1458  SoundLoader.tileToMusic[tileType][tileFrameY] = musicSlot;
1459  }
1460 
1467  public ModHotKey RegisterHotKey(string name, string defaultKey) {
1468  if (!loading)
1469  throw new Exception("RegisterHotKey can only be called from Mod.Load or Mod.Autoload");
1470 
1471  return ModContent.RegisterHotKey(this, name, defaultKey);
1472  }
1473 
1478  public ModTranslation CreateTranslation(string key) =>
1479  new ModTranslation(string.Format("Mods.{0}.{1}", Name, key));
1480 
1484  public void AddTranslation(ModTranslation translation) {
1485  translations[translation.Key] = translation;
1486  }
1487 
1488  internal ModTranslation GetOrCreateTranslation(string key, bool defaultEmpty = false) {
1489  key = key.Replace(" ", "_");
1490  return translations.TryGetValue(key, out var translation) ? translation : new ModTranslation(key, defaultEmpty);
1491  }
1492 
1498  public byte[] GetFileBytes(string name) => File?.GetBytes(name);
1499 
1505  public Stream GetFileStream(string name, bool newFileStream = false) => File?.GetStream(name, newFileStream);
1506 
1512  public bool FileExists(string name) => File != null && File.HasFile(name);
1513 
1518  public Texture2D GetTexture(string name) {
1519  if (!textures.TryGetValue(name, out var t))
1520  throw new MissingResourceException(name, textures.Keys);
1521 
1522  return t;
1523  }
1524 
1530  public bool TextureExists(string name) => textures.ContainsKey(name);
1531 
1538  public void AddTexture(string name, Texture2D texture) {
1539  if (Main.dedServ)
1540  return;
1541 
1542  if (TextureExists(name))
1543  throw new Exception("Texture already exist: " + name);
1544 
1545  textures[name] = texture;
1546  }
1547 
1554  public SoundEffect GetSound(string name) {
1555  if (!sounds.TryGetValue(name, out var sound))
1556  throw new MissingResourceException(name);
1557 
1558  return sound;
1559  }
1560 
1566  public bool SoundExists(string name) => sounds.ContainsKey(name);
1567 
1574  public Music GetMusic(string name) {
1575  if (!musics.TryGetValue(name, out var music))
1576  throw new MissingResourceException(name);
1577 
1578  return music;
1579  }
1580 
1586  public bool MusicExists(string name) => musics.ContainsKey(name);
1587 
1592  public DynamicSpriteFont GetFont(string name) {
1593  if (!fonts.TryGetValue(name, out var font))
1594  throw new MissingResourceException(name);
1595 
1596  return font;
1597  }
1598 
1602  public bool FontExists(string name) => fonts.ContainsKey(name);
1603 
1608  public Effect GetEffect(string name) {
1609  if (!effects.TryGetValue(name, out var effect))
1610  throw new MissingResourceException(name);
1611 
1612  return effect;
1613  }
1614 
1618  public bool EffectExists(string name) => effects.ContainsKey(name);
1619 
1623  public virtual object Call(params object[] args) {
1624  return null;
1625  }
1626 
1633  public ModPacket GetPacket(int capacity = 256) {
1634  if (netID < 0)
1635  throw new Exception("Cannot get packet for " + Name + " because it does not exist on the other side");
1636 
1637  var p = new ModPacket(MessageID.ModPacket, capacity + 5);
1638  if (ModNet.NetModCount < 256)
1639  p.Write((byte)netID);
1640  else
1641  p.Write(netID);
1642 
1643  p.netID = netID;
1644  return p;
1645  }
1646 
1647  public ModConfig GetConfig(string name)
1648  {
1649  List<ModConfig> configs;
1650  if (ConfigManager.Configs.TryGetValue(this, out configs))
1651  {
1652  return configs.Single(x => x.Name == name);
1653  }
1654  return null;
1655  }
1656 
1657  public T GetConfig<T>() where T : ModConfig => (T)GetConfig(typeof(T).Name);
1658  }
1659 }
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:913
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:82
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:759
void AddModWorld(string name, ModWorld modWorld)
Adds a ModWorld to this mod with the given name.
Definition: Mod.cs:1090
virtual void LoadResources()
Definition: Mod.cs:108
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:32
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:572
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:1415
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:874
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:1467
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:1623
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:1273
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:72
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:794
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:357
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:1237
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:76
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:425
bool LoadResourceLegacy(string path, int length, Func< Stream > getStream)
Definition: Mod.cs:185
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:476
void AddProjectile(string name, ModProjectile projectile)
Adds a type of projectile to the game with the specified name.
Definition: Mod.cs:715
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:1574
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:1009
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:600
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:135
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:24
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:649
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:1592
ModConfig GetConfig(string name)
Definition: Mod.cs:1647
string Name
The name of this GlobalTile instance.
Definition: GlobalTile.cs:23
static int NetModCount
Definition: ModNet.cs:65
Manages content added by mods. Liasons between mod content and Terraria&#39;s arrays and oversees the Loa...
Definition: ModContent.cs:24
ModPacket GetPacket(int capacity=256)
Creates a ModPacket object that you can write to and then send between servers and clients...
Definition: Mod.cs:1633
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:1208
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:99
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:238
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:70
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:148
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:1120
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:939
This class serves as a place for you to place all your properties and hooks for each mount...
Definition: ModMountData.cs:9
void AddCommand(string name, ModCommand mc)
Manually add a Command during Load
Definition: Mod.cs:1378
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:105
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:339
string Name
The internal name of this water style.
SoundEffect GetSound(string name)
Shorthand for calling ModContent.GetSound(this.FileName(name)).
Definition: Mod.cs:1554
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:1484
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:64
Texture2D GetTexture(string name)
Shorthand for calling ModContent.GetTexture(this.FileName(name)).
Definition: Mod.cs:1518
void AddGlobalItem(string name, GlobalItem globalItem)
Adds the given GlobalItem instance to this mod with the provided name.
Definition: Mod.cs:290
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:40
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:690
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:1146
void AddConfig(string name, ModConfig mc)
Definition: Mod.cs:224
void AddBossHeadTexture(string texture, int npcType=-1)
Assigns a head texture that can be used by NPCs on the map.
Definition: Mod.cs:896
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:93
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:523
void AddGlobalRecipe(string name, GlobalRecipe globalRecipe)
Manually add a Global Recipe during Load
Definition: Mod.cs:1355
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:838
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:23
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:1538
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:193
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:1304
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:1335
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:11
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:1608
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:985
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:1181