tModLoader Official tModLoader Help Thread

When an enemy npc is inflicted with my custom debuff they change color but they don't revert back to the original color.
Here is the debuff code:
Code:
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
using System;

namespace EpicnessModRemastered.Buffs
{
    public class Freeze : ModBuff
    {
        public override void SetDefaults()
        {
            Main.buffNoTimeDisplay[Type] = false;
            Main.buffName[this.Type] = "Freeze";
            Main.buffTip[this.Type] = "Nothing Shall MOVE!!!";
        }
        public override void Update(NPC npc, ref int buffIndex)//, int buffIndex, int buffType, int buffTime)
        {
            npc.velocity.X = 0;
            npc.velocity.Y = 0;
            npc.color = new Color(0, 80, 255, 100);
        }
       
    }
}
 
I need some help with my mod. I am trying to make my custom mod item a material for some armor, but when i add the ingredient to the armor, it says that my modded item is only a variable. Can someone please tell me how to make the custom item a material. Thanks
 
The reason for that is that Terraria uses the BlendState of AlphaBlend, which doesn't like semi-transparent pixels very well. There's two ways around this, though.
1) Create your own SpriteBatch and use BlendState.AlphaBlend in 'Begin'.
2) Give your sprite a black background and then set it's Alpha to 0.
1 is a bit complex. 2 is more straight forward, but can make parts of your sprite dark that you don't want it to.
Or use a helper method
Code:
        public static void MultiplyColorsByAlpha(this Texture2D texture)
        {
            Color[] data = new Color[texture.Width * texture.Height];
            texture.GetData(data);
            for (int i = 0; i < data.Length; i++)
            {
                Vector4 we = data[i].ToVector4();
                data[i] = new Color(we.X * we.W, we.Y * we.W, we.Z * we.W, we.W);
            }
            texture.SetData(data);
        }
 
How to make sprite rotate correctly?

This is my custom Bone Dagger's Projectile :
Code:
 public override void SetDefaults()
        {
            projectile.name = "Improve Bone Dagger";
            projectile.width = 22;
            projectile.height = 22;
            projectile.friendly = true;
            projectile.penetrate = 6;
            projectile.thrown = true;
        }

        public override void AI()
        {
           this.ai[0] += 1f;
           if (this.ai[0] >= 20f)
           {
             this.velocity.Y = this.velocity.Y + 0.4f;
             this.velocity.X = this.velocity.X * 0.97f;
           }
           else //if (this.type == 48 || this.type == 54 || this.type == 93 || this.type == 520 || this.type == 599)
           {
             this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 1.57f;
           }
        }
AI function is cpoied from gamesource (using ILSpy) , but the projectile does not rotate like bone throwing knife. So I think it isn't enough to make an projectile rotate. What should I add to my code?

What happened :

JeDBfTB.png


What I want

MwHK502.png
 
How to make sprite rotate correctly?

This is my custom Bone Dagger's Projectile :
Code:
 public override void SetDefaults()
        {
            projectile.name = "Improve Bone Dagger";
            projectile.width = 22;
            projectile.height = 22;
            projectile.friendly = true;
            projectile.penetrate = 6;
            projectile.thrown = true;
        }

        public override void AI()
        {
           this.ai[0] += 1f;
           if (this.ai[0] >= 20f)
           {
             this.velocity.Y = this.velocity.Y + 0.4f;
             this.velocity.X = this.velocity.X * 0.97f;
           }
           else //if (this.type == 48 || this.type == 54 || this.type == 93 || this.type == 520 || this.type == 599)
           {
             this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 1.57f;
           }
        }
AI function is cpoied from gamesource (using ILSpy) , but the projectile does not rotate like bone throwing knife. So I think it isn't enough to make an projectile rotate. What should I add to my code?

What happened :

JeDBfTB.png


What I want

MwHK502.png
I'm confused. The code you have posted shouldn't even build correctly, are you sure that is the code that is being used in that example image? For example, this.ai[0] should be projectile.ai[0] and so on for all the other "this"s
 
