Modding Terraria – Part 6.5 adding an NPC to Census
Modding Terraria is a fun method to add and adjust features playfully and learn more about programming.
This post has been updated to work with tModLoader v2023.9.3.0
In this part, we will cover adding an NPC to Census! Census is a mod that acts as a checklist for the housing panel. Instead of your regular housing panel, it will also show the missing townspeople with optional tips on unlocking said NPC.
For this tutorial, we will continue with our code from the last part. You can find it here if you haven’t read that one yet.
Understanding this tutorial is key for your development as a Terraria modder because one often overlooks the difficulty of making two mods compatible. Imagine the following scenario: you have 2 mods that both edit the guide and give him a different name. The first mod will name him Paul, and the second mod will name him Jeff. Which name it becomes depends on the load order of the mods, but ultimately, one gets overridden. While the guide’s name might not be the greatest example, it’s setting the stage for this article.
Without further ado, let’s get right into it.
Adding a NPC to Census
Open up your project and navigate to the Localization directory. If you can’t seem to find this directory, make sure you’re working in either a completely fresh mod project or you’ve exported the localization files through tModLoader. You can find the export option by going to “Manage Mods”, clicking on the green question mark icon and then clicking on “Extract Localization”
Inside this localization directory, you should see one or multiple *.hjson files. Opening it up we can find the following snippet:
NPCs: {
Bob: {
TownNPCMood: {
Princess_LovesNPC: I like {NPCName}.
LikeNPC_Princess: I like {NPCName}.
HateCrowded: I hate how crowded I am.
DislikeCrowded: I dislike how crowded I am.
LoveSpace: I love having so much space.
FarFromHome: I am too far from home.
NoHome: I hate not having a home.
Content: I am content.
}
DisplayName: Bob
Census.SpawnCondition: Conditions unknown
}
}
The following line is what we’re looking for Census.SpawnCondition: Conditions unknown. We can update this to say Census.SpawnCondition: What's he doing in the overworld?.
Save the file and open up tModLoader. You don’t have to rebuild for this change. Just hop into the game and watch your chance appear!
This practical knowledge should be everything we need–time to rebuild our mod inside TmodLoader and hop into a game.

Conclusion
As you can see from the image above, we’ve successfully added our custom NPC to the Census mod.
The core principles of loading a reference to another mod and checking for its existence is how t tackle most questions and problems regarding mod compatibility. This same principle applies to selling custom items through an NPC when you’ve done something else in a different mod.
Let’s take Calamity as an example. This mod features many custom bosses, including Leviathan and Anahita. Let’s say we’ve beaten them. In our own mod, we can now load in a reference to Calamity and check inside our NPC’s SetupShop method whether we’ve won the boss fight. If we have, we can let our NPC sell different items.
Including such feature will be a good exercise in order to learn more about inter-mod communication and is also something we will go over again in another tutorial. Stay tuned for more.




