How to create a mod with Microsoft Visual Studio (MVS) [tModLoader 0.4.1]

How to create a mod with Microsoft Visual Studio (MVS) [tModLoader 0.5]

Translated and supplemented by Warten. Link to the original. (In English)
Attention! ask stupid questions like: Why doesn't the Russian language work? Will drive the author into a wild rage.

Home
Remember: if your religion prohibits reading the FAQ, googling and using a translator, you may not wait for help here. General.

  • Set tModLoader
  • Make sure you have the latest .NET Framework installed - Microsoft-.NET-Framework-4.52.exe [1.07 Mb] (Downloads: 7), Microsoft-.NET-Framework-4.6.exe [1.43 Mb] (Downloads: 12).
  • Make sure you have XNA Framework .dll files (Or download XNA_Framework.zip [404.02 Kb] (Downloads: 13)).
  • Download and Install Microsoft Visual Studio, Community Edition - vs_community.exe [2.96 Mb] (Downloads: 24). (Install with C # workspace. Warning !: install with English) It's only for 30 days! Later you need to register an account for off. website and enter the program, it's free.
  • And of course, basic knowledge of C #. It's easy, read tutorials, guides and do any regular program before you start modding.

There are some things you should know before starting modding:

  • First of all, this manual is for tModLoader and it may (or may not) change as we update it.
  • Make sure you have the latest Microsoft .NET Framework (4.5 or higher) to prevent any problems.
  • Terraria uses XNA Framework libraries, so you will need DLLs in your mod. They are needed to prevent errors when writing code. You can download mine or find them yourself if you have the XNA Framework (Preferred).
  • And of course, don't forget Microsoft Visual Studio itself.

Introduction
MVS will help you auto-complete code by showing errors, and in general ... It will make the process of coding much faster and easier.
Microsoft Visual Studio is an application for creating many kinds of programs. You've probably heard of it before, and maybe someone even used it :)
If this is your first time using MVS, I recommend reviewing / reading the C # guides / tutorials first. There are a lot of them on the Internet.

How to create your mod (hereafter - project) in MVS
It is better to use MVS with installed English. tongue! After installation and launch, you will see the start page, close it. Then do everything as in the list.

  1. Click File -> New -> Project (Templates -> Other project types -> Visual Studio Solutions) name it “Mod Sources” (Without quotes)
  2. Set location: documents \ My Games \ Terraria \ ModLoader
  3. Click OK
  4. Click Add -> New Project -> Windows -> Classic Desktop -> Empty Project
  5. Enter the name of the mod (In English, without special characters and spaces)
  6. Click OK
  7. Right click on the new project (Right) -> Add -> Class (name it the same as you named the mod)
  8. Then write the code like here: (MODNAME is the name of your mod)
    using Terraria.ModLoader; namespace MODNAME { public class MODNAME : Mod { public override void SetModInfo(out string name, ref ModProperties properties) { name = "MODNAME"; properties.Autoload = true; } } }
  9. Now create a simple .txt file. Enter these lines there:
    author = This is your nickname, name, whatever, write whatever you want;
    version = version, any digits;
    displayName = this is the name of the mod that will be shown in the menu, here you can already write spaces, special characters, but you cannot use Cyrillic! (Russian letters)
    Like this:author = NAME version = 0 displayName = MOD NAME
  10. Drop the resulting build.txt into your project (Just drag and drop)
  11. Then right-click on your project -> references -> Add reference (Add the libraries (.dll) that you downloaded, and the modified Terraria.exe (With the modloader installed, you know))
  12. That's all, now you can run terraria and build the mod in the mod sources tab to check if you did everything right. If not then repeat.

Tips
Some tips:

  • Try to keep internal names such as namespaces and classes clean. That is, try to avoid special characters, spaces, dashes, etc. etc.
  • If you don't understand anything, ask yourself: Do you have any knowledge of C # in this case? If not, then read the C # tutorials / guides and then come back.

My tips:

  • Take a look at the source code of ExampleMod carefully, it contains almost everything that tModLoader can do at this time.
  • Note for MVS, it creates a .vs folder which will show up in the mod sources tab. For now, just ignore her.
  • Before you start modding you should at least know the very basics of C #.
    You can mostly learn these basics by building console applications.
    Don't be afraid to try doing something yourself!
    Experience with programming other applications will be a huge plus in the future.

C # tutorials (In English. Search for yourself in Russian.)

Additional links.

  • Documentation (eng)
  • Post tModLoader'a at the office. forum. (Also English. A request from the author, do not run there to ask anything in Russian, in most cases they will simply ignore you there)
  • IDs of items, tiles, etc.

Creating your project files
Crafting an item:
Tip: Item name and texture must be the same.
Tip: This "//" thing is called a comment, the program ignores everything that is written after it. And yes, you can write Cyrillic here.

Show / Hide text
First, create an Items folder. Just right click on your project -> Add -> Create folder. In general, the folder can have any name, but it's better not to deviate from the canon.
Now create a file for your item: right click on the folder -> Add -> Class. (Shift + Alt + C)
Useless using directives will appear in your file, remove them. Instead, add others that we need more:
using Terraria; // own terraria
using Terraria.ID; // ID of items, particles, npc, etc.
using Terraria.ModLoader; // what we use to make the mod
Next we see the name of the class (your item, do not forget to rename the ItemName), add ": ModItem" after it
{
class ItemName: ModItem // We tell the program that this thing is an item
Then add SetDefaults
{
public override void SetDefaults () // item properties
{
// write properties here
}
}}
That's all! Now you can edit the properties of the item.
Here is a list of properties. (Not everything here.)

// int = 1, float = 0.01f, double = 1.00, bool = true or false,
item.name = “Item name”; // the name of the item that will be shown in the game.
item.maxStack = 99; //Max. amount, int
item.value = 01020304; // where 01Plat 02Gold 03Silver 04Copper, that is, 1 platinum, 2 gold, 3 silver and 4 kopecks, int.

item.consumable = true; // item disappears after use, bool
item.healLife = 20; // heals xn, int
item.healMana = 20; // restores mana, int

item.damage = 20; // damage, int
item.melee = true; // damage type, you can write item.magic, item.ranged, item.summon, item.thrown instead. bool
item.crit = 20; // crit chance, int
item.knockBack = 2; // how far the mob flies after hitting, int
item.mana = 20; // how much mana is used, int

item.width = 40; // item width, int
item.height = 40; // item height, int
item.toolTip = “”; // any text
item.toolTip2 = “”; // text
item.rare = 2; // rarity, int
item.expert = false; // rainbow color like expert items and expert, bool

item.accessory = true; // dresses as an accessory, bool
item.defense = 20; // how much protection it gives, int
item.lifeRegen = 5; // regeneration, int
item.manaIncrease = 20; // adds max. mana, int

item.axe = 5; // the item works like an ax, int * 5
item.hammer = 25; // like a hammer, int
item.pick = 25; // like a pickaxe, int

item.useTime = 15; // usage time in ticks, int
item.useAnimation = 30; // animation in the game, then how fast we will swing the texture, int
item.useStyle = 1; / * how we use it: 1 - wave, 2 - use it as a potion, 3 - poke it like daggers,
4 - we raise it with our hands, 5 - we just hold it in our hands (books, firearms, etc.), int * /

item.shoot =; // what the object shoots with, int ID
item.shootSpeed ​​= 10f; // speed, float
Adding a recipe:
First we need to add AddRecipes
{
public override void SetDefaults () // item properties
{
// write properties here
}
public override void AddRecipes ()
{
// write the recipe here
}
}}
Then we add the rest:

ModRecipe recipe = new ModRecipe (mod); // we say this is a recipe
recipe.AddIngredient (ItemID.DirtBlock, 2); // we add a block of land to the recipe. You can write ID
recipe.AddIngredient (ItemID.DirtWall, 8); // earth wall
recipe.AddTile (TileID.WorkBenches); // crafting requires a workbench
recipe.SetResult (this, 99); // We end up with 99 items
recipe.AddRecipe (); // end of recipe
Making an accessory out of the item
Add UpdateAccessory ()
{
public override void SetDefaults () // item properties
{
// write properties here
}
public override void UpdateAccessory (Player player)
{
// accessory properties
}
public override void AddRecipes ()
{
// write the recipe here
}
}}
Accessory properties:

// + = adds, - = subtracts, * = multiplies, / = divides
player.meleeDamage + = 10f; // melee damage, float
player.thrownDamage + = 10f; // thrown damage, float
player.rangedDamage + = 10f; // ranged damage, float
player.magicDamage + = 10f; // magic damage, float
player.minionDamage + = 10f; // minion damage, float

player.statDefense + = 100; // protection, int
player.moveSpeed ​​+ = 100; // speed, int
player.maxMinions + = 10; // max. miniens, int

player.lifeRegen + = 10; // regen xn, int
player.manaRegen + = 10; // mana regen, int

player.waterWalk = true; // walking on water, bool
player.noFallDmg = true; // damage from height, bool
player.jumpBoost = true; // higher jump, bool
player.lavaImmune = true; // lava immun, bool
player.lifeForce = true; // + 20% hp ?, bool
player.lifeMagnet = true; // attracts hearts
player.lifeSteal = 5; // life style, int
player.jumpSpeedBoost = 10; // jump speed, int
player.manaCost - = 10; // mana cost, int
player.nightVision = true; // night vision, bool

player.magicCrit + = 10; // int
player.rangedCrit + = 10; // int
player.meleeCrit + = 10; // int
player.thrownCrit + = 10; // int
player. // minions don't crits

player.dash = 1; // jerk, int
player.dashDelay = 10; // time between jerks, int
player.AddBuff (BuffID.Shine, 5, false); // adds buff, int ID, int TIC, bool

TerrariaGo - Everything for Terraria (Terraria) free download