I'm confused. The code you have posted shouldn't even build correctly, are you sure that is the code that is being used in that example image? For example, this.ai[0] should be projectile.ai[0] and so on for all the other "this"s
My bad, i copy it from my old .cs file so "this" still not be replaced by "projectile", but the structure is not changed.
After some research, I make it rotate like my aim : after projectile.velocity.X reach its limit, it start to rotate 360 degrees and drop to the ground. But the magic number "5" in the code below is only the one that I think is the most suitable after some build and test, is there any way to calculate it or an better method to achieve my aim?
Code:
  if (this.counter >= 5)
  {
      projectile.rotation += (float)(Math.PI / 5f);
  }
  else
  {
      projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f;
  }

Full code
Code:
  private int counter;
  public override void SetDefaults()
  {
      projectile.CloneDefaults(ProjectileID.BoneDagger);
      projectile.name = "Improve Bone Dagger";
      projectile.aiStyle = 0;
      projectile.penetrate = 4;
      this.counter = 0;
  }

  public override void AI()
  {
      int num = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 75, projectile.velocity.X, projectile.velocity.Y, 100, default(Color), 1.2f);
      Main.dust[num].position = (Main.dust[num].position + projectile.Center) / 2f;
      Main.dust[num].noGravity = true;
      if (Main.rand.Next(3) == 0)
      {
      Main.dust[num].scale *= 2f;
      }
          projectile.ai[0] += 1f;
      if (projectile.ai[0] >= 50f)
      {
          projectile.velocity.Y = projectile.velocity.Y + 0.4f;
          projectile.velocity.X = projectile.velocity.X * 0.97f;
          this.counter++;
      }
      if (this.counter >= 5)
      {
          projectile.rotation += (float)(Math.PI / 5f);
      }
      else
      {
         projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f;
      }
  }
 
