Standalone [1.3] tModLoader - A Modding API

So the mod browser just outright crashes, without even showing the error message screen?
Did it crash, or did it claim it was "not responding"? If it was "not responding", if you waited a few more seconds, the operation would have timed out. I should multithread that anyway....
The first time, the game just vanished without a trace, or error message. The second time it was 'not responding' for about 10 seconds before a long error message popped up in a new window. The first time, I simply didn't have my router on, and the second time, I think I had my USB WiFi adapter disabled for technical reasons.
Also, for the dust's type, Main.dust[21].type gets the type of the dust in index 21 of the list of dusts in the world. What you want to do is use just 21.
Huh, that's an epic derp on my part, and explains much. I must have been thinking of something else when I copied some dust for testing purposes.
 
I cant seem to find the tModLoader folder. I also dont have the tModLoader.exe file. I already installed tModLoader but cant find the software nor the folder.
 
I cant seem to find the tModLoader folder. I also dont have the tModLoader.exe file. I already installed tModLoader but cant find the software nor the folder.
If you already installed it, then it should be inside your Steam's Terraria folder, and it should be called Terraria.exe. The vanilla exe file will be backed up as Terraria_v1.3.0.8.exe.
 
For all the recipes that require it, you could add both tiles as requirements.

Apologies, let me reword my question.

Is there a function that detects how close a specific tile is in relation to another one?

For example, a Terraria tree grows when off-screen. But how does the tree detect when something is blocking it from growing? Is there a specific function for that?
 
I don't mean to pester, but, I do have a couple of questions, at least in terms of graphics--with tModLoader, is it possible to edit the vanilla player and NPC graphics? If so, how would one go about doing this? o:
 
I'm having an error: This boss summoner won't work. The error I get is that if I use it, I get "Has Awoken" in the chat, but there is no "Eye of Madness" (which is exactly like the Eye of Cuthulu)

using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TModLoaderFirstMod.Items
{
public class SuspiciousLookingStereoPlayer : ModItem
{
public override void SetDefaults()
{
item.name = "Suspicious Looking Stereo Player";
item.width = 32;
item.height = 32;
item.maxStack = 20;
item.toolTip = "How suspicious can things get?";
item.rare = 1;
item.useAnimation = 45;
item.useTime = 45;
item.useStyle = 4;
item.useSound = 44;
item.consumable = true;
}

public override bool CanUseItem(Player player)
{
return !Main.dayTime && !NPC.AnyNPCs(mod.NPCType("EyeOfMadness"));
}

public override bool UseItem(Player player)
{
NPC.SpawnOnPlayer(player.whoAmI, mod.NPCType("EyeOfMadness"));
Main.PlaySound(15, (int)player.position.X, (int)player.position.Y, 0);
return true;
}

public override void AddRecipes()
{
ModRecipe recipe;
recipe = new ModRecipe(mod);
recipe.AddIngredient(Terraria.ID.ItemID.SoulofLight, 6);
recipe.AddIngredient(Terraria.ID.ItemID.SoulofFlight, 1);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
Top of spoiler
What is the issue? I am pretty sure the item is the problem.
 
I'm having an error: This boss summoner won't work. The error I get is that if I use it, I get "Has Awoken" in the chat, but there is no "Eye of Madness" (which is exactly like the Eye of Cuthulu)

using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TModLoaderFirstMod.Items
{
public class SuspiciousLookingStereoPlayer : ModItem
{
public override void SetDefaults()
{
item.name = "Suspicious Looking Stereo Player";
item.width = 32;
item.height = 32;
item.maxStack = 20;
item.toolTip = "How suspicious can things get?";
item.rare = 1;
item.useAnimation = 45;
item.useTime = 45;
item.useStyle = 4;
item.useSound = 44;
item.consumable = true;
}

public override bool CanUseItem(Player player)
{
return !Main.dayTime && !NPC.AnyNPCs(mod.NPCType("EyeOfMadness"));
}

public override bool UseItem(Player player)
{
NPC.SpawnOnPlayer(player.whoAmI, mod.NPCType("EyeOfMadness"));
Main.PlaySound(15, (int)player.position.X, (int)player.position.Y, 0);
return true;
}

public override void AddRecipes()
{
ModRecipe recipe;
recipe = new ModRecipe(mod);
recipe.AddIngredient(Terraria.ID.ItemID.SoulofLight, 6);
recipe.AddIngredient(Terraria.ID.ItemID.SoulofFlight, 1);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
Top of spoiler
What is the issue? I am pretty sure the item is the problem.
Can you post your NPCs code anyway? I have the (almost) exact same code and it seems to work just fine for me.
 
I don't mean to pester, but, I do have a couple of questions, at least in terms of graphics--with tModLoader, is it possible to edit the vanilla player and NPC graphics? If so, how would one go about doing this? o:
The ExampleMod shows how to swap out a texture: https://github.com/bluemagic123/tModLoader/blob/master/ExampleMod/ExampleMod.cs#L39
You should be able to do the same, except you'll need to take care to properly unload your texture replacement.
 
Apologies, let me reword my question.

Is there a function that detects how close a specific tile is in relation to another one?

For example, a Terraria tree grows when off-screen. But how does the tree detect when something is blocking it from growing? Is there a specific function for that?
Well, trees grow during UpdateWorld, we don't have hooks there yet. The code iterates through Main.tile[,] and checks active() and type.

Maybe you could use TileFrame to check Main.tile[i, j].type for surrounding tiles. If you detect the right tile, do whatever you want to do. (It might be hard. What exactly are you trying to do?)
 

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

namespace TModLoaderFirstMod.NPCs
{
public class EyeOfMadness : ModNPC
{

public override bool Autoload(ref string name, ref string texture)
{
name = "Eye Of Madness";
return mod.Properties.Autoload;
}

public override void SetDefaults()
{
npc.name = "Eye Of Madness";
npc.townNPC = false;
npc.friendly = false;
npc.width = 110;
npc.height = 152;
npc.aiStyle = 4;
npc.damage = 47;
npc.defense = 2;
npc.lifeMax = 5004;
npc.boss = true;
npc.noGravity = true;
npc.soundHit = 1;
npc.soundKilled = 1;
npc.knockBackResist = 1f;
npc.noTileCollide = true;
Main.npcFrameCount[npc.type] = 2;
animationType = NPCID.EyeofCthulhu;
music = MusicID.TheTowers;
}

public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
{
npc.lifeMax = (int)(npc.lifeMax * 0.476f * bossLifeScale);
npc.damage = 50;
}

public override bool PreNPCLoot()
{
return false;
}

public override void BossLoot(ref string name, ref int potionType)
{
name = "Eye of Madness";
potionType = ItemID.ManaPotion;
}
public override void NPCLoot()
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, Terraria.ID.ItemID.UnholyArrow, 20 + Main.rand.Next(30));
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, Terraria.ID.ItemID.IronBroadsword);

if (Main.rand.Next(10) == 0)
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, Terraria.ID.ItemID.KingStatue);
}
}
}
}
Top of spoiler

Oh, and is it possible to create a new MusicId yet? Or is that in the next update?
 

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

namespace TModLoaderFirstMod.NPCs
{
public class EyeOfMadness : ModNPC
{

public override bool Autoload(ref string name, ref string texture)
{
name = "Eye Of Madness";
return mod.Properties.Autoload;
}

public override void SetDefaults()
{
npc.name = "Eye Of Madness";
npc.townNPC = false;
npc.friendly = false;
npc.width = 110;
npc.height = 152;
npc.aiStyle = 4;
npc.damage = 47;
npc.defense = 2;
npc.lifeMax = 5004;
npc.boss = true;
npc.noGravity = true;
npc.soundHit = 1;
npc.soundKilled = 1;
npc.knockBackResist = 1f;
npc.noTileCollide = true;
Main.npcFrameCount[npc.type] = 2;
animationType = NPCID.EyeofCthulhu;
music = MusicID.TheTowers;
}

public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
{
npc.lifeMax = (int)(npc.lifeMax * 0.476f * bossLifeScale);
npc.damage = 50;
}

public override bool PreNPCLoot()
{
return false;
}

public override void BossLoot(ref string name, ref int potionType)
{
name = "Eye of Madness";
potionType = ItemID.ManaPotion;
}
public override void NPCLoot()
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, Terraria.ID.ItemID.UnholyArrow, 20 + Main.rand.Next(30));
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, Terraria.ID.ItemID.IronBroadsword);

if (Main.rand.Next(10) == 0)
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, Terraria.ID.ItemID.KingStatue);
}
}
}
}
Top of spoiler

Oh, and is it possible to create a new MusicId yet? Or is that in the next update?
The problem is that you're trying to spawn an NPC with an internal name of "EyeOfMadness", but when you autoload the NPC in the Autoload hook you're changing its internal name of "Eye of Madness" with spaces. You'll have to use one or the other. (Note that whatever you put in SetDefaults is just the display name in-game and doesn't matter.)

And yes, it's only possible to create new music IDs in the next update.

Is there a way to code an accessory like the Brain of Confusion? ie. giving debuffs to nearby mobs when the player gets hurt.
That will be possible using the ModPlayer.Hurt hook in the next update.
 
