Standalone [1.3] tModLoader - A Modding API

Chaoticley

Terrarian
It is most definitely not the easiest thing for someone completely new to coding. The most basic tmodloader functions revolve around making basic items or npcs. What you are trying to make involves running a global player script that holds a variable for your resource which is then referenced in every script that uses said resource. Depending on how you want these buffs to activate you might need to catch player inputs in update methods and whatnot. It isn't the most complicated thing in the world but it requires a bit of knowledge of how object oriented programing works and it depends on how versed you are on the fundamentals of coding.
I only have a few months of coding experience, but I would really like to give it a try... do you have any idea how I would go about starting to code this? And if not, do you know how I could incorporate animated sprites to my buffs, as mentioned above? Thank you!

Edit: Turns out, I was able to code the resource first try! Well, almost... I'm having a small issue where the resource is regenerating and is able to be used, but the "bar" that is supposed to show how much of the resource the player has isn't showing up for some reason... any ideas? Here's all my code:

using System.Collections.Generic;
using System.Linq;
using Terraria;
using Terraria.ModLoader;

namespace Test
{
public abstract class EssenceItem : ModItem
{
public override bool CloneNewInstances => true;
public int essenceCost = 0;

public virtual void SafeSetDefaults()
{
}

public sealed override void SetDefaults()
{
SafeSetDefaults();
item.melee = false;
item.ranged = false;
item.magic = false;
item.thrown = false;
item.summon = false;
}

public override void ModifyWeaponDamage(Player player, ref float add, ref float mult, ref float flat)
{
add += EssencePlayer.ModPlayer(player).essenceDamageAdd;
mult *= EssencePlayer.ModPlayer(player).essenceDamageMult;
}

public override void GetWeaponKnockback(Player player, ref float knockback)
{
knockback += EssencePlayer.ModPlayer(player).essenceKnockback;
}

public override void GetWeaponCrit(Player player, ref int crit)
{
crit += EssencePlayer.ModPlayer(player).essenceCrit;
}

public override void ModifyTooltips(List<TooltipLine> tooltips)
{
TooltipLine tt = tooltips.FirstOrDefault(x => x.Name == "Damage" && x.mod == "Terraria");
if (tt != null)
{
string[] splitText = tt.text.Split(' ');
string damageValue = splitText.First();
string damageWord = splitText.Last();
tt.text = damageValue + " essence " + damageWord;
}

if (essenceCost > 0)
{
tooltips.Add(new TooltipLine(mod, "Essence Cost", $"Uses {essenceCost} essence"));
}
}

public override bool CanUseItem(Player player)
{
var exampleDamagePlayer = player.GetModPlayer<EssencePlayer>();

if (exampleDamagePlayer.essenceCurrent >= essenceCost)
{
exampleDamagePlayer.essenceCurrent -= essenceCost;
return true;
}
return false;
}
}
}


using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;

namespace Test
{
public class EssencePlayer : ModPlayer
{
public static EssencePlayer ModPlayer(Player player)
{
return player.GetModPlayer<EssencePlayer>();
}

public float essenceDamageAdd;
public float essenceDamageMult = 1f;
public float essenceKnockback;
public int essenceCrit;

public int essenceCurrent;
public const int DefaultEssenceMax = 100;
public int essenceMax;
public int essenceMax2;
public float essenceRegenRate;
internal int essenceRegenTimer = 0;
public static readonly Color HealEssence = new Color(187, 91, 201);

public override void Initialize()
{
essenceMax = DefaultEssenceMax;
}

public override void ResetEffects()
{
ResetVariables();
}

public override void UpdateDead()
{
ResetVariables();
}

private void ResetVariables()
{
essenceDamageAdd = 0f;
essenceDamageMult = 1f;
essenceKnockback = 0f;
essenceCrit = 0;
essenceRegenRate = 1f;
essenceMax2 = essenceMax;
}

public override void PostUpdateMiscEffects()
{
UpdateResource();
}

private void UpdateResource()
{
essenceRegenTimer++;

if (essenceRegenTimer > 180 * essenceRegenRate)
{
essenceCurrent += 1;
essenceRegenTimer = 0;
}

essenceCurrent = Utils.Clamp(essenceCurrent, 0,essenceMax2);
}
}
}