Last edited:
ok, I'm trying to publish a mod, but I get this error:
The operation has timed out
at System.Net.HttpWebRequest.GetResponse()
at Terraria.ModLoader.IO.UploadFile.UploadFiles(String address, IEnumerable`1 files, NameValueCollection values)
at Terraria.ModLoader.UI.UIModSourceItem.Publish(UIMouseEvent evt, UIElement listeningElement)
can someone please help?
 
Hey, how do I position my weapons onto the characters body, like bows and guns? Like when I make rifles and reapers/bows the character is holding the stock or the bow string.
 
Got this error while trying to build my mod for the first time, I don't know what is wrong with build.txt

Failed to load C:\Users\Me\Documents\My Games\Terraria\ModLoader\Mod Sources\Mechanite\build.txt
System.FormatException: Input string was not in a correct format.
at System.Version.VersionResult.SetFailure(ParseFailureKind failure, String argument)
at System.Version.TryParseComponent(String component, String componentName, VersionResult& result, Int32& parsedComponent)
at System.Version.TryParseVersion(String version, VersionResult& result)
at System.Version.Parse(String input)
at System.Version..ctor(String version)
at Terraria.ModLoader.BuildProperties.ReadBuildFile(String modDir)
at Terraria.ModLoader.ModCompile.ReadProperties(String modFolder, IBuildStatus status)

author = Sinchu9

version = v0.1

displayName = Mechanite
Mod
hideCode = true
hideResources = true
includeSource = false
buildIgnore = *.csproj, *.user, obj\*, bin\*, .vs\*
includePDB = true
languageVersion = 4
 
Last edited:
I tried to make a minion that will shoot at enemies, but when I looked through ExampleMod I got so confused by files PurityWisp.cs and HoverShooter.cs. I got confused because PurityWisp.cs had class HoverShooter, which made me "Wait what". So, am I supposed to copy HoverShooter.cs to my mod and then make code for minion, giving it class HoverShooter?

EDIT: I got even more confused. I was looking through PurityWisp.cs and it has some sort of "ModPlayer.purityMinion" in function CheckActive. I looked through ExamplePlayer.cs, but I don't know what do I need to put into my mod if I want to make just the minion (because I saw there are some sort of badHeal, hero lives etc.)?
 
Last edited:
Got this error while trying to build my mod for the first time, I don't know what is wrong with build.txt

Failed to load C:\Users\Aidan\Documents\My Games\Terraria\ModLoader\Mod Sources\Mechanite\build.txt
System.FormatException: Input string was not in a correct format.
at System.Version.VersionResult.SetFailure(ParseFailureKind failure, String argument)
at System.Version.TryParseComponent(String component, String componentName, VersionResult& result, Int32& parsedComponent)
at System.Version.TryParseVersion(String version, VersionResult& result)
at System.Version.Parse(String input)
at System.Version..ctor(String version)
at Terraria.ModLoader.BuildProperties.ReadBuildFile(String modDir)
at Terraria.ModLoader.ModCompile.ReadProperties(String modFolder, IBuildStatus status)

author = Sinchu9

version = v0.1

displayName = Mechanite
Mod
hideCode = true
hideResources = true
includeSource = false
buildIgnore = *.csproj, *.user, obj\*, bin\*, .vs\*
includePDB = true
languageVersion = 4
version = v0.1
is wrong
version = 0.1
is right.
 
version = v0.1
is wrong
version = 0.1
is right.

now I get this

Failed to load C:\Users\Me\Documents\My Games\Terraria\ModLoader\Mod Sources\Mechanite\build.txt
System.ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length
at System.String.Substring(Int32 startIndex, Int32 length)
at Terraria.ModLoader.BuildProperties.ReadBuildFile(String modDir)
at Terraria.ModLoader.ModCompile.ReadProperties(String modFolder, IBuildStatus status)
 
now I get this

Failed to load C:\Users\Me\Documents\My Games\Terraria\ModLoader\Mod Sources\Mechanite\build.txt
System.ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length
at System.String.Substring(Int32 startIndex, Int32 length)
at Terraria.ModLoader.BuildProperties.ReadBuildFile(String modDir)
at Terraria.ModLoader.ModCompile.ReadProperties(String modFolder, IBuildStatus status)
Oh, was this not a copy and paste error?
Code:
displayName = Mechanite
Mod
Should be 1 line.
 
Code:
displayName = Mechanite
Mod
Should be 1 line.
Very strange, in my build.txt it looked like it was on one line. Although retyping it fixed it.


now I get this when loading in Terraria

Items/Armor/Tier1/MechaniteBreastplateR_Body
at Terraria.ModLoader.Mod.GetTexture(String name)
at Terraria.ModLoader.ModLoader.GetTexture(String name)
at Terraria.ModLoader.Mod.AddEquipTexture(EquipTexture equipTexture, ModItem item, EquipType type, String name, String texture, String armTexture, String femaleTexture)
at Terraria.ModLoader.Mod.AddEquipTexture(ModItem item, EquipType type, String name, String texture, String armTexture, String femaleTexture)
at Terraria.ModLoader.Mod.AutoloadItem(Type type)
at Terraria.ModLoader.Mod.Autoload()
at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)

I also have other armor sets have the same naming convention and work fine, so I'm confused

Folder.png
 
Very strange, in my build.txt it looked like it was on one line. Although retyping it fixed it.


now I get this when loading in Terraria

Items/Armor/Tier1/MechaniteBreastplateR_Body
at Terraria.ModLoader.Mod.GetTexture(String name)
at Terraria.ModLoader.ModLoader.GetTexture(String name)
at Terraria.ModLoader.Mod.AddEquipTexture(EquipTexture equipTexture, ModItem item, EquipType type, String name, String texture, String armTexture, String femaleTexture)
at Terraria.ModLoader.Mod.AddEquipTexture(ModItem item, EquipType type, String name, String texture, String armTexture, String femaleTexture)
at Terraria.ModLoader.Mod.AutoloadItem(Type type)
at Terraria.ModLoader.Mod.Autoload()
at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)

I also have other armor sets have the same naming convention and work fine, so I'm confused

Probably the namespace, double check things and look at the Texture Load error guide in my signature.
 
Can someone please help me with my mod. I am trying to make it so that one mob can drop a modded item and another mob drops another item. Here is my code so far :

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

namespace SukiMod.NPCs
{
public class ModGlobalNPC : GlobalNPC
{
public override void NPCLoot(NPC npc)
{
if (npc.type == NPCID.Vulture)
{
if (Main.rand.Next(2) == 0) //item rarity
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("VultureFeather")); //Item spawn

if (npc.type == NPCID.Zombie)

if (Main.rand.Next(2) == 0) //item rarity

Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ZombieBrain")); //Item spawn
}
}
}
}
}

Do i need to add or remove something or make another ModGlobalNPC file? Please help me!
 
Back
Top Bottom