Modding Terraria – Part 5 adjusting loot tables
Modding Terraria is a fun method to add and adjust features in a playful way and learn more about programming. In this part, we will cover adjusting loot tables in Terraria!
This post has been updated to work with tModLoader v2023.9.3.0
We will continue where we left off in the previous part. If you haven´t read that one yet, you can find it here.
Adjusting loot tables in Terraria
This time, we will walk through the process of adjusting loot tables. Loot tables are the datasets of items and drop rates of an entity. To get a more clear example, let’s look at the loot table for Zombies:

From the image above, we can learn that a normal zombie has a 2% chance on defeat to drop a Shackle and a 0.4% chance for a Zombie Arm. This distribution of items and percentages is called a loot table or drop table.
In our last part, we created a summonable mount which you can craft with 10 dirt blocks. This ruins the immersion a bit. Therefore, let’s make it so that our Flight Permit becomes a droppable item from the Eye of Cthulhu. We will give it a 5% drop chance.
In order to do this we need to adjust a couple things and create some more files, so without further ado, let’s get started!
Open up tModLoader and your Visual Studio project.
Creating our loot table
Remember part 2, where we created friendly zombies? If not, you can find it here. In this post, we worked inside a directory called Npcs. We will use this directory again. Create or enter it and inside create a file called EyeOfCthulhu.cs. The name does not really matter and more often than not you’ll see people combine all their NPC-related stuff in the same file. Because we want to create an organized structure, we choose to create a NPC-specific file.
Inside this EyeOfCthulhu.cs file, add the following code
using Mountmod.Items.Mounts; // replace this with your own namespace
using Terraria;
using Terraria.GameContent.ItemDropRules;
using Terraria.ID;
using Terraria.ModLoader;
namespace Mountmod.Npcs // replace this with your own namespace
{
public class EyeOfCthulhu : GlobalNPC
{
public override void ModifyNPCLoot(NPC npc, NPCLoot npcLoot)
{
if (npc.type == NPCID.EyeofCthulhu)
{
npcLoot.Add(ItemDropRule.ByCondition(
Condition.DownedEyeOfCthulhu.ToDropCondition(ShowItemDropInUI.Always),
ModContent.ItemType<HotAirBalloonMountItem>(),
chanceDenominator: 2,
chanceNumerator: 1
));
}
}
}
}
There you have it. This is basically all we need to adjust loot tables. Let’s go over the code in a bit more detail, however. We create a public class and extend from GlobalNPC. This way, we can access the ModifyNPCLoot method. Inside this method, we create an if-statement to check whether the NPC type, which was defeated, is an instance of the Eye Of Cthulhu. If it is, our if-statement results in TRUE.
Next, we access the npcLoot.add function which takes multiple parameters, in our case the following four:
- A drop condition – for us this is defeating the Eye of Cthulhu which we then need to convert to a drop condition
- Our item which we want to be dropped – in our case, the flight permit (HotAirBalloonMountItem)
- The chance denominator, in a fraction this is under the line. In the case of 1/2 the denominator is 2
- The chance numerator, in a fraction this is above the line. In the case of 1/2 the numerator is 1
Right now we have set our drop rate to be 50%, 1 out of 2 occassions. Feel free to adjust this.
This is also where the statement about organization comes into play. Imagine wanting to adjust 20 mobs. Inside ModifyNPCLoot you could have 20 if-statements or you could have 20 files with just one statement.
Anyway, hop on into tModLoader, rebuild your mod and start your game. After a couple of tries on the Eye of Cthulhu, you should find yourself with a Flight Permit!






1 Comment