using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.GameContent.UI.Elements;
using Terraria.UI;
using Terraria.ModLoader;
using Test;

namespace Test.UI
{
internal class EssenceBar : UIState
{
private UIText text;
private UIElement area;
private UIImage barFrame;
private Color gradientA;
private Color gradientB;

public override void OnInitialize()
{
area = new UIElement();
area.Left.Set(-area.Width.Pixels - 600, 1f);
area.Top.Set(30, 0f);
area.Width.Set(182, 0f);
area.Height.Set(60, 0f);

barFrame = new UIImage(ModContent.GetTexture("Test/UI/EssenceBarFrame"));
barFrame.Left.Set(22, 0f);
barFrame.Top.Set(0, 0f);
barFrame.Width.Set(138, 0f);
barFrame.Height.Set(34, 0f);

text = new UIText("0/0", 0.8f);
text.Width.Set(138, 0f);
text.Height.Set(34, 0f);
text.Top.Set(40, 0f);
text.Left.Set(0, 0f);

gradientA = new Color(123, 25, 138);
gradientB = new Color(187, 91, 201);

area.Append(text);
area.Append(barFrame);
Append(area);
}

public override void Draw(SpriteBatch spriteBatch)
{
if (!(Main.LocalPlayer.HeldItem.modItem is EssenceItem))
return;

base.Draw(spriteBatch);
}

protected override void DrawSelf(SpriteBatch spriteBatch)
{
base.DrawSelf(spriteBatch);

var modPlayer = Main.LocalPlayer.GetModPlayer<EssencePlayer>();
float quotient = (float)modPlayer.essenceCurrent / modPlayer.essenceMax2;
quotient = Utils.Clamp(quotient, 0f, 1f);

Rectangle hitbox = barFrame.GetInnerDimensions().ToRectangle();
hitbox.X += 12;
hitbox.Width -= 24;
hitbox.Y += 8;
hitbox.Height -= 16;

int left = hitbox.Left;
int right = hitbox.Right;
int steps = (int)((right - left) * quotient);
for (int i = 0; i < steps; i += 1)
{
float percent = (float)i / (right - left);
spriteBatch.Draw(Main.magicPixel, new Rectangle(left + i, hitbox.Y, 1, hitbox.Height), Color.Lerp(gradientA, gradientB, percent));
}
}
public override void Update(GameTime gameTime)
{
if (!(Main.LocalPlayer.HeldItem.modItem is EssenceItem))
return;

var modPlayer = Main.LocalPlayer.GetModPlayer<EssencePlayer>();
text.SetText($"Essence: {modPlayer.essenceCurrent} / {modPlayer.essenceMax2}");
base.Update(gameTime);
}
}
}


using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;

namespace Test.Items.Weapons
{
public class EssenceStaff : EssenceItem
{
public override void SetStaticDefaults()
{
Item.staff[item.type] = true;
}

public override void SafeSetDefaults()
{
item.CloneDefaults(ItemID.AmethystStaff);
item.Size = new Vector2(28, 36);
item.damage = 32;
item.knockBack = 3;
item.rare = ItemRarityID.Red;
item.mana = 0;
item.useStyle = ItemUseStyleID.HoldingOut;
essenceCost = 10;
}
}
}
 
Last edited:
  • Like
Reactions: W1K

W1K

Witch
I only have a few months of coding experience, but I would really like to give it a try... do you have any idea how I would go about starting to code this? And if not, do you know how I could incorporate animated sprites to my buffs, as mentioned above? Thank you!

Edit: Turns out, I was able to code the resource first try! Well, almost... I'm having a small issue where the resource is regenerating and is able to be used, but the "bar" that is supposed to show how much of the resource the player has isn't showing up for some reason... any ideas? Here's all my code:
That is quite a lot of good progress. I'd suggest to either upload the codes to hastebin or use the forum's "Insert Code" command to make things more readable.

