tModLoader How Do I Properly Rename Vanilla Terraria Items?

Hi,

I'm extremely new to Terraria modding and C#, so bear with me please :C

So I'm working on a mod that changes the names of every vanilla item to something different, for inside joke reasons that I do not wish to share.

Obviously I didn't know how to do this, so I went to the googel to find out how to do such a thing, where I found a couple lines of code that use Item.SetNameOverride to essentially just change the name of an item, which I found here.
And here's what I used from that:
C#:
if (item.type == ItemID.Shuriken) {
    item.SetNameOverride("Iron Shuriken");
}
I just copied and pasted this and now my code looks like so (sorry I don't know how to explain C# classes and vars and whatnot, again bear with me please):
C#:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace CoolItemsTest0.Global
{
    public class GlobalItemList : GlobalItem
    {
        public override void SetDefaults(Item item)
        {
            // Reserved for Copper Shortsword
            if (item.type == ItemID.CopperShortsword)
            {
                item.SetNameOverride("Bronze Edition Crap Sword");
            }
        }
    }
}

This worked.

So with that figured out, I decided to try copy and pasting that around 130 times to try to rename every single item in Terraria, shown here:
C#:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace CoolItemsTest0.Global
{
    public class GlobalItemList : GlobalItem
    {
        public override void SetDefaults(Item item)
        {
            // Reserved for Copper Shortsword
            if (item.type == ItemID.CopperShortsword)
            {
                item.SetNameOverride("Bronze Edition Crap Sword");
            }
            //Start of Item List
            if (item.type == ItemID.CopperShortsword)
            {
                item.SetNameOverride("Bronze Edition Crap Sword");
            }
            if (item.type == ItemID.CopperShortsword)
            {
                item.SetNameOverride("Bronze Edition Crap Sword");
            }
            if (item.type == ItemID.CopperShortsword)
            {
                item.SetNameOverride("Bronze Edition Crap Sword");
            }
            if (item.type == ItemID.CopperShortsword)
            {
                item.SetNameOverride("Bronze Edition Crap Sword");
            }
            if (item.type == ItemID.CopperShortsword)
            {
                item.SetNameOverride("Bronze Edition Crap Sword");
            }
            if (item.type == ItemID.CopperShortsword)
            {
                item.SetNameOverride("Bronze Edition Crap Sword");
            }
            if (item.type == ItemID.CopperShortsword)
            {
                item.SetNameOverride("Bronze Edition Crap Sword");
            }
        }
    }
}
(please ignore the fact it's all copper shortsword, I just wanted to give an example because the actual code is accurately represented here and also it's kinda sus so shush)

I tested this, and it worked perfectly as far as I could tell. All the items I renamed were renamed properly, and it seemed to leave the rest alone.

Until I tested it with friends.
Apparently what it decided to do was randomly rename items whenever you picked them up and it wasn't even really consistent.

I tried searching this function but there is literally no other documentation on it besides that one forum linked above.

SO (tl;dr), I'm not sure what to do here. Is there something wrong with what I'm doing, and/or is there a better way to do this?

If I need to clarify anything please let me know. Again, I'm sorry I'm not well-versed in C# or Terraria modding
 
I don't know what the exact problem might be, but I can guess. Perhaps in the game the types are not quite correctly synchronized and it would be best to use not Item.type but Item.netID.
Code:
if (item.netID == ItemID.CopperShortsword)
    item.SetNameOverride("Bronze Edition Crap Sword");
if (item.netID == ItemID.Katana)
    item.SetNameOverride("Japanese long sword");
And good luck learning C#.
 
I don't know what the exact problem might be, but I can guess. Perhaps in the game the types are not quite correctly synchronized and it would be best to use not Item.type but Item.netID.
Code:
if (item.netID == ItemID.CopperShortsword)
    item.SetNameOverride("Bronze Edition Crap Sword");
if (item.netID == ItemID.Katana)
    item.SetNameOverride("Japanese long sword");
And good luck learning C#.
Ok so i tried this: it did work.

However, it also still keeps renaming items at random in multiplayer, like before. I realized I had noticed this already and did some testing which confirmed my suspicions.
So basically it's doing the same thing as before.

I also checked to see if any mods were conflicting with it, both in multiplayer and singleplayer, and it seems like it's not affecting it (which it really shouldn't but idk technology is weird)

So basically it only does this in multiplayer. I'm not entirely sure why.
 
Ok so i tried this: it did work.

However, it also still keeps renaming items at random in multiplayer, like before. I realized I had noticed this already and did some testing which confirmed my suspicions.
So basically it's doing the same thing as before.

I also checked to see if any mods were conflicting with it, both in multiplayer and singleplayer, and it seems like it's not affecting it (which it really shouldn't but idk technology is weird)

So basically it only does this in multiplayer. I'm not entirely sure why.
try adding this
public override bool InstancePerEntity => true;
 
try adding this
public override bool InstancePerEntity => true;
Did that, didn't work.

Would you mind confirming where I place this line just so I know I'm not being an idiot? Sorry, again not well-versed in C# yet

I'll also mention that it works completely fine in singleplayer and while I'm hosting a multiplayer server. It just stops working properly whenever a friend of mine hosts a server
 
Back
Top Bottom