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