Mod Development Guide

Learn how to create amazing Terraria mods with tModLoader's C# API

20 min read Development Intermediate

Prerequisites

Development Environment

  • • Visual Studio 2022 (recommended)
  • • JetBrains Rider
  • • Visual Studio Code with C# extension
  • • .NET 6.0 SDK or later

Knowledge Requirements

  • • Basic C# programming
  • • Object-oriented concepts
  • • Familiarity with Terraria gameplay
  • • Basic understanding of game development

Development Setup

1 Install Development Tools

Choose your preferred C# development environment:

Visual Studio 2022

Full-featured IDE with excellent debugging

Download →

JetBrains Rider

Cross-platform IDE with advanced features

Download →

VS Code

Lightweight editor with C# extension

Download →

2 Create Your First Mod

Use tModLoader's built-in tools to create a mod template:

  1. Launch tModLoader and go to "Workshop" → "Develop Mods"
  2. Click "Create Mod" and enter your mod details
  3. Choose a unique mod name (no spaces or special characters)
  4. Click "Create" to generate the mod template

This creates a basic mod structure in your ModSources folder with all necessary files.

Basic Mod Structure

Every tModLoader mod follows a standard structure:

YourModName/
├── build.txt          # Mod metadata and dependencies
├── description.txt    # Mod description for the browser
├── icon.png          # Mod icon (64x64 recommended)
├── YourModName.cs    # Main mod class
├── Items/            # Custom items
├── NPCs/             # Custom NPCs
├── Projectiles/      # Custom projectiles
├── Tiles/            # Custom tiles/blocks
├── Walls/            # Custom walls
├── Buffs/            # Custom buffs/debuffs
└── Sounds/           # Custom audio files

Example Mod Class

Here's a basic mod class structure:

using Terraria.ModLoader;

namespace YourModName
{
    public class YourModName : Mod
    {
        public override void PostSetupContent()
        {
            // Code that runs after all mods are loaded
        }

        public override void PostUpdateInput()
        {
            // Code that runs every frame
        }

        public override void Unload()
        {
            // Cleanup code when mod is unloaded
        }
    }
}

build.txt Configuration

The build.txt file contains important metadata about your mod:

displayName = Your Mod Name
author = Your Name
version = 1.0.0
modReferences =
buildIgnore = *.csproj, *.user, *.suo, bin/, obj/, .vs/
homepage = https://github.com/yourusername/yourmod
description = A brief description of what your mod does

Creating Your First Item

Let's create a simple custom sword as your first item:

Create the Item Class

Create a new file: Items/ExampleSword.cs

using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace YourModName.Items
{
    public class ExampleSword : ModItem
    {
        public override void SetDefaults()
        {
            // Basic item properties
            Item.damage = 50;
            Item.DamageType = DamageClass.Melee;
            Item.width = 40;
            Item.height = 40;
            Item.useTime = 20;
            Item.useAnimation = 20;
            Item.useStyle = ItemUseStyleID.Swing;
            Item.knockBack = 6;
            Item.value = Item.buyPrice(gold: 1);
            Item.rare = ItemRarityID.Green;
            Item.UseSound = SoundID.Item1;
            Item.autoReuse = true;
        }

        public override void AddRecipes()
        {
            Recipe recipe = CreateRecipe();
            recipe.AddIngredient(ItemID.IronBar, 10);
            recipe.AddIngredient(ItemID.Wood, 5);
            recipe.AddTile(TileID.Anvils);
            recipe.Register();
        }
    }
}

Add Item Texture

Create a 40x40 pixel PNG image and save it as:

Items/ExampleSword.png

The file name must match your class name exactly.

Build and Test Your Mod

Build + Reload Workflow

tModLoader's powerful development feature allows you to test changes instantly:

  1. In tModLoader, go to "Workshop" → "Develop Mods"
  2. Find your mod in the list and click "Build + Reload"
  3. Wait for compilation to complete
  4. Your mod will automatically reload with changes
  5. Test your new item in-game

Pro Tip: Use "Build + Reload" frequently during development. It's much faster than restarting the game!

Common Build Errors

  • Missing texture: Ensure PNG file matches class name exactly
  • Compilation errors: Check syntax and using statements
  • Missing references: Verify ModLoader references are correct
  • Build.txt errors: Check mod metadata formatting

Advanced Development Topics

Custom NPCs

Create enemies, town NPCs, and bosses with custom AI

Learn More →

World Generation

Add custom biomes, structures, and world features

Learn More →

Custom UI

Create interfaces, HUDs, and interactive elements

Learn More →

Multiplayer Support

Handle networking and synchronization

Learn More →

Publishing Your Mod

Publishing to Steam Workshop

  1. Ensure your mod builds without errors
  2. Go to "Workshop" → "Develop Mods"
  3. Click "Publish" next to your mod
  4. Fill out the Steam Workshop form with description and tags
  5. Upload screenshots and set visibility
  6. Click "Publish" to make it live

Your mod will be available in the mod browser within a few minutes of publishing.

Best Practices for Publishing

Content Guidelines

  • Write clear, detailed descriptions
  • Include high-quality screenshots
  • Test thoroughly before publishing
  • Document known issues

Technical Requirements

  • No compilation errors or warnings
  • Proper null checking
  • Multiplayer compatibility testing
  • Performance optimization

Additional Resources