Standalone [1.3] tModLoader - A Modding API

is my terraria folder in documents supposed to be just a JSON file named config?
It's like that when you newly install Terraria.

Okay, nope! That doesn't appear in my tModLoader world.

EDIT: just realized, one of my worlds disappeared from tModLoader. One of the worlds that are ACTUALLY in the ModLoader World folder.

o_O
Hm, can you describe to me the vanilla worlds that did appear in the tModLoader folder? And are you using any sort of modification thing besides tModLoader?

Hey, bluemagic, I found a very STRANGE bug. Whenever I say recipe.AddTile(ItemID.WorkBench); it is meant to make the item crafted at a workbench, correct? But I checked the guide, (by guide I mean the NPC) and he said it was crafted at a present even though I said to craft it at a workbench in the code. This confused me VERY much.. I got it working by using the actual ID number, (18).
Well, that's a bug alright; a bug in your mod :p
The problem is that you were requiring a tile that shared an ID with the workbench's item ID. You had to use TileID instead.
 
And by the second one, I saw a program that gives you any item, the only downside is that you have to quit the game.

You could easily make a mod with a command that gives you an item with a certain ID though.

Here is some code that allows you to use the console to spawn items to your character using ItemIDs for vanilla Items and names for modItems. Add this to your mod file (the one with SetModInfo) Should work...I put it together kinda quickly, but it should prove useful to you and anyone else who wants to spawn items without adding recipes or using external tools.

To be honest, maybe I should make this into a mod and package it together with other useful debugging commands and such, kindof a Modders toolkit or something....

Code:
        public override void ChatInput(string text)
        {
            if (text[0] != '/')
            {
                return;
            }
            text = text.Substring(1);
            int index = text.IndexOf(' ');
            string command;
            string[] args;
            if (index < 0)
            {
                command = text;
                args = new string[0];
            }
            else
            {
                command = text.Substring(0, index);
                args = text.Substring(index + 1).Split(' ');
            }
            if (command == "item")
            {
                ItemCommand(args);
            }
            else if (command == "moditem")
            {
                ModItemCommand(args);
            }

        }

       
    private void ItemCommand(string[] args)
        {
            int type;
            int stack = 1;
            if (args.Length == 0/* || !Int32.TryParse(args[0], out type)*/)
            {
                Main.NewText("Usage: /item itemID(itemID or name) [stack]");
                return;
            }

            if(!Int32.TryParse(args[0], out type))
            {
                var itemid = typeof(Terraria.ID.ItemID);
                var field = itemid.GetField(args[0]);
                if(field == null)
                {
                    Main.NewText("Usage: /item itemID(itemID or name) [stack]");
                    return;
                }
                type = (short)field.GetValue(null);
            }

            if (args.Length == 2 && !Int32.TryParse(args[1], out stack))
            {
                Main.NewText("Usage: /item itemID [stack]");
                return;
            }

            Item.NewItem((int)Main.player[Main.myPlayer].Center.X, (int)Main.player[Main.myPlayer].Center.Y, 0, 0, type, stack);
        }

        private void ModItemCommand(string[] args)
        {
            String modName = this.Name;
            int stack = 1;
            if (args.Length == 0)
            {
                Main.NewText("Usage: /moditem itemName [modName] [stack]");
                return;
            }
            if(args.Length >= 2)
            {
                if(!Int32.TryParse(args[1], out stack))
                {
                    if (args.Length >= 3 && !Int32.TryParse(args[2], out stack))
                    {
                        Main.NewText("Usage: /moditem itemName [modName] [stack]");
                        return;
                    }
                    if (ModLoader.GetMod(args[1]) == null)
                    {
                        Main.NewText("Usage: /moditem itemName [modName] [stack]");
                        return;
                    }
                    modName = args[1];
                }
            }

            String itemName = args[0];

            if(stack == 0)
            {
                stack = 1;
            }
          
            Item.NewItem((int)Main.player[Main.myPlayer].Center.X, (int)Main.player[Main.myPlayer].Center.Y, 0, 0, ModLoader.GetMod(modName).ItemType(itemName), stack);

        }
 
Last edited:
Here is some code that allows you to use the console to spawn items to your character using ItemIDs for vanilla Items and names for modItems. Add this to your mod file (the one with SetModInfo) Should work...I put it together kinda quickly, but it should prove useful to you and anyone else who wants to spawn items without adding recipes or using external tools.

To be honest, maybe I should make this into a mod and package it together with other useful debugging commands and such, kindof a Modders toolkit or something....

