Terraria ModLoader  0.10.1.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 
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 void AddRecipeGroups() {
89  }
90 
94  public virtual void AddRecipes() {
95  }
96 
100  public virtual void PostAddRecipes() {
101  }
102 
103  public virtual void LoadResources() {
104  if (File == null)
105  return;
106 
107  fileHandle = File.Open();
108 
109  var skipCache = new HashSet<string>();
110  foreach (var entry in File) {
111  Interface.loadMods.SubProgressText = entry.Name;
112 
113  Stream _stream = null;
114  Stream GetStream() => _stream = File.GetStream(entry);
115 
116  if (LoadResource(entry.Name, entry.Length, GetStream))
117  skipCache.Add(entry.Name);
118 
119  _stream?.Dispose();
120  }
121  File.CacheFiles(skipCache);
122  }
123 
130  public virtual void Close() {
131  fileHandle?.Dispose();
132  if (File != null && File.IsOpen)
133  throw new IOException($"TModFile has open handles: {File.path}");
134  }
135 
143  public virtual bool LoadResource(string path, int length, Func<Stream> getStream) {
144  if (tModLoaderVersion < new Version(0, 11) && LoadResourceLegacy(path, length, getStream)) // TODO LoadResourceLegacy is marked obsolete
145  return false;
146 
147  string extension = Path.GetExtension(path).ToLower();
148  path = Path.ChangeExtension(path, null);
149  switch (extension) {
150  case ".png":
151  case ".rawimg":
152  if (!Main.dedServ)
153  LoadTexture(path, getStream(), extension == ".rawimg");
154  return true;
155  case ".wav":
156  case ".mp3":
157  case ".ogg":
158  //Main.engine == null would be more sensible, but only the waveBank fails on Linux when there is no audio hardware
159  if (Main.dedServ || Main.waveBank == null) { }
160  else if (path.Contains("Music/"))
161  musics[path] = LoadMusic(path, extension);
162  else
163  sounds[path] = LoadSound(getStream(), length, extension);
164  return true;
165  case ".xnb":
166  if (Main.dedServ) { }
167  else if (path.StartsWith("Fonts/"))
168  fonts[path] = Main.instance.OurLoad<DynamicSpriteFont>("tmod:"+Name+"/"+path);
169  else if (path.StartsWith("Effects/"))
170  effects[path] = Main.ShaderContentManager.Load<Effect>("tmod:"+Name+"/"+path);
171  else
172  throw new ResourceLoadException(Language.GetTextValue("tModLoader.LoadErrorUnknownXNBFileHint", path));
173  return true;
174  }
175 
176  return false;
177  }
178 
179  [Obsolete]
180  private bool LoadResourceLegacy(string path, int length, Func<Stream> getStream) {
181  using (var stream = getStream()) {
182  LoadResourceFromStream(path, length, new BinaryReader(stream));
183  return stream.Position > 0;
184  }
185  }
186 
187  [Obsolete("Use LoadResource instead", true)]
188  public virtual void LoadResourceFromStream(string path, int len, BinaryReader reader) {
189  }
190 
191  internal void AutoloadConfig()
192  {
193  if (Code == null)
194  return;
195 
196  // TODO: Attribute to specify ordering of ModConfigs
197  foreach (Type type in Code.GetTypes().OrderBy(type => type.FullName))
198  {
199  if (type.IsAbstract)
200  {
201  continue;
202  }
203  if (type.IsSubclassOf(typeof(ModConfig)))
204  {
205  var mc = (ModConfig)Activator.CreateInstance(type);
206  // Skip loading ClientSide on Main.dedServ?
207  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.
208  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");
209  if (mc.Mode == ConfigScope.ClientSide && Side == ModSide.Server) // Doesn't make sense.
210  throw new Exception($"The ModConfig {mc.Name} can't be loaded because the config is ClientSide but this Mods ModSide is Server");
211  mc.mod = this;
212  var name = type.Name;
213  if (mc.Autoload(ref name))
214  AddConfig(name, mc);
215  }
216  }
217  }
218 
219  public void AddConfig(string name, ModConfig mc)
220  {
221  mc.Name = name;
222  mc.mod = this;
223 
224  ConfigManager.Add(mc);
225  }
226 
233  public void AddItem(string name, ModItem item) {
234  if (!loading)
235  throw new Exception(Language.GetTextValue("tModLoader.LoadErrorAddItemOnlyInLoad"));
236 
237  if (items.ContainsKey(name))
238  throw new Exception(Language.GetTextValue("tModLoader.LoadError2ModItemSameName", name));
239 
240  item.mod = this;
241  item.Name = name;
242  item.DisplayName = GetOrCreateTranslation(string.Format("Mods.{0}.ItemName.{1}", Name, name));
243  item.Tooltip = GetOrCreateTranslation(string.Format("Mods.{0}.ItemTooltip.{1}", Name, name), true);
244 
245  item.item.ResetStats(ItemLoader.ReserveItemID());
246  item.item.modItem = item;
247 
248  items[name] = item;
249  ItemLoader.items.Add(item);
250  }
251 
257  public ModItem GetItem(string name) => items.TryGetValue(name, out var item) ? item : null;
258 
264  public T GetItem<T>() where T : ModItem => (T)GetItem(typeof(T).Name);
265 
271  public int ItemType(string name) => GetItem(name)?.item.type ?? 0;
272 
278  public int ItemType<T>() where T : ModItem => ItemType(typeof(T).Name);
279 
285  public void AddGlobalItem(string name, GlobalItem globalItem) {
286  if (!loading)
287  throw new Exception("AddGlobalItem can only be called from Mod.Load or Mod.Autoload");
288 
289  ItemLoader.VerifyGlobalItem(globalItem);
290 
291  globalItem.mod = this;
292  globalItem.Name = name;
293 
294  globalItems[name] = globalItem;
295  globalItem.index = ItemLoader.globalItems.Count;
296  ItemLoader.globalIndexes[Name + ':' + name] = ItemLoader.globalItems.Count;
297  if (ItemLoader.globalIndexesByType.ContainsKey(globalItem.GetType())) {
298  ItemLoader.globalIndexesByType[globalItem.GetType()] = -1;
299  }
300  else {
301  ItemLoader.globalIndexesByType[globalItem.GetType()] = ItemLoader.globalItems.Count;
302  }
303  ItemLoader.globalItems.Add(globalItem);
304  }
305 
311  public GlobalItem GetGlobalItem(string name) => globalItems.TryGetValue(name, out var globalItem) ? globalItem : null;
312 
318  public T GetGlobalItem<T>() where T : GlobalItem => (T)GetGlobalItem(typeof(T).Name);
319 
334  public int AddEquipTexture(ModItem item, EquipType type, string name, string texture,
335  string armTexture = "", string femaleTexture = "") {
336  return AddEquipTexture(new EquipTexture(), item, type, name, texture, armTexture, femaleTexture);
337  }
338 
352  public int AddEquipTexture(EquipTexture equipTexture, ModItem item, EquipType type, string name, string texture,
353  string armTexture = "", string femaleTexture = "") {
354  if (!loading)
355  throw new Exception("AddEquipTexture can only be called from Mod.Load or Mod.Autoload");
356 
357  ModContent.GetTexture(texture); //ensure texture exists
358 
359  equipTexture.Texture = texture;
360  equipTexture.mod = this;
361  equipTexture.Name = name;
362  equipTexture.Type = type;
363  equipTexture.item = item;
364  int slot = equipTexture.Slot = EquipLoader.ReserveEquipID(type);
365 
366  EquipLoader.equipTextures[type][slot] = equipTexture;
367  equipTextures[Tuple.Create(name, type)] = equipTexture;
368 
369  if (type == EquipType.Body) {
370  if (femaleTexture == null || !ModContent.TextureExists(femaleTexture))
371  femaleTexture = texture;
372  EquipLoader.femaleTextures[slot] = femaleTexture;
373 
374  ModContent.GetTexture(armTexture); //ensure texture exists
375  EquipLoader.armTextures[slot] = armTexture;
376  }
377  if (item != null) {
378  IDictionary<EquipType, int> slots;
379  if (!EquipLoader.idToSlot.TryGetValue(item.item.type, out slots))
380  EquipLoader.idToSlot[item.item.type] = slots = new Dictionary<EquipType, int>();
381 
382  slots[type] = slot;
383  if (type == EquipType.Head || type == EquipType.Body || type == EquipType.Legs)
384  EquipLoader.slotToId[type][slot] = item.item.type;
385  }
386  return slot;
387  }
388 
395  public EquipTexture GetEquipTexture(string name, EquipType type) =>
396  equipTextures.TryGetValue(Tuple.Create(name, type), out var texture) ? texture : null;
397 
404  public int GetEquipSlot(string name, EquipType type) => GetEquipTexture(name, type)?.Slot ?? -1;
405 
412  public sbyte GetAccessorySlot(string name, EquipType type) => (sbyte)GetEquipSlot(name, type);
413 
420  public void AddPrefix(string name, ModPrefix prefix) {
421  if (!loading)
422  throw new Exception("AddPrefix can only be called from Mod.Load or Mod.Autoload");
423 
424  if (prefixes.ContainsKey(name))
425  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.");
426 
427  prefix.mod = this;
428  prefix.Name = name;
429  prefix.DisplayName = GetOrCreateTranslation(string.Format("Mods.{0}.Prefix.{1}", Name, name));
430  prefix.Type = ModPrefix.ReservePrefixID();
431 
432  prefixes[name] = prefix;
433  ModPrefix.prefixes.Add(prefix);
434  ModPrefix.categoryPrefixes[prefix.Category].Add(prefix);
435  }
436 
442  public ModPrefix GetPrefix(string name) => prefixes.TryGetValue(name, out var prefix) ? prefix : null;
443 
449  public T GetPrefix<T>() where T : ModPrefix => (T)GetPrefix(typeof(T).Name);
450 
456  public byte PrefixType(string name) => GetPrefix(name)?.Type ?? 0;
457 
463  public byte PrefixType<T>() where T : ModPrefix => PrefixType(typeof(T).Name);
464 
471  public void AddDust(string name, ModDust dust, string texture = "") {
472  if (!loading)
473  throw new Exception("AddDust can only be called from Mod.Load or Mod.Autoload");
474 
475  dust.mod = this;
476  dust.Name = name;
477  dust.Type = ModDust.ReserveDustID();
478  dust.Texture = !string.IsNullOrEmpty(texture) ? ModContent.GetTexture(texture) : Main.dustTexture;
479 
480  dusts[name] = dust;
481  ModDust.dusts.Add(dust);
482  }
483 
489  public ModDust GetDust(string name) => dusts.TryGetValue(name, out var dust) ? dust : null;
490 
496  public T GetDust<T>() where T : ModDust => (T)GetDust(typeof(T).Name);
497 
503  public int DustType(string name) => GetDust(name)?.Type ?? 0;
504 
510  public int DustType<T>() where T : ModDust => DustType(typeof(T).Name);
511 
518  public void AddTile(string name, ModTile tile, string texture) {
519  if (!loading)
520  throw new Exception("AddItem can only be called from Mod.Load or Mod.Autoload");
521 
522  if (tiles.ContainsKey(name))
523  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.");
524 
525  tile.mod = this;
526  tile.Name = name;
527  tile.Type = (ushort)TileLoader.ReserveTileID();
528  tile.texture = texture;
529 
530  tiles[name] = tile;
531  TileLoader.tiles.Add(tile);
532  }
533 
539  public ModTile GetTile(string name) => tiles.TryGetValue(name, out var tile) ? tile : null;
540 
546  public T GetTile<T>() where T : ModTile => (T)GetTile(typeof(T).Name);
547 
553  public int TileType(string name) => GetTile(name)?.Type ?? 0;
554 
560  public int TileType<T>() where T : ModTile => TileType(typeof(T).Name);
561 
567  public void AddGlobalTile(string name, GlobalTile globalTile) {
568  if (!loading)
569  throw new Exception("AddGlobalTile can only be called from Mod.Load or Mod.Autoload");
570 
571  globalTile.mod = this;
572  globalTile.Name = name;
573 
574  globalTiles[name] = globalTile;
575  TileLoader.globalTiles.Add(globalTile);
576  }
577 
583  public GlobalTile GetGlobalTile(string name) => globalTiles.TryGetValue(name, out var globalTile) ? globalTile : null;
584 
590  public T GetGlobalTile<T>() where T : GlobalTile => (T)GetGlobalTile(typeof(T).Name);
591 
595  public void AddTileEntity(string name, ModTileEntity entity) {
596  if (!loading)
597  throw new Exception("AddTileEntity can only be called from Mod.Load or Mod.Autoload");
598 
599  int id = ModTileEntity.ReserveTileEntityID();
600  entity.mod = this;
601  entity.Name = name;
602  entity.Type = id;
603  entity.type = (byte)id;
604 
605  tileEntities[name] = entity;
606  ModTileEntity.tileEntities.Add(entity);
607  }
608 
614  public ModTileEntity GetTileEntity(string name) =>
615  tileEntities.TryGetValue(name, out var tileEntity) ? tileEntity : null;
616 
622  public T GetTileEntity<T>() where T : ModTileEntity => (T)GetTileEntity(typeof(T).Name);
623 
629  public int TileEntityType(string name) => GetTileEntity(name)?.Type ?? -1;
630 
636  public int TileEntityType<T>() where T : ModTileEntity => TileEntityType(typeof(T).Name);
637 
644  public void AddWall(string name, ModWall wall, string texture) {
645  if (!loading)
646  throw new Exception("AddWall can only be called from Mod.Load or Mod.Autoload");
647 
648  wall.mod = this;
649  wall.Name = name;
650  wall.Type = (ushort)WallLoader.ReserveWallID();
651  wall.texture = texture;
652 
653  walls[name] = wall;
654  WallLoader.walls.Add(wall);
655  }
656 
662  public ModWall GetWall(string name) => walls.TryGetValue(name, out var wall) ? wall : null;
663 
664  public T GetWall<T>() where T : ModWall => (T)GetWall(typeof(T).Name);
665 
671  public int WallType(string name) => GetWall(name)?.Type ?? 0;
672 
678  public int WallType<T>() where T : ModWall => WallType(typeof(T).Name);
679 
685  public void AddGlobalWall(string name, GlobalWall globalWall) {
686  if (!loading)
687  throw new Exception("AddGlobalWall can only be called from Mod.Load or Mod.Autoload");
688 
689  globalWall.mod = this;
690  globalWall.Name = name;
691 
692  globalWalls[name] = globalWall;
693  WallLoader.globalWalls.Add(globalWall);
694  }
695 
701  public GlobalWall GetGlobalWall(string name) => globalWalls.TryGetValue(name, out var globalWall) ? globalWall : null;
702 
703  public T GetGlobalWall<T>() where T : GlobalWall => (T)GetGlobalWall(typeof(T).Name);
704 
710  public void AddProjectile(string name, ModProjectile projectile) {
711  if (!loading)
712  throw new Exception("AddProjectile can only be called from Mod.Load or Mod.Autoload");
713 
714  if (projectiles.ContainsKey(name))
715  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.");
716 
717  projectile.mod = this;
718  projectile.Name = name;
719  projectile.projectile.type = ProjectileLoader.ReserveProjectileID();
720  projectile.DisplayName = GetOrCreateTranslation(string.Format("Mods.{0}.ProjectileName.{1}", Name, name));
721 
722  projectiles[name] = projectile;
723  ProjectileLoader.projectiles.Add(projectile);
724  }
725 
731  public ModProjectile GetProjectile(string name) => projectiles.TryGetValue(name, out var proj) ? proj : null;
732 
733  public T GetProjectile<T>() where T : ModProjectile => (T)GetProjectile(typeof(T).Name);
734 
740  public int ProjectileType(string name) => GetProjectile(name)?.projectile.type ?? 0;
741 
747  public int ProjectileType<T>() where T : ModProjectile => ProjectileType(typeof(T).Name);
748 
754  public void AddGlobalProjectile(string name, GlobalProjectile globalProjectile) {
755  if (!loading)
756  throw new Exception("AddGlobalProjectile can only be called from Mod.Load or Mod.Autoload");
757 
758  ProjectileLoader.VerifyGlobalProjectile(globalProjectile);
759 
760  globalProjectile.mod = this;
761  globalProjectile.Name = name;
762 
763  globalProjectiles[name] = globalProjectile;
764  globalProjectile.index = ProjectileLoader.globalProjectiles.Count;
765  ProjectileLoader.globalIndexes[Name + ':' + name] = ProjectileLoader.globalProjectiles.Count;
766  if (ProjectileLoader.globalIndexesByType.ContainsKey(globalProjectile.GetType())) {
767  ProjectileLoader.globalIndexesByType[globalProjectile.GetType()] = -1;
768  }
769  else {
770  ProjectileLoader.globalIndexesByType[globalProjectile.GetType()] = ProjectileLoader.globalProjectiles.Count;
771  }
772  ProjectileLoader.globalProjectiles.Add(globalProjectile);
773  }
774 
780  public GlobalProjectile GetGlobalProjectile(string name) => globalProjectiles.TryGetValue(name, out var globalProj) ? globalProj : null;
781 
782  public T GetGlobalProjectile<T>() where T : GlobalProjectile => (T)GetGlobalProjectile(typeof(T).Name);
783 
789  public void AddNPC(string name, ModNPC npc) {
790  if (!loading)
791  throw new Exception("AddNPC can only be called from Mod.Load or Mod.Autoload");
792 
793  if (npcs.ContainsKey(name))
794  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.");
795 
796  npc.mod = this;
797  npc.Name = name;
798  npc.npc.type = NPCLoader.ReserveNPCID();
799  npc.DisplayName = GetOrCreateTranslation(string.Format("Mods.{0}.NPCName.{1}", Name, name));
800 
801  npcs[name] = npc;
802  NPCLoader.npcs.Add(npc);
803  }
804 
810  public ModNPC GetNPC(string name) => npcs.TryGetValue(name, out var npc) ? npc : null;
811 
812  public T GetNPC<T>() where T : ModNPC => (T)GetNPC(typeof(T).Name);
813 
819  public int NPCType(string name) => GetNPC(name)?.npc.type ?? 0;
820 
826  public int NPCType<T>() where T : ModNPC => NPCType(typeof(T).Name);
827 
833  public void AddGlobalNPC(string name, GlobalNPC globalNPC) {
834  if (!loading)
835  throw new Exception("AddGlobalNPC can only be called from Mod.Load or Mod.Autoload");
836 
837  NPCLoader.VerifyGlobalNPC(globalNPC);
838 
839  globalNPC.mod = this;
840  globalNPC.Name = name;
841 
842  globalNPCs[name] = globalNPC;
843  globalNPC.index = NPCLoader.globalNPCs.Count;
844  NPCLoader.globalIndexes[Name + ':' + name] = NPCLoader.globalNPCs.Count;
845  if (NPCLoader.globalIndexesByType.ContainsKey(globalNPC.GetType())) {
846  NPCLoader.globalIndexesByType[globalNPC.GetType()] = -1;
847  }
848  else {
849  NPCLoader.globalIndexesByType[globalNPC.GetType()] = NPCLoader.globalNPCs.Count;
850  }
851  NPCLoader.globalNPCs.Add(globalNPC);
852  }
853 
859  public GlobalNPC GetGlobalNPC(string name) => globalNPCs.TryGetValue(name, out var globalNPC) ? globalNPC : null;
860 
861  public T GetGlobalNPC<T>() where T : GlobalNPC => (T)GetGlobalNPC(typeof(T).Name);
862 
869  public void AddNPCHeadTexture(int npcType, string texture) {
870  if (!loading)
871  throw new Exception("AddNPCHeadTexture can only be called from Mod.Load or Mod.Autoload");
872 
873  int slot = NPCHeadLoader.ReserveHeadSlot();
874  NPCHeadLoader.heads[texture] = slot;
875  if (!Main.dedServ) {
876  ModContent.GetTexture(texture);
877  }
878  /*else if (Main.dedServ && !(ModLoader.FileExists(texture + ".png") || ModLoader.FileExists(texture + ".rawimg")))
879  {
880  throw new MissingResourceException(texture);
881  }*/
882  NPCHeadLoader.npcToHead[npcType] = slot;
883  NPCHeadLoader.headToNPC[slot] = npcType;
884  }
885 
891  public void AddBossHeadTexture(string texture, int npcType = -1) {
892  if (!loading)
893  throw new Exception("AddBossHeadTexture can only be called from Mod.Load or Mod.Autoload");
894 
895  int slot = NPCHeadLoader.ReserveBossHeadSlot(texture);
896  NPCHeadLoader.bossHeads[texture] = slot;
897  ModContent.GetTexture(texture);
898  if (npcType >= 0) {
899  NPCHeadLoader.npcToBossHead[npcType] = slot;
900  }
901  }
902 
908  public void AddPlayer(string name, ModPlayer player) {
909  if (!loading)
910  throw new Exception("AddPlayer can only be called from Mod.Load or Mod.Autoload");
911 
912  player.mod = this;
913  player.Name = name;
914 
915  players[name] = player;
916  PlayerHooks.Add(player);
917  }
918 
924  public ModPlayer GetPlayer(string name) => players.TryGetValue(name, out var player) ? player : null;
925 
926  public T GetPlayer<T>() where T : ModPlayer => (T)GetPlayer(typeof(T).Name);
927 
934  public void AddBuff(string name, ModBuff buff, string texture) {
935  if (!loading)
936  throw new Exception("AddBuff can only be called from Mod.Load or Mod.Autoload");
937 
938  if (buffs.ContainsKey(name))
939  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.");
940 
941  buff.mod = this;
942  buff.Name = name;
943  buff.Type = BuffLoader.ReserveBuffID();
944  buff.texture = texture;
945  buff.DisplayName = GetOrCreateTranslation(string.Format("Mods.{0}.BuffName.{1}", Name, name));
946  buff.Description = GetOrCreateTranslation(string.Format("Mods.{0}.BuffDescription.{1}", Name, name));
947 
948  buffs[name] = buff;
949  BuffLoader.buffs.Add(buff);
950  }
951 
957  public ModBuff GetBuff(string name) => buffs.TryGetValue(name, out var buff) ? buff : null;
958 
959  public T GetBuff<T>() where T : ModBuff => (T)GetBuff(typeof(T).Name);
960 
966  public int BuffType(string name) => GetBuff(name)?.Type ?? 0;
967 
973  public int BuffType<T>() where T : ModBuff => BuffType(typeof(T).Name);
974 
980  public void AddGlobalBuff(string name, GlobalBuff globalBuff) {
981  globalBuff.mod = this;
982  globalBuff.Name = name;
983 
984  globalBuffs[name] = globalBuff;
985  BuffLoader.globalBuffs.Add(globalBuff);
986  }
987 
993  public GlobalBuff GetGlobalBuff(string name) => globalBuffs.TryGetValue(name, out var globalBuff) ? globalBuff : null;
994 
995  public T GetGlobalBuff<T>() where T : GlobalBuff => (T)GetGlobalBuff(typeof(T).Name);
996 
1004  public void AddMount(string name, ModMountData mount, string texture,
1005  IDictionary<MountTextureType, string> extraTextures = null) {
1006  if (!loading)
1007  throw new Exception("AddMount can only be called from Mod.Load or Mod.Autoload");
1008 
1009  if (Mount.mounts == null || Mount.mounts.Length == MountID.Count)
1010  Mount.Initialize();
1011 
1012  mount.mod = this;
1013  mount.Name = name;
1014  mount.Type = MountLoader.ReserveMountID();
1015  mount.texture = texture;
1016 
1017  mountDatas[name] = mount;
1018  MountLoader.mountDatas[mount.Type] = mount;
1019 
1020  if (extraTextures == null)
1021  return;
1022 
1023  foreach (var entry in extraTextures) {
1024  if (!ModContent.TextureExists(entry.Value))
1025  continue;
1026 
1027  Texture2D extraTexture = ModContent.GetTexture(entry.Value);
1028  switch (entry.Key) {
1029  case MountTextureType.Back:
1030  mount.mountData.backTexture = extraTexture;
1031  break;
1032  case MountTextureType.BackGlow:
1033  mount.mountData.backTextureGlow = extraTexture;
1034  break;
1035  case MountTextureType.BackExtra:
1036  mount.mountData.backTextureExtra = extraTexture;
1037  break;
1038  case MountTextureType.BackExtraGlow:
1039  mount.mountData.backTextureExtraGlow = extraTexture;
1040  break;
1041  case MountTextureType.Front:
1042  mount.mountData.frontTexture = extraTexture;
1043  break;
1044  case MountTextureType.FrontGlow:
1045  mount.mountData.frontTextureGlow = extraTexture;
1046  break;
1047  case MountTextureType.FrontExtra:
1048  mount.mountData.frontTextureExtra = extraTexture;
1049  break;
1050  case MountTextureType.FrontExtraGlow:
1051  mount.mountData.frontTextureExtraGlow = extraTexture;
1052  break;
1053  }
1054  }
1055  }
1056 
1062  public ModMountData GetMount(string name) => mountDatas.TryGetValue(name, out var modMountData) ? modMountData : null;
1063 
1064  public T GetMount<T>() where T : ModMountData => (T)GetMount(typeof(T).Name);
1065 
1071  public int MountType(string name) => GetMount(name)?.Type ?? 0;
1072 
1078  public int MountType<T>() where T : ModMountData => MountType(typeof(T).Name);
1079 
1085  public void AddModWorld(string name, ModWorld modWorld) {
1086  if (!loading)
1087  throw new Exception("AddModWorld can only be called from Mod.Load or Mod.Autoload");
1088 
1089  modWorld.mod = this;
1090  modWorld.Name = name;
1091 
1092  worlds[name] = modWorld;
1093  WorldHooks.Add(modWorld);
1094  }
1095 
1101  public ModWorld GetModWorld(string name) => worlds.TryGetValue(name, out var world) ? world : null;
1102 
1108  public T GetModWorld<T>() where T : ModWorld => (T)GetModWorld(typeof(T).Name);
1109 
1115  public void AddUgBgStyle(string name, ModUgBgStyle ugBgStyle) {
1116  if (!loading)
1117  throw new Exception("AddUgBgStyle can only be called from Mod.Load or Mod.Autoload");
1118 
1119  ugBgStyle.mod = this;
1120  ugBgStyle.Name = name;
1121  ugBgStyle.Slot = UgBgStyleLoader.ReserveBackgroundSlot();
1122 
1123  ugBgStyles[name] = ugBgStyle;
1124  UgBgStyleLoader.ugBgStyles.Add(ugBgStyle);
1125  }
1126 
1132  public ModUgBgStyle GetUgBgStyle(string name) => ugBgStyles.TryGetValue(name, out var bgStyle) ? bgStyle : null;
1133 
1134  public T GetUgBgStyle<T>() where T : ModUgBgStyle => (T)GetUgBgStyle(typeof(T).Name);
1135 
1141  public void AddSurfaceBgStyle(string name, ModSurfaceBgStyle surfaceBgStyle) {
1142  if (!loading)
1143  throw new Exception("AddSurfaceBgStyle can only be called from Mod.Load or Mod.Autoload");
1144 
1145  surfaceBgStyle.mod = this;
1146  surfaceBgStyle.Name = name;
1147  surfaceBgStyle.Slot = SurfaceBgStyleLoader.ReserveBackgroundSlot();
1148 
1149  surfaceBgStyles[name] = surfaceBgStyle;
1150  SurfaceBgStyleLoader.surfaceBgStyles.Add(surfaceBgStyle);
1151  }
1152 
1158  public ModSurfaceBgStyle GetSurfaceBgStyle(string name) => surfaceBgStyles.TryGetValue(name, out var bgStyle) ? bgStyle : null;
1159 
1160  public T GetSurfaceBgStyle<T>() where T : ModSurfaceBgStyle => (T)GetSurfaceBgStyle(typeof(T).Name);
1161 
1167  public int GetSurfaceBgStyleSlot(string name) => GetSurfaceBgStyle(name)?.Slot ?? -1;
1168 
1169  public int GetSurfaceBgStyleSlot<T>() where T : ModSurfaceBgStyle => GetSurfaceBgStyleSlot(typeof(T).Name);
1170 
1176  public void AddGlobalBgStyle(string name, GlobalBgStyle globalBgStyle) {
1177  if (!loading)
1178  throw new Exception("AddGlobalBgStyle can only be called from Mod.Load or Mod.Autoload");
1179 
1180  globalBgStyle.mod = this;
1181  globalBgStyle.Name = name;
1182 
1183  globalBgStyles[name] = globalBgStyle;
1184  GlobalBgStyleLoader.globalBgStyles.Add(globalBgStyle);
1185  }
1186 
1192  public GlobalBgStyle GetGlobalBgStyle(string name) => globalBgStyles.TryGetValue(name, out var bgStyle) ? bgStyle : null;
1193 
1194  public T GetGlobalBgStyle<T>() where T : GlobalBgStyle => (T)GetGlobalBgStyle(typeof(T).Name);
1195 
1203  public void AddWaterStyle(string name, ModWaterStyle waterStyle, string texture, string blockTexture) {
1204  if (!loading)
1205  throw new Exception("AddWaterStyle can only be called from Mod.Load or Mod.Autoload");
1206 
1207  waterStyle.mod = this;
1208  waterStyle.Name = name;
1209  waterStyle.Type = WaterStyleLoader.ReserveStyle();
1210  waterStyle.texture = texture;
1211  waterStyle.blockTexture = blockTexture;
1212 
1213  waterStyles[name] = waterStyle;
1214  WaterStyleLoader.waterStyles.Add(waterStyle);
1215  }
1216 
1222  public ModWaterStyle GetWaterStyle(string name) => waterStyles.TryGetValue(name, out var waterStyle) ? waterStyle : null;
1223 
1224  public T GetWaterStyle<T>() where T : ModWaterStyle => (T)GetWaterStyle(typeof(T).Name);
1225 
1232  public void AddWaterfallStyle(string name, ModWaterfallStyle waterfallStyle, string texture) {
1233  if (!loading)
1234  throw new Exception("AddWaterfallStyle can only be called from Mod.Load or Mod.Autoload");
1235 
1236  waterfallStyle.mod = this;
1237  waterfallStyle.Name = name;
1238  waterfallStyle.Type = WaterfallStyleLoader.ReserveStyle();
1239  waterfallStyle.texture = texture;
1240 
1241  waterfallStyles[name] = waterfallStyle;
1242  WaterfallStyleLoader.waterfallStyles.Add(waterfallStyle);
1243  }
1244 
1250  public ModWaterfallStyle GetWaterfallStyle(string name) => waterfallStyles.TryGetValue(name, out var waterfallStyle) ? waterfallStyle : null;
1251 
1252  public T GetWaterfallStyle<T>() where T : ModWaterfallStyle => (T)GetWaterfallStyle(typeof(T).Name);
1253 
1259  public int GetWaterfallStyleSlot(string name) => GetWaterfallStyle(name)?.Type ?? -1;
1260 
1261  public int GetWaterfallStyleSlot<T>() where T : ModWaterfallStyle => GetWaterfallStyleSlot(typeof(T).Name);
1262 
1268  public void AddGore(string texture, ModGore modGore = null) {
1269  if (!loading)
1270  throw new Exception("AddGore can only be called from Mod.Load or Mod.Autoload");
1271 
1272  int id = ModGore.ReserveGoreID();
1273  ModGore.gores[texture] = id;
1274  if (modGore != null) {
1275  ModGore.modGores[id] = modGore;
1276  }
1277  }
1278 
1284  public int GetGoreSlot(string name) => ModGore.GetGoreSlot(Name + '/' + name);
1285 
1291  public int GetGoreSlot<T>() where T : ModGore => GetGoreSlot(typeof(T).Name);
1292 
1299  public void AddSound(SoundType type, string soundPath, ModSound modSound = null) {
1300  if (!loading)
1301  throw new Exception("AddSound can only be called from Mod.Load or Mod.Autoload");
1302  int id = SoundLoader.ReserveSoundID(type);
1303  SoundLoader.sounds[type][soundPath] = id;
1304  if (modSound != null) {
1305  SoundLoader.modSounds[type][id] = modSound;
1306  modSound.sound = ModContent.GetSound(soundPath);
1307  }
1308  }
1309 
1316  public int GetSoundSlot(SoundType type, string name) => SoundLoader.GetSoundSlot(type, Name + '/' + name);
1317 
1324  public LegacySoundStyle GetLegacySoundSlot(SoundType type, string name) => SoundLoader.GetLegacySoundSlot(type, Name + '/' + name);
1325 
1330  public void AddBackgroundTexture(string texture) {
1331  if (!loading)
1332  throw new Exception("AddBackgroundTexture can only be called from Mod.Load or Mod.Autoload");
1333 
1334  BackgroundTextureLoader.backgrounds[texture] = BackgroundTextureLoader.ReserveBackgroundSlot();
1335  ModContent.GetTexture(texture);
1336  }
1337 
1343  public int GetBackgroundSlot(string name) => BackgroundTextureLoader.GetBackgroundSlot(Name + '/' + name);
1344 
1350  public void AddGlobalRecipe(string name, GlobalRecipe globalRecipe) {
1351  if (!loading)
1352  throw new Exception("AddGlobalRecipe can only be called from Mod.Load or Mod.Autoload");
1353 
1354  globalRecipe.mod = this;
1355  globalRecipe.Name = name;
1356 
1357  globalRecipes[name] = globalRecipe;
1358  RecipeHooks.Add(globalRecipe);
1359  }
1360 
1366  public GlobalRecipe GetGlobalRecipe(string name) => globalRecipes.TryGetValue(name, out var globalRecipe) ? globalRecipe : null;
1367 
1368  public T GetGlobalRecipe<T>() where T : GlobalRecipe => (T)GetGlobalRecipe(typeof(T).Name);
1369 
1373  public void AddCommand(string name, ModCommand mc) {
1374  if (!loading)
1375  throw new Exception("AddCommand can only be called from Mod.Load or Mod.Autoload");
1376 
1377  mc.mod = this;
1378  mc.Name = name;
1379  CommandManager.Add(mc);
1380  }
1381 
1410  public void AddMusicBox(int musicSlot, int itemType, int tileType, int tileFrameY = 0) {
1411  if (!loading)
1412  throw new Exception("AddMusicBox can only be called from Mod.Load or Mod.Autoload");
1413 
1414  if (Main.waveBank == null)
1415  return;
1416 
1417  if (musicSlot < Main.maxMusic) {
1418  throw new ArgumentOutOfRangeException("Cannot assign music box to vanilla music ID " + musicSlot);
1419  }
1420  if (musicSlot >= SoundLoader.SoundCount(SoundType.Music)) {
1421  throw new ArgumentOutOfRangeException("Music ID " + musicSlot + " does not exist");
1422  }
1423  if (itemType < ItemID.Count) {
1424  throw new ArgumentOutOfRangeException("Cannot assign music box to vanilla item ID " + itemType);
1425  }
1426  if (ItemLoader.GetItem(itemType) == null) {
1427  throw new ArgumentOutOfRangeException("Item ID " + itemType + " does not exist");
1428  }
1429  if (tileType < TileID.Count) {
1430  throw new ArgumentOutOfRangeException("Cannot assign music box to vanilla tile ID " + tileType);
1431  }
1432  if (TileLoader.GetTile(tileType) == null) {
1433  throw new ArgumentOutOfRangeException("Tile ID " + tileType + " does not exist");
1434  }
1435  if (SoundLoader.musicToItem.ContainsKey(musicSlot)) {
1436  throw new ArgumentException("Music ID " + musicSlot + " has already been assigned a music box");
1437  }
1438  if (SoundLoader.itemToMusic.ContainsKey(itemType)) {
1439  throw new ArgumentException("Item ID " + itemType + " has already been assigned a music");
1440  }
1441  if (!SoundLoader.tileToMusic.ContainsKey(tileType)) {
1442  SoundLoader.tileToMusic[tileType] = new Dictionary<int, int>();
1443  }
1444  if (SoundLoader.tileToMusic[tileType].ContainsKey(tileFrameY)) {
1445  string message = "Y-frame " + tileFrameY + " of tile type " + tileType + " has already been assigned a music";
1446  throw new ArgumentException(message);
1447  }
1448  if (tileFrameY % 36 != 0) {
1449  throw new ArgumentException("Y-frame must be divisible by 36");
1450  }
1451  SoundLoader.musicToItem[musicSlot] = itemType;
1452  SoundLoader.itemToMusic[itemType] = musicSlot;
1453  SoundLoader.tileToMusic[tileType][tileFrameY] = musicSlot;
1454  }
1455 
1462  public ModHotKey RegisterHotKey(string name, string defaultKey) {
1463  if (!loading)
1464  throw new Exception("RegisterHotKey can only be called from Mod.Load or Mod.Autoload");
1465 
1466  return ModContent.RegisterHotKey(this, name, defaultKey);
1467  }
1468 
1473  public ModTranslation CreateTranslation(string key) =>
1474  new ModTranslation(string.Format("Mods.{0}.{1}", Name, key));
1475 
1479  public void AddTranslation(ModTranslation translation) {
1480  translations[translation.Key] = translation;
1481  }
1482 
1483  internal ModTranslation GetOrCreateTranslation(string key, bool defaultEmpty = false) {
1484  key = key.Replace(" ", "_");
1485  return translations.TryGetValue(key, out var translation) ? translation : new ModTranslation(key, defaultEmpty);
1486  }
1487 
1493  public byte[] GetFileBytes(string name) => File?.GetBytes(name);
1494 
1500  public Stream GetFileStream(string name, bool newFileStream = false) => File?.GetStream(name, newFileStream);
1501 
1507  public bool FileExists(string name) => File != null && File.HasFile(name);
1508 
1513  public Texture2D GetTexture(string name) {
1514  if (!textures.TryGetValue(name, out var t))
1515  throw new MissingResourceException(name, textures.Keys);
1516 
1517  return t;
1518  }
1519 
1525  public bool TextureExists(string name) => textures.ContainsKey(name);
1526 
1533  public void AddTexture(string name, Texture2D texture) {
1534  if (Main.dedServ)
1535  return;
1536 
1537  if (TextureExists(name))
1538  throw new Exception("Texture already exist: " + name);
1539 
1540  textures[name] = texture;
1541  }
1542 
1549  public SoundEffect GetSound(string name) {
1550  if (!sounds.TryGetValue(name, out var sound))
1551  throw new MissingResourceException(name);
1552 
1553  return sound;
1554  }
1555 
1561  public bool SoundExists(string name) => sounds.ContainsKey(name);
1562 
1569  public Music GetMusic(string name) {
1570  if (!musics.TryGetValue(name, out var music))
1571  throw new MissingResourceException(name);
1572 
1573  return music;
1574  }
1575 
1581  public bool MusicExists(string name) => musics.ContainsKey(name);
1582 
1587  public DynamicSpriteFont GetFont(string name) {
1588  if (!fonts.TryGetValue(name, out var font))
1589  throw new MissingResourceException(name);
1590 
1591  return font;
1592  }
1593 
1597  public bool FontExists(string name) => fonts.ContainsKey(name);
1598 
1603  public Effect GetEffect(string name) {
1604  if (!effects.TryGetValue(name, out var effect))
1605  throw new MissingResourceException(name);
1606 
1607  return effect;
1608  }
1609 
1613  public bool EffectExists(string name) => effects.ContainsKey(name);
1614 
1618  public virtual object Call(params object[] args) {
1619  return null;
1620  }
1621 
1628  public ModPacket GetPacket(int capacity = 256) {
1629  if (netID < 0)
1630  throw new Exception("Cannot get packet for " + Name + " because it does not exist on the other side");
1631 
1632  var p = new ModPacket(MessageID.ModPacket, capacity + 5);
1633  if (ModNet.NetModCount < 256)
1634  p.Write((byte)netID);
1635  else
1636  p.Write(netID);
1637 
1638  p.netID = netID;
1639  return p;
1640  }
1641 
1642  public ModConfig GetConfig(string name)
1643  {
1644  List<ModConfig> configs;
1645  if (ConfigManager.Configs.TryGetValue(this, out configs))
1646  {
1647  return configs.Single(x => x.Name == name);
1648  }
1649  return null;
1650  }
1651 
1652  public T GetConfig<T>() where T : ModConfig => (T)GetConfig(typeof(T).Name);
1653  }
1654 }
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:908
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:754
void AddModWorld(string name, ModWorld modWorld)
Adds a ModWorld to this mod with the given name.
Definition: Mod.cs:1085
virtual void LoadResources()
Definition: Mod.cs:103
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:567
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:1410
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:869
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:1462
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:1618
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:1268
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:70
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:789
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:352
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:1232
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:420
bool LoadResourceLegacy(string path, int length, Func< Stream > getStream)
Definition: Mod.cs:180
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:471
void AddProjectile(string name, ModProjectile projectile)
Adds a type of projectile to the game with the specified name.
Definition: Mod.cs:710
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:1569
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:1004
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:595
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:130
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:14
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:644
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:1587
ModConfig GetConfig(string name)
Definition: Mod.cs:1642
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:22
ModPacket GetPacket(int capacity=256)
Creates a ModPacket object that you can write to and then send between servers and clients...
Definition: Mod.cs:1628
static bool TextureExists(string name)
Returns whether or not a texture with the specified name exists.
Definition: ModContent.cs:89
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:1203
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:94
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:233
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:143
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:1115
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:934
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:1373
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:100
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:334
string Name
The internal name of this water style.
SoundEffect GetSound(string name)
Shorthand for calling ModContent.GetSound(this.FileName(name)).
Definition: Mod.cs:1549
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:1479
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:1513
void AddGlobalItem(string name, GlobalItem globalItem)
Adds the given GlobalItem instance to this mod with the provided name.
Definition: Mod.cs:285
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:139
void AddGlobalWall(string name, GlobalWall globalWall)
Adds the given GlobalWall instance to this mod with the provided name.
Definition: Mod.cs:685
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:13
void AddSurfaceBgStyle(string name, ModSurfaceBgStyle surfaceBgStyle)
Adds the given surface background style with the given name to this mod.
Definition: Mod.cs:1141
void AddConfig(string name, ModConfig mc)
Definition: Mod.cs:219
void AddBossHeadTexture(string texture, int npcType=-1)
Assigns a head texture that can be used by NPCs on the map.
Definition: Mod.cs:891
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:88
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:518
void AddGlobalRecipe(string name, GlobalRecipe globalRecipe)
Manually add a Global Recipe during Load
Definition: Mod.cs:1350
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:833
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:30
void AddTexture(string name, Texture2D texture)
Shorthand for calling ModLoader.AddTexture(this.FileName(name), texture).
Definition: Mod.cs:1533
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:188
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:1299
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:1330
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:86
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:1603
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:980
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:1176