Mod開発ガイド

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

20 分で読める 開発 中級

前提条件

Development Environment

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

Knowledge Requirements

  • • 基本的なC#プログラミング
  • • オブジェクト指向の概念
  • • Terrariaのゲームプレイに精通
  • • ゲーム開発の基本的な理解

開発環境セットアップ

1 Install Development Tools

お好みのC#開発環境を選択:

Visual Studio 2022

フル機能のIDE with excellent debugging

ダウンロード →

JetBrains Rider

クロスプラットフォームIDE with advanced features

ダウンロード →

VS Code

軽量エディタ with C# extension

ダウンロード →

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.

基本的なMod構造

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

サンプルModクラス

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

最初のアイテムを作成

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

アイテムクラスを作成

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();
        }
    }
}

アイテムテクスチャを追加

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

Items/ExampleSword.png

The file name must match your class name exactly.

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

上級開発トピック

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 →

Modの公開

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.

公開のベストプラクティス

コンテンツガイドライン

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

技術要件

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

追加リソース