Code:
        public override void ChatInput(string text)
        {
            if (text[0] != '/')
            {
                return;
            }
            text = text.Substring(1);
            int index = text.IndexOf(' ');
            string command;
            string[] args;
            if (index < 0)
            {
                command = text;
                args = new string[0];
            }
            else
            {
                command = text.Substring(0, index);
                args = text.Substring(index + 1).Split(' ');
            }
            if (command == "item")
            {
                ItemCommand(args);
            }
            else if (command == "moditem")
            {
                ModItemCommand(args);
            }

        }

        private void ItemCommand(string[] args)
        {
            int type;
            int stack = 1;
            if (args.Length == 0 || !Int32.TryParse(args[0], out type))
            {
                Main.NewText("Usage: /item itemID [stack]");
                return;
            }
            if (args.Length == 2 && !Int32.TryParse(args[1], out stack))
            {
                Main.NewText("Usage: /item itemID [stack]");
                return;
            }
            Item.NewItem((int)Main.player[Main.myPlayer].Center.X, (int)Main.player[Main.myPlayer].Center.Y, 0, 0, type, stack);
        }

        private void ModItemCommand(string[] args)
        {
            String modName = this.Name;
            int stack = 1;
            if (args.Length == 0)
            {
                Main.NewText("Usage: /moditem itemName [modName] [stack]");
                return;
            }
            if(args.Length >= 2)
            {
                if(!Int32.TryParse(args[1], out stack))
                {
                    if (args.Length >= 3 && !Int32.TryParse(args[2], out stack))
                    {
                        Main.NewText("Usage: /moditem itemName [modName] [stack]");
                        return;
                    }
                    if (ModLoader.GetMod(args[1]) == null)
                    {
                        Main.NewText("Usage: /moditem itemName [modName] [stack]");
                        return;
                    }
                    modName = args[1];
                }
            }

            String itemName = args[0];

            if(stack == 0)
            {
                stack = 1;
            }
          
            Item.NewItem((int)Main.player[Main.myPlayer].Center.X, (int)Main.player[Main.myPlayer].Center.Y, 0, 0, ModLoader.GetMod(modName).ItemType(itemName), stack);

        }
Hey, thanks for the command helps a lot, I got the /moditem to work, but I couldn't figure out how to use /item. Could you explain how I would say, give myself a furnace? I tried /item Furnace, I tried /item ItemID.Furnace, that didn't work either, so if you could explain the item names a bit better, that would help. Other than that, it is amazing!
 
Hey, thanks for the command helps a lot, I got the /moditem to work, but I couldn't figure out how to use /item. Could you explain how I would say, give myself a furnace? I tried /item Furnace, I tried /item ItemID.Furnace, that didn't work either, so if you could explain the item names a bit better, that would help. Other than that, it is amazing!

For vanilla items, you use their item #. There is a list to get the ids from: https://github.com/bluemagic123/tModLoader/wiki/Vanilla-Item-IDs
 
Hey, thanks for the command helps a lot, I got the /moditem to work, but I couldn't figure out how to use /item. Could you explain how I would say, give myself a furnace? I tried /item Furnace, I tried /item ItemID.Furnace, that didn't work either, so if you could explain the item names a bit better, that would help. Other than that, it is amazing!
Good point, it would be nice to use either the number or the name. I've updated the ItemCommand method, now you can do any of the following
/item Wire
/item Wire 10
/item 530
/item 530 100
and get wire every time. Of course it also works with all other items too. Remember that most item names are just no spaces, with each word capitalized.
Code:
    private void ItemCommand(string[] args)
        {
            int type;
            int stack = 1;
            if (args.Length == 0/* || !Int32.TryParse(args[0], out type)*/)
            {
                Main.NewText("Usage: /item itemID(itemID or name) [stack]");
                return;
            }

            if(!Int32.TryParse(args[0], out type))
            {
                var itemid = typeof(Terraria.ID.ItemID);
                var field = itemid.GetField(args[0]);
                if(field == null)
                {
                    Main.NewText("Usage: /item itemID(itemID or name) [stack]");
                    return;
                }
                type = (short)field.GetValue(null);
            }

            if (args.Length == 2 && !Int32.TryParse(args[1], out stack))
            {
                Main.NewText("Usage: /item itemID [stack]");
                return;
            }

            Item.NewItem((int)Main.player[Main.myPlayer].Center.X, (int)Main.player[Main.myPlayer].Center.Y, 0, 0, type, stack);
        }
 
Two things.

