TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches

◆ SaveNPCs()

static List< TagCompound > Terraria.ModLoader.IO.WorldIO.SaveNPCs ( )
inlinestaticpackage

Definition at line 130 of file WorldIO.cs.

131 {
133 TagCompound data = new TagCompound();
134 for (int index = 0; index < Main.maxNPCs; index++)
135 {
136 NPC npc = Main.npc[index];
137 if (!npc.active || !NPCLoader.SavesAndLoads(npc))
138 {
139 continue;
140 }
142 EntityGlobalsEnumerator<GlobalNPC> enumerator = NPCLoader.HookSaveData.Enumerate(npc).GetEnumerator();
143 while (enumerator.MoveNext())
144 {
145 GlobalNPC g = enumerator.Current;
147 {
148 globalData.AddRange(unloadedGlobalNPC.data);
149 continue;
150 }
151 g.SaveData(npc, data);
152 if (data.Count != 0)
153 {
154 globalData.Add(new TagCompound
155 {
156 ["mod"] = g.Mod.Name,
157 ["name"] = g.Name,
158 ["data"] = data
159 });
160 data = new TagCompound();
161 }
162 }
163 TagCompound tag;
164 if (NPCLoader.IsModNPC(npc))
165 {
166 npc.ModNPC.SaveData(data);
167 tag = new TagCompound
168 {
169 ["mod"] = npc.ModNPC.Mod.Name,
170 ["name"] = npc.ModNPC.Name
171 };
172 if (data.Count != 0)
173 {
174 tag["data"] = data;
175 data = new TagCompound();
176 }
177 if (npc.townNPC)
178 {
179 tag["displayName"] = npc.GivenName;
180 tag["homeless"] = npc.homeless;
181 tag["homeTileX"] = npc.homeTileX;
182 tag["homeTileY"] = npc.homeTileY;
183 tag["isShimmered"] = NPC.ShimmeredTownNPCs[npc.type];
184 tag["npcTownVariationIndex"] = npc.townNpcVariationIndex;
185 }
186 }
187 else
188 {
189 if (globalData.Count == 0)
190 {
191 continue;
192 }
193 tag = new TagCompound
194 {
195 ["mod"] = "Terraria",
196 ["name"] = NPCID.Search.GetName(npc.type)
197 };
198 }
199 tag["x"] = npc.position.X;
200 tag["y"] = npc.position.Y;
201 tag["globalData"] = globalData;
202 list.Add(tag);
203 }
204 return list;
205 }
static readonly IdDictionary Search
Definition NPCID.cs:12911

References Terraria.Entity.active, Terraria.ModLoader.IO.TagCompound.Count, Terraria.NPC.GivenName, Terraria.NPC.homeless, Terraria.NPC.homeTileX, Terraria.NPC.homeTileY, Terraria.ModLoader.NPCLoader.HookSaveData, Terraria.ModLoader.NPCLoader.IsModNPC(), Terraria.Main.maxNPCs, Terraria.NPC.ModNPC, Terraria.Main.npc, Terraria.Entity.position, Terraria.ModLoader.NPCLoader.SavesAndLoads(), Terraria.ID.NPCID.Search, Terraria.NPC.ShimmeredTownNPCs, Terraria.NPC.townNPC, Terraria.NPC.townNpcVariationIndex, and Terraria.NPC.type.

Referenced by Terraria.ModLoader.IO.WorldIO.Save().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: