Standalone [1.3] tModLoader - A Modding API

The tutorial doesn't list all the item parameters. Heres some more: (I can't guaruntee they all work as some functionalities are not in the api yet.)

*Phew that was a lot of typing
@bluemagic123 you should add these to the OP. Or not. I dunno. Either way I guess

item.name(string)
item.texture(string) //Path to the texture. Dunno if this works
item.code(string)//Full type name for the ModItem-extending class to be used for this item.
item.displayName(string)
item.size(int)
item.width(int)
item.height(int)
item.scale(float)//Scale multiplier used when drawing the item in the world.
item.tooltip(string)//The tooltip of the item, as seen in game.
item.useStyle(int)
item.holdStyle(int)
item.useAnimation(int)
item.useTime(int)
item.channel(bool)//Whether the item can be channeled
item.maxStack(int)
item.pick(int)//Item's Pick Power
item.axe(int)//Item's Axe Power
item.hammer(int)//Item's Hammer Power
item.tileBoost(int)//The tile placement range increase when equipped.
item.placeStyle(int)//The Placement Style to use
item.damage(int)
item.knockback(float)
item.healLife(int)//How much life is gained when consumed(must be consumable first(duh!))
item.healMana(int)//How much mana is gained when consumed(must be consumable first(duh!))
item.potion(bool)//Whether the item is a potion (triggers the Potion Sickness debuff).
item.consumable(bool)//Whether it is consumed on use
item.autoReuse(bool)//Whether the item can be continuously used by holding down.
item.useTurn(bool)//Whether the player will turn to face the mouse
item.defence(int)
item.rare(int)
item.lifeRegen(int)
item.manaIncrease(int)
item.mana(int)//How much mana used on use
item.vanity(bool)//Whether or not it is an vanity item
item.crit(int//Crit chance bonus
item.noUseGraphic(bool)//Whether or not to hide item on use
item.melee(bool)//Makes the damage type melee
item.ranged(bool)//Makes the damage type ranged
item.magic(bool)//Makes the damage type magic
item.summon(bool)//Makes the damage type summon
item.reuseDelay(int)
item.color(int)//in RGB or RGBA format
item.mech(bool)//whether or not wires are displayed when the item is equipped
item.makeNPC(int, string)//NPC spawned when used
item.value(int)//Item buy value. Sell value is 1/5th of this.
item.shoot(int, string) //Projectile type used by this weapon
item.useAmmo(int, string)//The type of the ammo used by this item.
item.ammo(int, string)//The type of the ammo used by this item.
item.accessory(bool)//Whether or not it is an accessory
item.buff(int, string)//The type of buff given by this item
 
So, how to make a recipe for mod item?
Code:
    public override void AddRecipes()
    {
        ModRecipe recipe = new ModRecipe(this);
        recipe.AddIngredient(ItemID.DirtBlock);
        recipe.SetResult(ItemID.CoralSlasher, 1);
        recipe.AddRecipe();
}
This won't work :(
 
So, how to make a recipe for mod item?
Code:
    public override void AddRecipes()
    {
        ModRecipe recipe = new ModRecipe(this);
        recipe.AddIngredient(ItemID.DirtBlock);
        recipe.SetResult(ItemID.CoralSlasher, 1);
        recipe.AddRecipe();
}
This won't work :(
Is CoralSlasher an item you are making? I can't find it in the vanilla code.

If you want to use an item that is added by your mod, you'll have to use this method:
public void SetResult(Mod mod, string itemName, int stack = 1)
Sets the result of this recipe with the given item name from the given mod, and with the given stack stack. If the mod parameter is null, then it will automatically use an item from the mod creating this recipe.

For example, in the example mod I do this:
Code:
recipe.SetResult(null, "Example Sword");
 
Is CoralSlasher an item you are making? I can't find it in the vanilla code.

If you want to use an item that is added by your mod, you'll have to use this method:
public void SetResult(Mod mod, string itemName, int stack = 1)
Sets the result of this recipe with the given item name from the given mod, and with the given stack stack. If the mod parameter is null, then it will automatically use an item from the mod creating this recipe.

For example, in the example mod I do this:
Code:
recipe.SetResult(null, "Example Sword");
Yay, it works! Thank you very much ^_^
 
So by using Goraterons easy install method I was able to quickly install the basic tModloader, and this is what I got! Quite pleased it all went so smoothly

It is real easy aint it? :D No need to install the tModLoader files seperately either, it's all in the .exe :D
[DOUBLEPOST=1437123473,1437123307][/DOUBLEPOST]Here's how I do my main.cs file.. I like it more this way
I create another .cs file which will hold a lot of my 'utilities' functions, and then I can simply call that from within my main.cs
For example I created a setModProperty function, I just like it more this way.

using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using OverpowerTime.Items;
using OverpowerTime.Services;

namespace OverpowerTime
{
public class OverpowerTime : Mod
{
public string mod_name,
mod_author,
mod_ver,
mod_path,
mod_itemsfolder,
mod_logsfolder;

Utilities _util;

public OverpowerTime()
{
_util = new Utilities(this);

/* _util.setModName("Overpower Time");
_util.setModVersion("1");
_util.setModAuthor("Gorateron (GIMJ)");
_util.setModItemsfolder("Items");
_util.setModPath("OverpowerTime"); */

_util.setModProperty(1, "Overpower Time");
_util.setModProperty(2, "Gorateron (GIMJ)");
_util.setModProperty(3, "1");
_util.setModProperty(4, "OverpowerTime");
_util.setModProperty(5, "Items");
_util.setModProperty(6, "Logs");

}

public override void SetModInfo(out string name, ref string version, ref string author)
{
name = mod_name;
version = mod_ver;
author = mod_author;

}

public override void Load()
{
AddItem("Empowered Wooden Sword", new EPWoodenSword(), mod_path+"/"+mod_itemsfolder+"/EPWoodenSword");
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(this);
recipe.AddIngredient(ItemID.DirtBlock);
recipe.SetResult(null, "Empowered Wooden Sword");
recipe.AddRecipe();
}
}
}

using System;
using System.Globalization;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

namespace OverpowerTime.Services
{
public class Utilities
{
OverpowerTime _parent;

public Utilities(OverpowerTime parent)
{
_parent = parent;
}

public void setModProperty(int property, string value)
{
switch(property)
{
case 1:
_parent.mod_name = value;
break;
case 2:
_parent.mod_author = value;
break;
case 3:
_parent.mod_ver = value;
break;
case 4:
_parent.mod_path = value;
break;
case 5:
_parent.mod_itemsfolder = value;
break;
case 6:
_parent.mod_logsfolder = value;
break;
default:

break;
}
}

public void setModName(string name)
{
_parent.mod_name = name;
}

public void setModItemsfolder(string folder)
{
_parent.mod_itemsfolder = folder;
}

public void setModAuthor(string author)
{
_parent.mod_author = author;
}

public void setModPath(string path)
{
_parent.mod_path = path;
}

public void setModVersion(string version)
{
_parent.mod_ver = version;
}

public void Log(string log)
{
string logsDir = _parent.mod_path + "/" + _parent.mod_logsfolder;
Directory.CreateDirectory(logsDir);
string curDate = DateTime.Now.ToString("M/d/yyyy");
string logsFile = logsDir = "/[" + curDate + "]_logs.txt";

if (!File.Exists(logsFile))
File.Create(logsFile);

File.WriteAllText(@logsFile, log);
File.WriteAllText(@logsFile, "/n");
}
}

}


I went to bed after this so I haven't done much with it yet
[DOUBLEPOST=1437123605][/DOUBLEPOST]
My highest priorities for the next update are to make in-game error messages appear when the game crashes or a build fails, and to auto-disable any mods that crash upon loading. I know the feel from tAPI r15 :p
What do you mean by assigning an image to a custom item image?

Oh yes please do that! It would be much easier to know what's going wrong.
Nevermind about the item image, it is actually possible.. hehe
 
Last edited:
I'd be willing to make a tutorial on how to add mods via Microsoft Visual Studio, if you guys want? So you can add/change code via Visual Studio, you'll get auto-complete etc. which is really nice
[DOUBLEPOST=1437128148,1437127702][/DOUBLEPOST]
The tutorial doesn't list all the item parameters. Heres some more: (I can't guaruntee they all work as some functionalities are not in the api yet.)