I can't really spend much time on it atm, and tMod's UI coding is something I'm a bit behind with myself as I haven't done much of it. First thing I'd try is debug and make sure the UI can at least draw anything at all to bar any problems with the logic, for instance I'd remove the condition in Draw to make sure it always draws, and simplify the drawing logic with something that easily verifies the method is being called at all (like drawing some gibberish on screen or debug text).
 

Elmemes

Terrarian
ok so i play on pc a friend LEGALLY gave me his terraria version from gog and when i tried to run mod loader this came up:

[23:22:52] [1/INFO] [tML]: Starting tModLoader v0.11.8.4 Windows client (4/7/2022)
[23:22:52] [1/INFO] [tML]: Running on NetFramework 4.8
[23:22:52] [1/INFO] [tML]: Executable: C:\GOG Games\Terraria\tModLoader.exe
[23:22:52] [1/INFO] [tML]: Working Directory: C:\GOG Games\Terraria
[23:22:52] [1/INFO] [tML]: Launch Parameters:
[23:22:52] [1/DEBUG] [tML]: Assembly Resolve: -> MonoMod.RuntimeDetour, Version=20.11.16.1, Culture=neutral, PublicKeyToken=null
[23:22:52] [1/DEBUG] [tML]: Assembly Resolve: MonoMod.RuntimeDetour, Version=20.11.16.1, Culture=neutral, PublicKeyToken=null -> MonoMod.Utils, Version=20.11.16.1, Culture=neutral, PublicKeyToken=null
[23:22:52] [1/DEBUG] [tML]: Assembly Resolve: MonoMod.RuntimeDetour, Version=20.11.16.1, Culture=neutral, PublicKeyToken=null -> Mono.Cecil, Version=0.11.3.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e
[23:22:53] [1/DEBUG] [tML]: Assembly Resolve: -> Ionic.Zip.Reduced, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c
[23:22:53] [1/DEBUG] [tML]: Assembly Resolve: -> Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
[23:22:55] [1/INFO] [tML]: Checking GOG or manual installation...
[23:22:55] [1/FATAL] [tML]: Terraria.exe is not the unmodified Terraria executable.

GOG installs must have the unmodified Terraria executable to function.

If you patched the .exe, you can create a copy of the original exe and name it "Terraria_v<VERSION>.exe"


PLS HELP
 

Attachments

  • Emotional Damage.png
    Emotional Damage.png
    73.9 KB · Views: 50

Youmii~

