tModLoader Edit NPC Data/Behavior with mods

sukeeabanira

Terrarian
Hello
is possible to Modify vanilla Terrraria Data with modding?
I'm planning to override Vanilla terraria NPCs Behavior and Sprites with my custom mod sprites and data, but I don't want to make Resource packs for my mod.
since I'm new to terraria modding and community, i don't exactly know terraria modding structures.
thank you.
 
Look up tModLoader/ExampleMod/Common/GlobalNPCs/GuideGlobalNPC.cs at 1.4.4 · tModLoader/tModLoader and other Global NPCs for changing code of vanilla NPCs.
Also you can change vanilla sprite by just changing its asset in ModSystem. That's how I did it:
C#:
public override void PostSetupContent()
    {
    TextureAssets.Item[ID] = ModContent.Request<Texture2D>("Path/to/your/texture");
    }

Sorry to revive this semi-dead thread, but could you maybe go a bit more into detail on how to change the sprite sheet of a NPC? Im using this code but that doesnt seem to change anything:
C#:
public override void PostSetupContent() {
            TextureAssets.Npc[NPCID.Mechanic] = ModContent.Request<Texture2D>("NPCOutfits/Content/Items/Mechanic/Mechanic_Default");
        }
 
Sorry to revive this semi-dead thread, but could you maybe go a bit more into detail on how to change the sprite sheet of a NPC? Im using this code but that doesnt seem to change anything:
C#:
public override void PostSetupContent() {
            TextureAssets.Npc[NPCID.Mechanic] = ModContent.Request<Texture2D>("NPCOutfits/Content/Items/Mechanic/Mechanic_Default");
        }
sorry, idk, you made everything right. I didn't change NPCs so far so maybe they aren't changeable
 
sorry, idk, you made everything right. I didn't change NPCs so far so maybe they aren't changeable
Ah okay, thats a shame then. Was working on a mod to switch outfits for NPCs but I cant seem to find a actual way to switch the textures of them :/

EDIT: Yippie! Did manage to figure it out!
C#:
public class CustomNPC : GlobalNPC
    {
        public override bool PreDraw(NPC npc, SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor)
        {
            if(npc.type == NPCID.Mechanic) {
                switch(TagSystem.mechanicOutfit) {
                    case 1:
                        TextureAssets.Npc[npc.type] = ModContent.Request<Texture2D>("NPCOutfits/Content/Items/Mechanic/Mechanic_1");
                        break;
                    default:
                        break;
                }
                
            }
            return true;
        }
    }
 
Last edited:
Back
Top Bottom