*Phew that was a lot of typing
@bluemagic123 you should add these to the OP. Or not. I dunno. Either way I guess

item.name(string)
item.texture(string) //Path to the texture. Dunno if this works
item.code(string)//Full type name for the ModItem-extending class to be used for this item.
item.displayName(string)
item.size(int)
item.width(int)
item.height(int)
item.scale(float)//Scale multiplier used when drawing the item in the world.
item.tooltip(string)//The tooltip of the item, as seen in game.
item.useStyle(int)
item.holdStyle(int)
item.useAnimation(int)
item.useTime(int)
item.channel(bool)//Whether the item can be channeled
item.maxStack(int)
item.pick(int)//Item's Pick Power
item.axe(int)//Item's Axe Power
item.hammer(int)//Item's Hammer Power
item.tileBoost(int)//The tile placement range increase when equipped.
item.placeStyle(int)//The Placement Style to use
item.damage(int)
item.knockback(float)
item.healLife(int)//How much life is gained when consumed(must be consumable first(duh!))
item.healMana(int)//How much mana is gained when consumed(must be consumable first(duh!))
item.potion(bool)//Whether the item is a potion (triggers the Potion Sickness debuff).
item.consumable(bool)//Whether it is consumed on use
item.autoReuse(bool)//Whether the item can be continuously used by holding down.
item.useTurn(bool)//Whether the player will turn to face the mouse
item.defence(int)
item.rare(int)
item.lifeRegen(int)
item.manaIncrease(int)
item.mana(int)//How much mana used on use
item.vanity(bool)//Whether or not it is an vanity item
item.crit(int//Crit chance bonus
item.noUseGraphic(bool)//Whether or not to hide item on use
item.melee(bool)//Makes the damage type melee
item.ranged(bool)//Makes the damage type ranged
item.magic(bool)//Makes the damage type magic
item.summon(bool)//Makes the damage type summon
item.reuseDelay(int)
item.color(int)//in RGB or RGBA format
item.mech(bool)//whether or not wires are displayed when the item is equipped
item.makeNPC(int, string)//NPC spawned when used
item.value(int)//Item buy value. Sell value is 1/5th of this.
item.shoot(int, string) //Projectile type used by this weapon
item.useAmmo(int, string)//The type of the ammo used by this item.
item.ammo(int, string)//The type of the ammo used by this item.
item.accessory(bool)//Whether or not it is an accessory
item.buff(int, string)//The type of buff given by this item

You are right, certain things are not in yet. You can easily see this if you setup your mod project via Visual Studio, and add the API in as a reference.
For example. item.Code isn't in, item.buff is actually split into item.buffTime and item.buffType

I'm not sure, but it seems saving items doesn't work? When I create my custom items they won't stay in my inventory after I close the world and go back in again.
 
Last edited:
The function you're looking for is AddTile(ID) I believe.

So you'd add something like recipe.AddTile(18) (18 is the tile id for workbench I believe) before recipe.AddRecipe() to make it only craftable at a workbench.

Within your recipe, before you call "recipe.AddRecipe()", you should call "recipe.AddTile(##)" where "##" is the tile ID of the workstation you want to use.

Code:
ModRecipe recipe = new ModRecipe(this);
recipe.AddIngredient(ItemID.DirtBlock);
recipe.SetResult(ItemID.DirtBlock, 999);
recipe.AddTile(18);
recipe.AddRecipe();
This crafts a dirt block into 999 dirt blocks, provided it's near a tile of ID 18 (workbench). All of that apart from the "AddTile" line is from the example in the OP.

It's exactly what I was looking, thanks to the 2: D

PS: To add a "workbench" personalized, would be more complicated, right? (with workbench, I refer to a custom craft)
 
It's exactly what I was looking, thanks to the 2: D

PS: To add a "workbench" personalized, would be more complicated, right? (with workbench, I refer to a custom craft)

tModLoader doesn't support custom tiles yet, but in the future you can do that.
 
With "item.makeNPC(int, string)", would the integer be the amount of the NPC you spawn, and the string be the NPC? How is that used? "NPCID.Guide"?

Edit: Or is it that the integer is the ID of the NPC and the string is its name? I don't know.
 
Last edited:
With "item.makeNPC(int, string)", would the integer be the amount of the NPC you spawn, and the string be the NPC? How is that used? "NPCID.Guide"?

Edit: Or is it that the integer is the ID of the NPC and the string is its name? I don't know.

Hope this helps you, this is from tAPI
In tModLoader it seems item.makeNPC only takes a type of 'short', and not string or int. So it works slightly differently from tAPI or it is not finished yet. As seen here:
BfbZcDd.png

You can set up your project in Visual Basic and you can easily see what types these things ask for :) If people really don't know how to set it up I might make a tutorial
Vh2jMU7.png
 