First, whenever I load up Terraria with the modded client, only SOME of my worlds/characters load up. So this is very annoying, because I can't use Builders Workshop to test some of my mods. Which leads to the second question.

Second, is there any way of giving yourself any item in the game without quitting the game? Or do I just have to keep quitting, and replacing my clients? Because I don't want to have to do that.

Please help! :D

Huh, I'm wondering how tModLoader is detecting those worlds in the first place, since tModLoader uses a separate folder to store information. Did you copy the files over from your vanilla Worlds folder to your tModLoader Worlds folder?

For the second one, I'm not really sure what that program has to do with this. You could easily make a mod with a command that gives you an item with a certain ID though.
I think I know what's going on here. When I first launched tModLoader, one valilla player showed up in the list. It was the one player that I had cloud synced with Steam. So it seems that any players/worlds that are on your steam cloud shows up in tModLoader too.

I wonder what would happen if a moded player/world was synced into the cloud?
 
I think I know what's going on here. When I first launched tModLoader, one valilla player showed up in the list. It was the one player that I had cloud synced with Steam. So it seems that any players/worlds that are on your steam cloud shows up in tModLoader too.

I wonder what would happen if a moded player/world was synced into the cloud?
...Oh my god, that makes so much more sense... I thought I made it so that they were separate but evidently not. I'll have to fix that for the next update.

Because modded players and worlds save as two separate files, a modded player/world synced in the cloud would appear normally to vanilla, without any trace of any modded item, tile, etc. There would be these .tplr and .twld files floating around in the cloud though that only tModLoader knows to access.
 
...Oh my god, that makes so much more sense... I thought I made it so that they were separate but evidently not. I'll have to fix that for the next update.

Because modded players and worlds save as two separate files, a modded player/world synced in the cloud would appear normally to vanilla, without any trace of any modded item, tile, etc. There would be these .tplr and .twld files floating around in the cloud though that only tModLoader knows to access.
That DOES make way more sense! Wow!
[DOUBLEPOST=1442859248,1442859005][/DOUBLEPOST]
Good point, it would be nice to use either the number or the name. I've updated the ItemCommand method, now you can do any of the following
/item Wire
/item Wire 10
/item 530
/item 530 100
and get wire every time. Of course it also works with all other items too. Remember that most item names are just no spaces, with each word capitalized.
Code:
    private void ItemCommand(string[] args)
        {
            int type;
            int stack = 1;
            if (args.Length == 0/* || !Int32.TryParse(args[0], out type)*/)
            {
                Main.NewText("Usage: /item itemID(itemID or name) [stack]");
                return;
            }

            if(!Int32.TryParse(args[0], out type))
            {
                var itemid = typeof(Terraria.ID.ItemID);
                var field = itemid.GetField(args[0]);
                if(field == null)
                {
                    Main.NewText("Usage: /item itemID(itemID or name) [stack]");
                    return;
                }
                type = (short)field.GetValue(null);
            }

            if (args.Length == 2 && !Int32.TryParse(args[1], out stack))
            {
                Main.NewText("Usage: /item itemID [stack]");
                return;
            }

            Item.NewItem((int)Main.player[Main.myPlayer].Center.X, (int)Main.player[Main.myPlayer].Center.Y, 0, 0, type, stack);
        }

Thanks for the updated code, this will help a LOT when I am modding, no more builders workshop :D

(no hate on builders workshop :p)
 

Exeton already has a command mod ready for download that has some basic commands

True, however I haven't added support for modded items as it is based off item id instead of the item name.

Also, is Main.mouseX the position of the tile the mouse is on? If it isn't is there an easy way I can get that without factoring in resolutions and stuff?
 
Last edited:
True, however I haven't added support for modded items as it is based off item id instead of the item name.

Also, is Main.mouseX the position of the tile the mouse is on? If it isn't is there an easy way I can get that without factoring in resolutions and stuff?
Main.mouseX is the position of the mouse on the screen. There's also Main.screenPosition to tell the position in the world of the game screen. So you can add together Main.screenPosition.X and Main.mouseX to get the position in the world of the mouse, then convert to tile coordinates.

How do you make a minion?
I'll make an example minion in the example mod once I add support for buffs.
 
Main.mouseX is the position of the mouse on the screen. There's also Main.screenPosition to tell the position in the world of the game screen. So you can add together Main.screenPosition.X and Main.mouseX to get the position in the world of the mouse, then convert to tile coordinates.


I'll make an example minion in the example mod once I add support for buffs.
Are there pets?
 
Back
Top Bottom