tModLoader Official tModLoader Help Thread

I'm going to need more help, as I'm trying to get custom crates to appear, but for that, I'll need to know internal names for biomes. (Or zones, I guess.) The only one I know is that the ocean is called the beach internally, but can anyone help with the rest? If possible, I would like to know about the underworld, granite, spider cave, marble, surface, tundra, mushroom biome, the underground, caverns, and space. Thank you.
 
Last edited:
Cannot implicitly convert type 'Terraria.Item[]' to 'bool' Why you gotta do this too me Terraria!?!?!?

Here is the part the error is located in.
C#:
    public static void AI(Item item, Player player, NPC npc) {
        if (npc.type == 2) {
            if (player.miscEquips) {
                if (item.type == ModContent.ItemType<SightNecklace>()) {
                    npc.friendly = true;
                    npc.aiStyle = 24;
                    npc.damage = 0;
                }
            }
        }
    }
Of course, I expected it to be complicated, but didn't expect it to be thorny nor tedious.
You seem to be checking if player.miscEquips is true, but it's an Item[] array, and it can't convert that to a boolean. What exactly is the if(player.miscEquips) meant to be checking?

Can somebody kindly explain how to use tModLoader's decompiler? I was told that it can be used to decompile 1.4.0.5 in this thread, but I can't understand how to work it.
tModLoader doesn't have a decompiler (that I'm aware of), so you're going to have to use something like ilspy or dnspy (or avalonia ilspy if you're on Linux or mac).

I'm going to need more help, as I'm trying to get custom crates to appear, but for that, I'll need to know internal names for biomes. (Or zones, I guess.) The only one I know is that the ocean is called the beach internally, but can anyone help with the rest? If possible, I would like to know about the underworld, granite, spider cave, marble, surface, tundra, mushroom biome, the underground, caverns, and space. Thank you.
If you have access to Terraria's source code, you should be able to find them in Main. Search for 'zone' in Main
 
So, I was trying to download tml, but it wouldn't download.

My Steam account is a shared account (I think it's called family share or something). Every time I clicked "Install" from the Steam store, a screen saying "preparing to install" appeared for a split second, and then the page refreshed.

Eventually my dad (the owner of the shared account) downloaded it from his account, and it started working. But now, every time I accept a game invite, it takes me to the Steam store, as if I don't have it downloaded.

Not sure if this is a Steam problem or a Tml problem, but please tell me if there's a solution %:sigh:

Edit: I managed to fix the problem. Hope this doesn't happen to the rest of you!
 
Last edited:
Hey all!

So I'm not sure if this is the place to post this, but I am starting work on a mod of my own ( :D ) and I need some help XD
I'm new to coding, but I feel like with a little help I could pick it up quite fast.

So I was wondering, would anyone be willing to sit with me for maybe like, 30mins or so, and just give me the basics of "this means this" in the context of Tmodloader?

I would really appreciate any help honestly, as the mod isn't super-advanced, just long-winded.

Thanks in advance! ^.^
 
Hey all!

So I'm not sure if this is the place to post this, but I am starting work on a mod of my own ( :D ) and I need some help XD
I'm new to coding, but I feel like with a little help I could pick it up quite fast.

So I was wondering, would anyone be willing to sit with me for maybe like, 30mins or so, and just give me the basics of "this means this" in the context of Tmodloader?

I would really appreciate any help honestly, as the mod isn't super-advanced, just long-winded.

Thanks in advance! ^.^
I can certainly try to help you with any questions you have, but the best way to learn is to just jump into it. Do have at least a quick look at a C# tutorial (tutorialspoint has a good one I think) as I had no idea how to code when I started modding, and didn't have a look at any tutorials, and it really slowed me down. Once you understand C# a bit (especially object-orientated-programming) you start to understand tModLoader.
tModLoader wiki
tModLoader Documentation (VERY useful)
Download and have a look at Example Mod (download from 'Creating Mods' section here) and feel free to dm me if you need any direct help or whatever
 
Does anybody know how i could make my magic weapon have a 10% chance to shoot out a different projectile? Also, how do i make a projectile shoot projectiles like how the north pole's projectile shoots the snowflakes?
 
Does anybody know how i could make my magic weapon have a 10% chance to shoot out a different projectile? Also, how do i make a projectile shoot projectiles like how the north pole's projectile shoots the snowflakes?
In your magic weapon item's class, you'll need to override the Shoot method like so:
Code:
public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
    // Check for that 10% chance
    if(Main.rand.Next(10) == 0)
    {
        // Change projectileTypeHere to whatever projectile type you want to shoot, with the 10% chance
        type = projectileTypeHere;
    }
    return true; // Fire projectile - with a 10% chance, the type of projectile fired will be changed from item.shoot to projectileTypeHere
}

As for a projectile firing a projectile, have a look at Projectile.NewProjectile(...), calling that method with the appropriate arguments in your projectile's AI() method.
Example code to go in AI():
Code:
if(projectile.timeLeft % 20 == 0) // Every 20 frames/ticks
{
    // Fire a North Pole Snowflake at this projectile's center with velocity of 1 on the y-axis. Change the arguments to whatever you want
    Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, 0, 1, ProjectileID.NorthPoleSnowflake, damageAmountHere, knockbackAmountHere, projectile.owner);
}
 
In your magic weapon item's class, you'll need to override the Shoot method like so:
Code:
public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
    // Check for that 10% chance
    if(Main.rand.Next(10) == 0)
    {
        // Change projectileTypeHere to whatever projectile type you want to shoot, with the 10% chance
        type = projectileTypeHere;
    }
    return true; // Fire projectile - with a 10% chance, the type of projectile fired will be changed from item.shoot to projectileTypeHere
}

