tModLoader

tModLoader

Not enough ratings
Getting Started With tModLoader Coding
By TrappedU
What I recommend to have when coding Terraria. (cuz I get asked this a lot)
   
Award
Favorite
Favorited
Unfavorite
About This Guide
By the end of this guide you should be good to go with coding Terraria and developing your first mod! This guide will focus on windows 10 and 11 machine setup so anything mac/Linux based may not be 100% correct with this guide, however tools throughout the guide will work on mac for the most part.
Enabling Developer Mode
First of all you will need to enable something called Developer Mode. This will enable tModLoader to essentially allow you to develop mods! You can find this setting in the bottom right of the main menu when you load tModLoader, shown in the image below.


Make sure that is done before reading on.
Required Tools and Setup
In order to code there are 2 (but I say 3) major tools you need in order to code Terraria. First one we will talk about it tools that you can use to create sprites. If you already have art tools like adobe photoshop or any other art tool to make sprites with skip this paragraph. If you don't then, I suggest paint.net. Paint. net is a very easy to use image creator that is free that takes up extremely little space on your computer. Click the link for download.

https://www.getpaint.net/download.html

Then you will want to click the logo "download now dotpdn" under the download options.

Next you will get taken to another page, where in the top right you will find the download. Once downloaded, install it like with any program.



Now you have a very easy to use sprite software! However this tutorial won't cover how to use paint. net. If its not self explanatory already and you need help learning how to use paint. net, search up some youtube videos on it.

Ok now to talk about something called Visual Studio. Visual Studio is pretty much a necessity to code Terraria since it comes with all the tools you need. Click here for link: https://visualstudio.microsoft.com/ Once opened, click the download option which will get you the installer. Once you open the application you will get taken to this screen.


You need these 2 options at the top of this image. You can select more if you use VS for other stuff, up to you.





Now the last tool that you can have which will help with terraria localization files or .hjson is something called Notepad++. Notepad++ is basically a more advanced Notepad application that allows for code/file editor/overall looks better. The notepad application built into your computer works but I recommend Notepad++. Download: https://notepad-plus-plus.org/downloads/ Download the most recent one and install it.
Creating First Mod
Before we can actually create a mod, there is one more download you need. When you open tModLoader and go to workshop then Develop Mod, It will tell you to install MicrosoftXNA which it will give you a link to the download page. You need at least version 8.0, get that unless there's a more polished version. (depends on how outdated this guide/if tmodloader updated)

After that last download your done with downloads! To create your mod, go back to develop mod tab in tModLoader and click create mod. It will have you go through some naming and first details of your mod. Once that is done, your mod will be in the directory Documents/My Games/Terraria/tModLoader/ModSources/"Your Mod Name" I recommend creating a shortcut so you can get to it easier.

Key things to know: When looking at develop mod tab in tModLoader, you can see Build, Build and Reload, and Publish. Clicking on Build check for errors in code, Build and Reload will check for errors and reload so your stuff works in game. Publish, well publishes the mod!
Contents of your mod
When you open your mod in file explorer there's a lot. Lets talk about each core file.

build.txt
displayName = "Name of your mod" (with spaces)
author = "The author of the mod"
version = 1.0 This is the version number, left of period is major update, right for minor update

the only important part of this file is in order to publish you must update the version number.

description.txt
This file is what will be displayed when people click on info of your mod. Put something in this so people know what your mod does.

"your mod name".cs
This one is not important early on but later is a file that can be very helpful for functions and more.

"you mod name".csproj
Dont mess with this one unless you know what your doing

icon.png
This png file is your icon when people view your mod on the browser, replace it with whatever you want but note that is must be in an 80 by 80 for it to work.

Now If you open Localization folder you can see a files called en-US_Mods."your mod name".hjson This is your localization file, where you can name items and descriptions. If you just created your mod you can see that there's a localization for the starting sword you named. This file is where you can change that, and as you create new things in your mod, this file will update as you reload the mod.

Sword Code/Reference Materials
Just to help you start out with the first code, tModLoader gives you basic code for a sword. So lets run through that. The image below is my modified code to the sword with comments with "//" that annotates the code.


Heres links from the screenshot:
https://terraria.wiki.gg/wiki/Sound_IDs
https://terraria.wiki.gg/wiki/Rarity
https://terraria.wiki.gg/wiki/Use_Style_IDs

Things to note is that you can create whatever folders you want, just make sure your code aligns with you directory.

Example Mod: Example is the best reference mod there is. Simply download the mod and enable it on tModLoader. You will also want to extract it so you can see the code for things you may want to learn how to make. To extract a mod, Example mod for example, go to mod manager, find Example Mod, click the ? then click extract. To view the contents go to Documents/My Games/Terraria/tModLoader/ModReader/ExampleMod . This will be your best reference for things. Look through the code and sprites and learn what you want.

If you really wanna see all the functions available: https://docs.tmodloader.net/docs/1.4-stable/index.html (could be outdated, depending on guide)

Last tool is AI, if you need coding assist. AI is a great tool for coding like ChatGPT, it can write code for you but also learn from it too, but also check with build and reload if the code actually works.

I recommend starting off small and easy. Do not try coding a boss right off the bat (bad idea). Learn how to make pickaxe/axe then furniture/blocks/accessories/armor. Then projectiles and enemies once your comfortable with that. Take it slow, it is much different than normal coding since most things are functions.

Hoping this helps with setting up and getting started, questions drop them in comments and ill see if I can get you an answer, I will not be helping with code errors. Just send screenshots to AI or smth.