tModLoader v0.11.8.9
A mod to make and play Terraria mods
NPCHeadLoader.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using Terraria.ID;
4
5namespace Terraria.ModLoader
6{
10 public static class NPCHeadLoader
11 {
15 public static readonly int vanillaHeadCount = Main.npcHeadTexture.Length;
19 public static readonly int vanillaBossHeadCount = Main.npcHeadBossTexture.Length;
20 private static int nextHead = vanillaHeadCount;
21 private static int nextBossHead = vanillaBossHeadCount;
22 internal static IDictionary<string, int> heads = new Dictionary<string, int>();
23 internal static IDictionary<string, int> bossHeads = new Dictionary<string, int>();
24 internal static IDictionary<int, int> npcToHead = new Dictionary<int, int>();
25 internal static IDictionary<int, int> headToNPC = new Dictionary<int, int>();
26 internal static IDictionary<int, int> npcToBossHead = new Dictionary<int, int>();
27
28 internal static int ReserveHeadSlot() {
29 int reserve = nextHead;
30 nextHead++;
31 return reserve;
32 }
33
34 internal static int ReserveBossHeadSlot(string texture) {
35 if (bossHeads.TryGetValue(texture, out int existing)) {
36 return existing;
37 }
38 int reserve = nextBossHead;
40 return reserve;
41 }
42
48 public static int GetHeadSlot(string texture) => heads.TryGetValue(texture, out int slot) ? slot : -1;
49
55 public static int GetBossHeadSlot(string texture) => bossHeads.TryGetValue(texture, out int slot) ? slot : -1;
56
57 internal static void ResizeAndFillArrays() {
58 Array.Resize(ref Main.npcHeadTexture, nextHead);
59 Array.Resize(ref Main.npcHeadBossTexture, nextBossHead);
60 foreach (string texture in heads.Keys) {
61 Main.npcHeadTexture[heads[texture]] = ModContent.GetTexture(texture);
62 }
63 foreach (string texture in bossHeads.Keys) {
64 Main.npcHeadBossTexture[bossHeads[texture]] = ModContent.GetTexture(texture);
65 }
66 foreach (int npc in npcToBossHead.Keys) {
67 NPCID.Sets.BossHeadTextures[npc] = npcToBossHead[npc];
68 }
69 }
70
71 internal static void Unload() {
74 heads.Clear();
75 bossHeads.Clear();
76 npcToHead.Clear();
77 headToNPC.Clear();
78 npcToBossHead.Clear();
79 }
80 //in Terraria.NPC.TypeToNum replace final return with this
81 internal static int GetNPCHeadSlot(int type) => npcToHead.TryGetValue(type, out int slot) ? slot : -1;
82
83 //in Terraria.NPC.NumToType replace final return with this
84 internal static int GetNPCFromHeadSlot(int slot) => headToNPC.TryGetValue(slot, out int type) ? type : -1;
85 }
86}
Manages content added by mods. Liasons between mod content and Terraria's arrays and oversees the Loa...
Definition: ModContent.cs:27
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 serves as a central place from which NPC head slots are stored and NPC head textures are a...
static readonly int vanillaBossHeadCount
The number of vanilla boss head textures that exist.
static readonly int vanillaHeadCount
The number of vanilla town NPC head textures that exist.
static int GetBossHeadSlot(string texture)
Gets the index of the boss head texture corresponding to the given texture path.
static int GetHeadSlot(string texture)
Gets the index of the head texture corresponding to the given texture path.