As for a projectile firing a projectile, have a look at Projectile.NewProjectile(...), calling that method with the appropriate arguments in your projectile's AI() method.
Example code to go in AI():
Code:
if(projectile.timeLeft % 20 == 0) // Every 20 frames/ticks
{
    // Fire a North Pole Snowflake at this projectile's center with velocity of 1 on the y-axis. Change the arguments to whatever you want
    Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, 0, 1, ProjectileID.NorthPoleSnowflake, damageAmountHere, knockbackAmountHere, projectile.owner);
}
Thanks for the help! It works perfectly!
 
Hi everybody! Just looking for a bit of advice. I noticed when messing around with item.buffType there are several ways to assign the same buff. Which way is best for which situation? I've put some examples down below.
C#:
item.buffType = mod.BuffType("GhostbladeBuff"); //can also use item.buffType = BuffType<Buffs.GhostbladeBuff>();

item.buffType = BuffID.AmmoBox; //seems to be used for all vanilla buffs

item.buffType = mod.BuffType("string");

item.buffType = mod.BuffType<modBuff>();//is obsolete

item.buffType = ModContent.BuffType<modBuff>(); //works

item.buffType = ModContent.GetModBuff(modBuff); //I assume this works, but haven't tested it yet.
 
Hi everybody! Just looking for a bit of advice. I noticed when messing around with item.buffType there are several ways to assign the same buff. Which way is best for which situation? I've put some examples down below.
C#:
item.buffType = mod.BuffType("GhostbladeBuff"); //can also use item.buffType = BuffType<Buffs.GhostbladeBuff>();

item.buffType = BuffID.AmmoBox; //seems to be used for all vanilla buffs

item.buffType = mod.BuffType("string");

item.buffType = mod.BuffType<modBuff>();//is obsolete

item.buffType = ModContent.BuffType<modBuff>(); //works

item.buffType = ModContent.GetModBuff(modBuff); //I assume this works, but haven't tested it yet.
I'd be glad to help!

First, let's eliminate BuffID.Buff;, why? Because it can only be used for vanilla buffs. Mod buffs don't have stable IDs, another mod may overwrite their IDs.

Next, because mod.BuffType<modBuff>(); is obsolete (you stated it too,) it won't be used.

I also haven't tried item.buffType = ModContent.GetModBuff(modBuff); //I assume this works, but haven't tested it yet. either.

This leaves us to these three.

C#:
item.buffType = mod.BuffType("modBuff");

item.buffType = BuffType<Buffs.modBuff>();

item.buffType = ModContent.BuffType<modBuff>();

In my opinion. mod.BuffType("modBuff"); is the easiest, due to having a simple, easy to remember, code line.
And this can be used too if you want: item.buffType = ModContent.BuffType<modBuff>();
I'm not sure about item.buffType = ModContent.BuffType<modBuff>(); but sure, if it works then you can use it.

You're welcome!
 
Is there a good way to change vanilla sprites using mods? Like, instead of a texture pack, just change textures through a mod (I only need to change boss sprites).
 
Is there a good way to change vanilla sprites using mods? Like, instead of a texture pack, just change textures through a mod (I only need to change boss sprites).
You can probably locate the vanilla sprites in Main (assuming you have access to the source code) and then in your mod, I guess in your mod's Load() method? you can replace those sprites with your own, for example: Main.dukeFishronTexture = ModContent.GetTexture("ModFolder/pathToImage");
That should work, but I haven't tried it.
 
the potion combinations from AlchemistNPC got me thinking, how do i make a potion give multiple buffs? I've had this idea for a food item that gives well fed and swiftness.
 
the potion combinations from AlchemistNPC got me thinking, how do i make a potion give multiple buffs? I've had this idea for a food item that gives well fed and swiftness.
You'll have to apply the buffs in UseItem with player.AddBuff, instead of setting item.buffType.
 
I am having problems editing vanilla recipes bc the items I want to edit have no recipe ex: extractinator, magic mirror, Hermes boots. how would I use the recipe finder for things that don't have recipes
 
I am having problems editing vanilla recipes bc the items I want to edit have no recipe ex: extractinator, magic mirror, Hermes boots. how would I use the recipe finder for things that don't have recipes
I don't think you can use the recipe finder for that - If you want to make a recipe for a vanilla item, just create a recipe like you'd usually do, and set the result to that item.
 
I dont understand, can you give me an example?
Sure:
Code:
// Override UseItem in ModItem
public override bool UseItem(Player player)
{
    player.AddBuff(Terraria.ID.BuffID.Hunter, 360); // Add the Hunter buff to the player for 6 seconds
    player.AddBuff(Terraria.ID.BuffID.Horrified, 360); // Add the Horrified buff the the player for 6 seconds
    return true; // Yes, this item does something when used
}


Now I've got a question, if anybody can help me:
I'm more or less a beginner to using netcode - I've not payed attention to making my mods multiplayer-compatible until now. So naturally I'm having issues.
I've got a projectile that moves Items and NPCs around, and when I go on multiplayer, when I move an Item or NPC, it goes back to where it would've been if I hadn't moved it, after a seemingly random delay.
My code (inside projectile AI()) is to the effect of: (I've left out irrelavant bits of code such as checking whether the npc/item is active, checking it's position, etc.)
Code:
if(Main.myPlayer == projectile.owner)
{
    foreach(NPC npc in Main.npc)
    {
        npc.position = Main.MouseWorld;
        npc.netUpdate = true;
    }
    
    foreach(Item item in Main.item)
    {
        item.position = Main.MouseWorld;
        // I don't know how to sync item data
    }
}
Any idea what I'm doing wrong?
 
Back
Top Bottom