Terrarian
Looking for help, when playing t-modloader with a bunch of mods (Calamity, Stars Above, Split, AlchemistNPC, Fargos's Soulsmod, and more i cannot remember atm, will give them if needed.) my game crashes whenever the first wave of the Old Ones Army starts. Same thing happens if i just spawn an Ogre. My game also crashes as the Warrior of Light boss from Stars Above would go into his final phase.

Crash log (Old Ones Army)_________________________________________________

11/4/22 2:32:08 AM
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at SDL2.SDL.SDL_GL_SwapWindow(IntPtr window)
at Microsoft.Xna.Framework.Graphics.OpenGLDevice.SwapBuffers(Nullable`1 sourceRectangle, Nullable`1 destinationRectangle, IntPtr overrideWindowHandle)
at Microsoft.Xna.Framework.Graphics.GraphicsDevice.Present()
at Microsoft.Xna.Framework.GraphicsDeviceManager.Microsoft.Xna.Framework.IGraphicsDeviceManager.EndDraw()
at Microsoft.Xna.Framework.Game.EndDraw()
at Microsoft.Xna.Framework.Game.Tick()
at Microsoft.Xna.Framework.SDL2_FNAPlatform.RunLoop(Game game)
at Microsoft.Xna.Framework.Game.Run()
at Terraria.Program.LaunchGame_()
________________________________________________________

I tried to uninstall and reinstall mods, tmodloader and verfiy steam files and I'm unsure if this correlates, but when verifying the base game files i receive this message

1649660535731.png


and if I verify the files the same message pops up.

Any help with fixing these?
 

jopojelly

Retinazer
tModLoader
Looking for help, when playing t-modloader with a bunch of mods (Calamity, Stars Above, Split, AlchemistNPC, Fargos's Soulsmod, and more i cannot remember atm, will give them if needed.) my game crashes whenever the first wave of the Old Ones Army starts. Same thing happens if i just spawn an Ogre. My game also crashes as the Warrior of Light boss from Stars Above would go into his final phase.

Crash log (Old Ones Army)_________________________________________________

11/4/22 2:32:08 AM
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at SDL2.SDL.SDL_GL_SwapWindow(IntPtr window)
at Microsoft.Xna.Framework.Graphics.OpenGLDevice.SwapBuffers(Nullable`1 sourceRectangle, Nullable`1 destinationRectangle, IntPtr overrideWindowHandle)
at Microsoft.Xna.Framework.Graphics.GraphicsDevice.Present()
at Microsoft.Xna.Framework.GraphicsDeviceManager.Microsoft.Xna.Framework.IGraphicsDeviceManager.EndDraw()
at Microsoft.Xna.Framework.Game.EndDraw()
at Microsoft.Xna.Framework.Game.Tick()
at Microsoft.Xna.Framework.SDL2_FNAPlatform.RunLoop(Game game)
at Microsoft.Xna.Framework.Game.Run()
at Terraria.Program.LaunchGame_()
________________________________________________________

I tried to uninstall and reinstall mods, tmodloader and verfiy steam files and I'm unsure if this correlates, but when verifying the base game files i receive this message

View attachment 363655

and if I verify the files the same message pops up.

Any help with fixing these?
The log file is needed to figure this out (My Games/Terraria/ModLoader/Logs/client.log), but honestly you'll more likely be able to solve this by asking on our discord (tModLoader.net/discord), that's where most support inquiries are resolved. Very rarely will someone able to actually help you check this thread.
 

Youmii~

Terrarian
The log file is needed to figure this out (My Games/Terraria/ModLoader/Logs/client.log), but honestly you'll more likely be able to solve this by asking on our discord (tModLoader.net/discord), that's where most support inquiries are resolved. Very rarely will someone able to actually help you check this thread.
Alright, thanks for the help!
 

>>Terrarian<<

Torch God
I don't know if someone can answer this, maybe blushiemagic, or jopojelly, or even Jofairden. But: When is this thread going to be updated about the tModLoader being in 1.4? Only when 1.4 beta comes in May 16th? Or after?
 

jopojelly

Retinazer
tModLoader
I don't know if someone can answer this, maybe blushiemagic, or jopojelly, or even Jofairden. But: When is this thread going to be updated about the tModLoader being in 1.4? Only when 1.4 beta comes in May 16th? Or after?
Not sure what May 16th is, but I guess we should edit the 1st post with some info on 1.4. Most of our communications about the alpha happen on discord.
 

Nakano15

Terrarian
I got a bizarre idea that might be useful for the unknown mod items.
What if modders could setup an alias for the items, which tells what what vanilla item in Terraria would be like that weapon the character is using?

The reason for that, is if for example, one joins a server that doesn't have the mods they're using. Instead of making them having unknown items, the items from the mods could be masked to their vanilla counter part.
So, if for example my character is using a modded rocket launcher, and I enter a server that doesn't have the mod of the rocket launcher I'm using, It could instead temporarily change into the Rocket Launcher item from vanilla Terraria.

The items themselves would still have to show their name and mod it is from, and also some indication that it isn't actually the item that the player had, includding also a tooltip telling that the item was replaced. On my idea, I think that would be saved alongside the item id and mod id.

That's an idea I gathered when messing with server stuff. I hope it end up being useful.
 

>>Terrarian<<

Torch God
I got a bizarre idea that might be useful for the unknown mod items.
What if modders could setup an alias for the items, which tells what what vanilla item in Terraria would be like that weapon the character is using?

The reason for that, is if for example, one joins a server that doesn't have the mods they're using. Instead of making them having unknown items, the items from the mods could be masked to their vanilla counter part.
So, if for example my character is using a modded rocket launcher, and I enter a server that doesn't have the mod of the rocket launcher I'm using, It could instead temporarily change into the Rocket Launcher item from vanilla Terraria.

The items themselves would still have to show their name and mod it is from, and also some indication that it isn't actually the item that the player had, includding also a tooltip telling that the item was replaced. On my idea, I think that would be saved alongside the item id and mod id.

That's an idea I gathered when messing with server stuff. I hope it end up being useful.
The problem is that not everything made in mods has a similar item in vanilla. What if you make a mod with something that isn't in the game??
 

blushiemagic

Retinazer
tModLoader
Today we are changing the default tModLoader on Steam to the Terraria 1.4+ version. As you might know, we have had 1.4 tModLoader as an option on the Betas menu for quite some time as we've worked on new features to make modding and playing on 1.4 tModLoader a pleasant experience.

The current 1.3 version will still be available on Steam, you'll just need to select 1.3-legacy in the steam betas menu. We expect many of you will want to use this option until you finish your current playthrough of the game.

Please do not expect to be able to switch to 1.4 and continue using all the same mods you are currently using on 1.3. Many mods have unfortunately been retired, or otherwise have not yet been updated to 1.4. However, our workshop is already blooming with mods, and many relatively small & popular missing mods have already had alternatives created for them.

Click here to browse tModLoader's Steam Workshop right now.

1.4 tModLoader is still in active development​

Although 1.4 tModLoader is now leaving the Alpha stage, we'd like to reiterate that it still remains in active development, with a continuous release cycle bringing new breaking changes on the 1st of each month. We have a system in place for actively maintained mods to continue working seamlessly as each month's update arrives, but that requires the modders to stay on top of updating their mod if required within the designated time period at the end of each month. More information on the modder maintenance workflow can be found in the following announcement:

Beta Branches​

To summarize, here are the available options:
default - This is the 1.4 version that we expect players to use
1.3-legacy - This is the latest 1.3 version. We expect many will want to use this if they are currently playing through the game.
1.4-preview - This branch contains upcoming changes. This is where we test new features. This is also where modders need to publish their mods during the last 10 days of the month if needed.

Twitter​

Feel free to follow tModLoader on Twitter, there will be occasional announcements and posts to showcase the amazing mods which are being worked on:
twitter.com/tModLoader

Our Lovely Contributors​

As any open-source project, the majority of 1.4 tModLoader was made possible thanks to volunteers.
Our sincere gratitude and appreciation go to the following people, who have contributed to tModLoader since Terraria: Journey's End's release day:
direwolf420, Chik3r, ExterminatorX99, ThomasThePencil, Itorius, Steviegt6, Rartrin, Agrair, Ishigh1, DarkLight66, DarioDaF, kittenchilly, Dual-Iron, MrSlimeDude, sgkoishi, OliHeamon, RighteousRyan1, Igmc, NotLe0n, Pixelnando, daim03, fakelag, andrewlord607, pollen00, einarmo, Setnour6, MutantWafflez, Ozzatron, Antirhinnum, CriddleZap, jackbondpreston, Pbone3, ModernMAK, Crapsky233, absoluteAquarian, rjmarzec, ubnt-intrepid, ScalarVector1, Pacnysam, Falcon-05, staticfox, JPANv2, Nyrest, Naginif, D1plex, georgewoodall82, Tyfyter, zzp198, SpencerDawg, RunningDroid, Trivaxy, SadOnion, miarodri, sdegueldre, JamzOhJamz, Ved-s, BarteQ778177, Lumelore, RuneZhevitz, Dinoxel, jjohnsnaill, xKirtle, MikhailMCraft, terrynmuse, hannest03, Fatiz, Valjean42, TomaszOleszko, Rijam, IbanPlay, Fragstiller, S-Pladison

Our Lovely Supporters​

We haven't said this enough, and today seems like the perfect opportunity:
Thank you to the following people who have supported us on Patreon in the last 5+ years, allowing us to dedicate more time to tModLoader's development & maintainment.
You're all truly wonderful!
Andrew Spinks, orian34, dinidini, Glorpy, Elfinlocks, Andrew Nelson, POCKETS, Tantamount, SheepishShepherd, Neuron, BlackHackedGhost, Jeremy Weeks, Amanda Oczkowski, Anay Patel, jjgaming2006, Hunter Amelink, Andreas Østergaard Nielsen, Voiceline, Ray Gibbs, Nike62, Vamist, Patcheresu, Barbara Stone, Meadow, Invelios, AetherBreaker, xbit, Jim Harrington, Toni Stache, Peanutbutta187, Crepe, Panini, Linus, Raphael, englishmuffins10, Hao Wu, Soft Scratch, Steptimus Heap, - Neo -, Corniflex, Ranarrr, Rictor86, Cybernetic, TreeZenDE, Waasephi, Brachiaraidos, Clayton Dorsey, Joesph Dasilva, Jared, Ryan, Neels, AlejandroAkbal, ItsFrosty, tooSlyk, Rdforzer, Andrey, MyTea, absoluteZero, Geog, Zephy, Dog toi Boi, Coolmike5000, qwerty123, Robert Lowe, Rose Malone, Eddiero, xAqult, Wertfuzzy77, Damon Schopen, An IRL Rabbit, Chris Book, Mujtba Alsuwaii, Cidericus, Jeff Butterworth, OmniObserver, Austin Paxton, Alexander, Kirby26, Max McKinney, Samanosuke Akechi, bill, Malte Bjuggfält, Drew, Mello, Scott Reismanis, Justin Mercer, Paper Luigi, Steven Stitz, Josh Nadolski, Tsuniyono Zets, Aviatorskylark, Rebecca Brown, Leonardo Vidal, Kirtle, Syrinx Harmodios, Jacob Roper, Tomat (Stevie), Captain Meliodas, Darcy Owens, Chris Cheeseman, eltaro, Derp Duck, Rogierd, Joe Day, VolcanicMG, Randal Bradakis, Florian, HasteReapr, 追魂祥云

Frequently Asked Questions​


How do I switch to back to 1.3 tModLoader?​

1. Right click on tModLoader in Steam and select 'Properties...', then 'BETAS';
2. Select '1.3-legacy' in the drop-down menu on top;
3. Close the window. You don't need to type any passwords!

How do I switch to 1.4-preview versions?​

You might've already guessed.
Follow the steps listed above, but select '1.4-preview' on the second step instead.

I'm a GOG user! Where do I download TML?​

Hello GOG user!
See our Github Releases for manual TML downloads.
And if you want a preview build - see our Github Actions instead, and download 'Release Build's at the bottom of the latest artifact's page.
Note: Downloading preview Github Actions builds will require logging into Github.

When will TML be 64-bit?​

It's already 64-bit!
Specifically, it's what's called AnyCPU, but we currently only ship x86_64 natives. In addition to TML being made 64-bit-capable, it has been made to run on a ten years newer runtime (.NET 6+), far newer versions of a better game framework (FNA instead of XNA), and we've even unified what would've been 6 Windows/Linux/Mac Client/Server builds into just one portable release that can be run on every Desktop OS. Together, all of this yells: performance, consistency, stability, possibilities, and comfort.

I have a 32-bit OS, will it be supported?​

Sorry, but not yet. We've had plans to re-add support for 32-bit Windows systems in June's stable update, but didn't make it in time, so it'll arrive later either this month, or in July.

Why was this delayed?​

It happens.
 

insistent

Terrarian
Heya i bought terraria yesterday and installed tmodoader but it wont launch. Anyone know what might be the issue?
Thanks!
Untitled2.png
 

jopojelly

Retinazer
tModLoader
Well thats something, but the guide doesnt really mention anything outside of PATH, i dont know what what to do along this enigma.
That's why I mentioned the steam_api64 section above, it's the same thing, we think, so following those instructions but for the other dll names should work. If you need more help, come to discord, I don't check this often. tModLoader.net/discord
 

insistent

Terrarian
That's why I mentioned the steam_api64 section above, it's the same thing, we think, so following those instructions but for the other dll names should work. If you need more help, come to discord, I don't check this often. tModLoader.net/discord
Forgot to add that i did search it, in windows\system32, cant be found.

Im already on discord, tried there once with no avail and its quite busy.
 
Top Bottom