tModLoader Official tModLoader Help Thread

I don't know if this is the right place to put this, but I have been getting an error when trying to reload mods that add lots of content/items to the game, (Specifically Calamity, Thorium, and Spirit) but not mods that don't. (Like Boss Checklist and Health bars) Here is the error. Please help me fix it. I'm on Terraria v1.3.5.2 and tModloader v0.10.1. It says Version=1.3.5.1 Even though at the bottom left of the screen it says 1.3.5.2. It is the same error for Calamity, Thorium, and Spirit.

Failed to resolve assembly: 'Terraria, Version=1.3.5.1, Culture=neutral, PublicKeyToken=null'
at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
at Mono.Cecil.TypeReference.Resolve()
at Mono.Cecil.Mixin.CheckedResolve(TypeReference self)
at Mono.Cecil.SignatureReader.ReadCustomAttributeEnum(TypeReference enum_type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeElementValue(TypeReference type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeElement(TypeReference type
at Mono.Cecil.SignatureReader.ReadCustomAttributeFixedArrayArgument(ArrayType type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeFixedArgument(TypeReference type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeConstructorArguments(CustomAttribute attribute, Collection`1 parameters)
at Mono.Cecil.MetadataReader.ReadCustomAttributeSignature(CustomAttribute attribute)
at Mono.Cecil.CustomAttribute.<Resolve>b__34_0(CustomAttribute attribute, MetadataReader reader)
at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
at Mono.Cecil.CustomAttribute.Resolve()
at Mono.Cecil.CustomAttribute.get_ConstructorArguments()
at Mono.Cecil.ImmediateModuleReader.ReadCustomAttributes(ICustomAttributeProvider provider)
at Mono.Cecil.ImmediateModuleReader.ReadType(TypeDefinition type)
at Mono.Cecil.ImmediateModuleReader.ReadTypes(Collection`1 types)
at Mono.Cecil.ImmediateModuleReader.ReadModule(ModuleDefinition module)
at Mono.Cecil.ModuleWriter.WriteModuleTo(ModuleDefinition module, Stream stream, WriterParameters parameters)
at Mono.Cecil.ModuleDefinition.Write(Stream stream, WriterParameters parameters)
at Terraria.ModLoader.AssemblyManager.LoadedMod.EncapsulateReferences(Byte[] code)
at Terraria.ModLoader.AssemblyManager.LoadedMod.LoadAssemblies()
at Terraria.ModLoader.AssemblyManager.InstantiateMods(List`1 modsToLoad)
 
I don't know if this is the right place to put this, but I have been getting an error when trying to reload mods that add lots of content/items to the game, (Specifically Calamity, Thorium, and Spirit) but not mods that don't. (Like Boss Checklist and Health bars) Here is the error. Please help me fix it. I'm on Terraria v1.3.5.2 and tModloader v0.10.1. It says Version=1.3.5.1 Even though at the bottom left of the screen it says 1.3.5.2. It is the same error for Calamity, Thorium, and Spirit.
~snip~
Verify the Game Cache and reinstall tModLoader.
 
Okay, I have an issue that needs an urgent fix. I have a worm type enemy that when the code for it is present in the mod's code causes all worlds to display "Load Failed! No backup found!"

This only happens with my mod and only for this enemy. If there's a way to fix this I can give the code.
 
So I have a projectile, and I'm trying to apply a flickering mask to it. This is the code I have:
Code:
        public override void PostDraw(SpriteBatch spriteBatch, Color lightColor)
        {
            if (Main.rand.Next(4) <= 2)
            {
                Texture2D texture = mod.GetTexture("Projectiles/HauntProjectileGlow");
                Vector2 drawPos = projectile.position;
                Rectangle frame = new Rectangle(0, 0, texture.Width, texture.Height);
                spriteBatch.Draw(texture, drawPos, frame, Color.White * 0.7f, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
            }
        }
... and the mod builds with no errors, but the mask just never appears over the projectile. The mask, itself, is a slightly different shape, with a visibly different center, so I know it's just plain not appearing. I'm guessing it's a matter of me barely grasping the code I'm working with, so I'm just wondering what I've done wrong.

Also, is it possible to get a mask to rotate at a different speed than the projectile? And perhaps make it translucent?

places to look for projectile-specific mask examples would probably be helpful, so I can see and better grasp what it is I'm doing, but I find other mask examples (like the item-in-world mask example in the wiki tutorial) don't provide my dense head with enough relevant info I can recognize.
 
So I have a projectile, and I'm trying to apply a flickering mask to it. This is the code I have:
Code:
        public override void PostDraw(SpriteBatch spriteBatch, Color lightColor)
        {
            if (Main.rand.Next(4) <= 2)
            {
                Texture2D texture = mod.GetTexture("Projectiles/HauntProjectileGlow");
                Vector2 drawPos = projectile.position;
                Rectangle frame = new Rectangle(0, 0, texture.Width, texture.Height);
                spriteBatch.Draw(texture, drawPos, frame, Color.White * 0.7f, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
            }
        }
... and the mod builds with no errors, but the mask just never appears over the projectile. The mask, itself, is a slightly different shape, with a visibly different center, so I know it's just plain not appearing. I'm guessing it's a matter of me barely grasping the code I'm working with, so I'm just wondering what I've done wrong.

Also, is it possible to get a mask to rotate at a different speed than the projectile? And perhaps make it translucent?

places to look for projectile-specific mask examples would probably be helpful, so I can see and better grasp what it is I'm doing, but I find other mask examples (like the item-in-world mask example in the wiki tutorial) don't provide my dense head with enough relevant info I can recognize.
You have to draw in screen coordinates, which you can do by subtracting Main.screenPosition from your drawpos
 
How do you make a projectile act like water bolt where its not affected by gravity but it still bounces of tiles because i tried ai style 8 but it was the same as magic fireball whatever its called but i wanted it to act water bolt.

Heres code if it helps in anyway
Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace NicksMod.Projectiles
{

    public class GelBallP : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.width = 20;       //projectile width
            projectile.height = 24;  //projectile height
            projectile.friendly = true;      //make that the projectile will not damage you
            projectile.melee = true;         //
            projectile.tileCollide = true;   //make that the projectile will be destroed if it hits the terrain
            projectile.penetrate = -1;      //how many npc will penetrate
            projectile.timeLeft = 1500;   //how many time this projectile has before disepire
            projectile.light = 0.0f;    // projectile light
            projectile.extraUpdates = 1;
            projectile.ignoreWater = true;
            projectile.aiStyle = 8;
        }
        public override void AI()           //this make that the projectile will face the corect way
        {                                                           // |
            projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f;
        }
       
    }
}
Help me pls because im still a beginner
[doublepost=1508491913,1508491472][/doublepost]Or at least show me how to make projectiles bounce of tiles
 
How do you make a projectile act like water bolt where its not affected by gravity but it still bounces of tiles because i tried ai style 8 but it was the same as magic fireball whatever its called but i wanted it to act water bolt.

Heres code if it helps in anyway
~snip~
Help me pls because im still a beginner
[doublepost=1508491913,1508491472][/doublepost]Or at least show me how to make projectiles bounce of tiles
Heya, Nick... if you check ExampleMod, in the Projectiles folder, read the code for ExampleBullet... it shows a lot of the questions you're asking, including code to set new directions for the projectile when it ricochets. Basically, if you're not using a vanilla projectile as-is, you're probably going to have to code your own.

Edit: Here's a link to it on the tModLoader wiki:
https://github.com/blushiemagic/tModLoader/tree/master/ExampleMod
 
does anyone know how to make an npc spawn at specific biomes such as in jungles or like in snow also how do u make an npc drop more than 1 of a specific item and/or have a chance to drop it like a 1/2 chance to drop something. also know how to make an npc drop multiple different items and yes i know im asking a lot
 
Last edited:
I'm just beginning code, looking at the code for example gun, but I cant seem to find what I did wrong. I probably just missed something idk.
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Thunderbolt.Items.Weapons
{
public class Slimeeradicator : ModItem
{
public override void SetStaticDefaults()
{
Tooltip.SetDefault("pelts slime at enemies.");
}
public override void SetDefaults()
{
item.damage = 75;
item.ranged = true;
item.width = 50;
item.height = 32;
item.useTime = 30;
item.useAnimation = 20;
item.useStyle = 5;
item.noMelee = true;
item.knockBack = 6;
item.value = 10000;
item.rare = 4;
item.UseSound = SoundID.Item11;
item.autoReuse = false;
item.shoot = 10;
item.shootSpeed = 16f;
item.useAmmo = AmmoID.Bullet;
}

public override void AddRecipes()
{
recipe.AddIngredient(null, "DirtBlock", 10);
recipe.AddTile(null, "WorkBenches");
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}

And error - c:\Users\Zylch\Documents\My Games\Terraria\ModLoader\Mod Sources\Thunderbolt\Items\Weapons\Slimeeradicator.cs(9,15) : error CS0101: The namespace 'Thunderbolt.Items.Weapons' already contains a definition for 'Slimeeradicator'
 
I'm just beginning code, looking at the code for example gun, but I cant seem to find what I did wrong. I probably just missed something idk.
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Thunderbolt.Items.Weapons
{
    public class Slimeeradicator : ModItem
    {
        public override void SetStaticDefaults()
        {
            Tooltip.SetDefault("pelts slime at enemies.");
        }
        public override void SetDefaults()
        {
            item.damage = 75;
            item.ranged = true;
            item.width = 50;
            item.height = 32;
            item.useTime = 30;
            item.useAnimation = 20;
            item.useStyle = 5;
            item.noMelee = true;
            item.knockBack = 6;
            item.value = 10000;
            item.rare = 4;
            item.UseSound = SoundID.Item11;
            item.autoReuse = false;
            item.shoot = 10;
            item.shootSpeed = 16f;
            item.useAmmo = AmmoID.Bullet;
        }

        public override void AddRecipes()
        {
            recipe.AddIngredient(null, "DirtBlock", 10);
            recipe.AddTile(null, "WorkBenches");
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}
And error - c:\Users\Zylch\Documents\My Games\Terraria\ModLoader\Mod Sources\Thunderbolt\Items\Weapons\Slimeeradicator.cs(9,15) : error CS0101: The namespace 'Thunderbolt.Items.Weapons' already contains a definition for 'Slimeeradicator'
Make sure that there aren't any files that are using the same name? It's definitely an issue with the Namespace, as the error says.
 
I'm just beginning code, looking at the code for example gun, but I cant seem to find what I did wrong. I probably just missed something idk.
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Thunderbolt.Items.Weapons
{
public class Slimeeradicator : ModItem
{
public override void SetStaticDefaults()
{
Tooltip.SetDefault("pelts slime at enemies.");
}
public override void SetDefaults()
{
item.damage = 75;
item.ranged = true;
item.width = 50;
item.height = 32;
item.useTime = 30;
item.useAnimation = 20;
item.useStyle = 5;
item.noMelee = true;
item.knockBack = 6;
item.value = 10000;
item.rare = 4;
item.UseSound = SoundID.Item11;
item.autoReuse = false;
item.shoot = 10;
item.shootSpeed = 16f;
item.useAmmo = AmmoID.Bullet;
}

public override void AddRecipes()
{
recipe.AddIngredient(null, "DirtBlock", 10);
recipe.AddTile(null, "WorkBenches");
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}

And error - c:\Users\Zylch\Documents\My Games\Terraria\ModLoader\Mod Sources\Thunderbolt\Items\Weapons\Slimeeradicator.cs(9,15) : error CS0101: The namespace 'Thunderbolt.Items.Weapons' already contains a definition for 'Slimeeradicator'
btw, your recipes are wrong: https://github.com/blushiemagic/tModLoader/wiki/Basic-Recipes
 
does anyone know how to make an npc spawn at specific biomes such as in jungles or like in snow also how do u make an npc drop more than 1 of a specific item and/or have a chance to drop it like a 1/2 chance to drop something. also know how to make an npc drop multiple different items and yes i know im asking a lot
Well you can override the SpawnChance hook and check for the biome bools on the player
To drop more items you simply drop more in the NPCLoot hook? Don't really understand the problem
To get a 1/2 chance you can use Main.rand for random chances:

Code:
if (Main.rand.Next() == 0) // Next() will get a random 0 or 1, Next(5) will get a random 0, 1, 2, 3 or 4. What you enter is x, the chance will be 1/x so in that case 1/5
{
    // drop 50% chance
}
 
Hey guys, I have a little problem with the frame animation for my weapon (staff). I created the texture (with the frames beneath the main frame) fine and put the Main.RegisterItemAnimation(item.type, new DrawAnimationVertical(speed, maxframes)); in my code and it works like a charm - it's animated while in hotbar, while thrown on the ground, but the problem comes when firing (using) the staff. It shows all other "forms" above the one I'm holding. If you can help and need the code I'll upload it here, so you can see where is the problem. Thanks!
 
I made a custom shot gun but in game it only shoots 1 bullet like a normal gun would anyone know how to fix this? heres code below



Code:
using Terraria.ID;
using Terraria.ModLoader;

namespace NicksMod.Items
{
    public class ForestDragonEggFragmentShotgun : ModItem
    {
        public override void SetStaticDefaults()
        {
            Tooltip.SetDefault("A shotgun made from the fragments of shattered forest dragon eggs");
        }

        public override void SetDefaults()
        {
            item.damage = 9;
            item.ranged = true;
            item.width = 38;
            item.height = 29;
            item.useAnimation = 24;
            item.useTime = 24;
            item.reuseDelay = 0;
            item.useStyle = 5;
            item.noMelee = true; //so the item's animation doesn't do damage
            item.knockBack = 3;
            item.value = 1000;
            item.rare = 1;
            item.UseSound = SoundID.Item36;
            item.autoReuse = false;
            item.shoot = 10; //idk why but all the guns in the vanilla source have this
            item.shootSpeed = 8f;
            item.useAmmo = AmmoID.Bullet;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
                        recipe.AddIngredient(null, "ForestDragonEggFragment", 1);
            recipe.AddTile(TileID.Anvils);
            recipe.SetResult(this);
            recipe.AddRecipe();
               
                // What if I wanted it to shoot like a shotgun?
        // Shotgun style: Multiple Projectiles, Random spread
        /*public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            int numberProjectiles = 2 + Main.rand.Next(2); // 4 or 5 shots
            for (int i = 0; i < numberProjectiles; i++)
            {
                Vector2 perturbedSpeed = new Vector2(speedX, speedY).RotatedByRandom(MathHelper.ToRadians(30)); // 30 degree spread.
                // If you want to randomize the speed to stagger the projectiles
                // float scale = 1f - (Main.rand.NextFloat() * .3f);
                // perturbedSpeed = perturbedSpeed * scale;
                Projectile.NewProjectile(position.X, position.Y, perturbedSpeed.X, perturbedSpeed.Y, type, damage, knockBack, player.whoAmI);
            }
            return false; // return false because we don't want tmodloader to shoot projectile
        }*/

                     
        }
    }
}
 
Last edited:
I made a custom shot gun but in game it only shoots 1 bullet like a normal gun would anyone know how to fix this? heres code below
also how do you make projectiles roll like a boulder across the ground?

In code, you can use // to comment out a single line, or you can place /* and */ around a block of code to comment out that entire block. Commented-out text is just there for people to read, and isn't treated as code in the build. If you look at your code, you can see some of the code you've borrowed is inside a /* and */ block. More of the code you might want to use is also placed behind further // marks.
 
error CS0246: The type or namespace name 'Vector2' could not be found (are you missing a using directive or an assembly reference?)
... i know this asking a lot but can someone help me pls lol im still beginner. heres code below
Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace NicksMod.Items
{
    public class ForestDragonEggFragmentShotgun : ModItem
    {
        public override void SetStaticDefaults()
        {
            Tooltip.SetDefault("A shotgun made from the fragments of shattered forest dragon eggs");
        }

        public override void SetDefaults()
        {
            item.damage = 9;
            item.ranged = true;
            item.width = 38;
            item.height = 29;
            item.useAnimation = 24;
            item.useTime = 24;
            item.reuseDelay = 0;
            item.useStyle = 5;
            item.noMelee = true; //so the item's animation doesn't do damage
            item.knockBack = 3;
            item.value = 1000;
            item.rare = 1;
            item.UseSound = SoundID.Item36;
            item.autoReuse = false;
            item.shoot = 10; //idk why but all the guns in the vanilla source have this
            item.shootSpeed = 8f;
            item.useAmmo = AmmoID.Bullet;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
                        recipe.AddIngredient(null, "ForestDragonEggFragment", 1);
            recipe.AddTile(TileID.Anvils);
            recipe.SetResult(this);
            recipe.AddRecipe();
                
                }
        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            int numberProjectiles = 3 + Main.rand.Next(2); // 4 or 5 shots
            for (int i = 0; i < numberProjectiles; i++)
            {
                Vector2 perturbedSpeed = new Vector2(speedX, speedY).RotatedByRandom(MathHelper.ToRadians(30)); // 30 degree spread.
                // If you want to randomize the speed to stagger the projectiles
                // float scale = 1f - (Main.rand.NextFloat() * .3f);
                // perturbedSpeed = perturbedSpeed * scale;
                Projectile.NewProjectile(position.X, position.Y, perturbedSpeed.X, perturbedSpeed.Y, type, damage, knockBack, player.whoAmI);
            }
            }
       
         }

}
 
Getting this issue now - error CS0115: 'Thunderbolt.Items.Weapons.Slimeeradicator.AddRecipe()': no suitable method found to override

Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Thunderbolt.Items.Weapons
{
    public class Slimeeradicator : ModItem
    {
        public override void SetStaticDefaults()
        {
            Tooltip.SetDefault("pelts slime at enemies.");
        }
        public override void SetDefaults()
        {
            item.damage = 75;
            item.ranged = true;
            item.width = 50;
            item.height = 32;
            item.useTime = 30;
            item.useAnimation = 20;
            item.useStyle = 5;
            item.noMelee = true;
            item.knockBack = 6;
            item.value = 10000;
            item.rare = 4;
            item.UseSound = SoundID.Item11;
            item.autoReuse = false;
            item.shoot = 10;
            item.shootSpeed = 16f;
            item.useAmmo = AmmoID.Bullet;
        }

        public override void AddRecipe()
        {
            recipe = new ModRecipe(Mod);
            recipe.AddIngredient(ItemID.dirtblock, 2);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}
 
Back
Top Bottom