I'm going to wait until tModLoader is more or less complete before I attempt to learn how to put RPG elements and custom health and mana meters into a mod. One of the tutorials I came across for tAPI did mention that Visual Studio Express 2013 makes it much easier to code mods for Terraria. A tutorial for using VSE with tModLoader would be awesome.
 
Hope this helps you, this is from tAPI
In tModLoader it seems item.makeNPC only takes a type of 'short', and not string or int. So it works slightly differently from tAPI or it is not finished yet. As seen here:

You can set up your project in Visual Basic and you can easily see what types these things ask for :) If people really don't know how to set it up I might make a tutorial

I have the follow-up question of whether I'm using it wrong, or is it not implemented yet, because it doesn't seem to be working for me, although the mod does build correctly.

Code:
item.width = 40;
item.height = 40;
item.useTime = 20;
item.useAnimation = 20;
item.useStyle = 1;
item.value = 52156;
item.rare = 2;
item.useSound = 1;
item.autoReuse = false;
item.consumable = true;
item.useTurn = false;
item.makeNPC = 1;
item.maxStack = 99;
 
I have the follow-up question of am I using it wrong, or is it not implemented yet, because it doesn't seem to be working for me, although the mod does build correctly.

Code:
item.width = 40;
item.height = 40;
item.useTime = 20;
item.useAnimation = 20;
item.useStyle = 1;
item.value = 52156;
item.rare = 2;
item.useSound = 1;
item.autoReuse = false;
item.consumable = true;
item.useTurn = false;
item.makeNPC = 1;
item.maxStack = 99;

What errors do you get in the log?
I got make NPC to work, but only with one mob and it only appeared for a second then dissapeared.
 
None. The mod builds just fine, but the item doesn't spawn a slime when I use it.

Yeah, I dunno why it doesn't work, sorry. The only one that worked for me was: item.makeNPC = 355. I need to mess with it more. It might just be because the modloader doesn't have that implemented yet.
[DOUBLEPOST=1437150417,1437150262][/DOUBLEPOST]
Not fun you couldn't steal codes from other mods

A tutorial would be fantastic. And it also would make it much easier to see what the modloader does and doesn't have right now, because right now, I'm just kinda blindly experimenting.
 
Yeah, I dunno why it doesn't work, sorry. The only one that worked for me was: item.makeNPC = 355. I need to mess with it more. It might just be because the modloader doesn't have that implemented yet.

That's weird. Fireflies work for me too, but only at night, though that makes sense. Slime doesn't work regardless of time of day though. Oh well. Thanks for your help!
 
Okay I'll make a tutorial then on how to set it up, it's really easy.. and yes it makes it quite a lot easier.
 
Back
Top Bottom