The problem is that you're trying to spawn an NPC with an internal name of "EyeOfMadness", but when you autoload the NPC in the Autoload hook you're changing its internal name of "Eye of Madness" with spaces. You'll have to use one or the other. (Note that whatever you put in SetDefaults is just the display name in-game and doesn't matter.)

And yes, it's only possible to create new music IDs in the next update.

It works!.. sort of. I need to work out the animation. It summons it though! Thanks!
 
The problem is that you're trying to spawn an NPC with an internal name of "EyeOfMadness", but when you autoload the NPC in the Autoload hook you're changing its internal name of "Eye of Madness" with spaces. You'll have to use one or the other. (Note that whatever you put in SetDefaults is just the display name in-game and doesn't matter.)

And yes, it's only possible to create new music IDs in the next update.


That will be possible using the ModPlayer.Hurt hook in the next update.
Yes thank you!
 
In the SetDefaults function of your ModTile, define 'animationFrameHeight' with the height of each of your animation frames including the padding. So if your animation is 48 pixels high (for example) and there is a padding of 2 pixels between each frame, you set animationFrameHeight to 50.
Then you can override the AnimateTile function inside your tile where you can increase the second parameter (called frameCounter by default) and check that against a set value of ticks. If the check returns true, then you can set the first parameter (called frame by default) to the animation frame you want to display (and reset frameCounter, ofc).
Great, that worked! Thanks a lot! :D
 
so we have to change json files to cs files?
I'm confused with the MNodLoader documentation
There's a little bit more to it. You can't just take your 'MyAwesomeWeapon.json' file and change it to 'MyAwesomeWeapon.cs'. You need to make a .cs file with the correct using statements, namespace and class name, override the SetDefaults function in your newly made ModItem or ModProjectile, etc. and input the values in the SetDefaults function by calling the reference to the actual 'item' or 'projectile', etc.
It might be a good start to look at some items in the example mod to get a better understanding of this process.

EDIT:
Just a quicky for myself. Is it already possible to make your own conversion type to use with WorldGen.Convert? Ty in advance!
 
Last edited:
Just a quicky for myself. Is it already possible to make your own conversion type to use with WorldGen.Convert? Ty in advance!
You mean like for solutions, right?

No hooks yet, but when I did it, I just copied the whole method into my ModProjectile and deleted the other stuff, then called the copied method in ModProjectile.AI:
Code:
AI()
if (projectile.owner == Main.myPlayer)
            {
                Convert((int)(projectile.position.X + (float)(projectile.width / 2)) / 16, (int)(projectile.position.Y + (float)(projectile.height / 2)) / 16, 2);
            }
Code:
        public static void Convert(int i, int j, int size = 4)
        {
            for (int k = i - size; k <= i + size; k++)
            {
                for (int l = j - size; l <= j + size; l++)
                {
                    if (WorldGen.InWorld(k, l, 1) && Math.Abs(k - i) + Math.Abs(l - j) < 6)
                    {
                        int type = (int)Main.tile[k, l].type;
                        int wall = (int)Main.tile[k, l].wall;

                        if (wall == WallID.Wood)
                        {
                            Main.tile[k, l].wall = WallID.GoldBrick;
                            WorldGen.SquareWallFrame(k, l, true);
                            NetMessage.SendTileSquare(-1, k, l, 3);
                        }

                        if (TileID.Sets.Conversion.Stone[type])
                        {
                            Main.tile[k, l].type = TileID.Gold;
                            WorldGen.SquareTileFrame(k, l, true);
                            NetMessage.SendTileSquare(-1, k, l, 3);
                        }
                        else if (type == TileID.CopperCoinPile)
                        {
                            Main.tile[k, l].type = TileID.GoldCoinPile;
                            WorldGen.SquareTileFrame(k, l, true);
                            NetMessage.SendTileSquare(-1, k, l, 3);
                        }
              }
       }
   }
}
 
There's a little bit more to it. You can't just take your 'MyAwesomeWeapon.json' file and change it to 'MyAwesomeWeapon.cs'. You need to make a .cs file with the correct using statements, namespace and class name, override the SetDefaults function in your newly made ModItem or ModProjectile, etc. and input the values in the SetDefaults function by calling the reference to the actual 'item' or 'projectile', etc.
It might be a good start to look at some items in the example mod to get a better understanding of this process.
ok, I saw the github things and its like just longer. got a few questions;
Must I have a weapon folder or just keep the Item folder with weapons inside?
say I want my weapon with a bit of coding must that weapon have 2 cs files? I learnt programming but I've yet to use my programming because still nervous.
EDIT: should most of the file (i.e ModInfo.json) remain as is or change? I dont see the changes on his github
 
Back
Top Bottom