Standalone [1.3] tModLoader - A Modding API

How do I make a weapon which shoots three projectiles at once like the Subsuming Vortex from calamity mod? Pls reply, I have no idea to Code this kind of stuff.
 
Hey guys, what would be the easiest way to check if an item is currently in a player's inventory from the player class itself every frame? I see that there's a whole bunch of methods for frame updates in existence but I would specifically be looking for UpdateInventory which doesn't seem to exist in the player class. Would I simply use the UpdatePlayer method instead? Additionally, when checking to see if a player has a modded item, do you use the mod item's DisplayName when checking?

EDIT: I suppose I should clarify what I'm trying to do. I'm seeing if I can update the CompressedPotions mod to combine the buffs of the complex compressed potions so they don't take up the entire buff bar. My thought to do this was to use a ModPlayer to check if the item is in the inventory, and if it is, then manually apply the buffs. If the item is removed, the buffs would then be removed. What would be the best way of going about this?
 
Last edited:
Hi! I wanted to go back to vanilla from modded, and put the old vanilla terraria.exe file into the terraria files folder (with the modded terraria.exe file taken out but the rest of the modded stuff in it). However the file must have then made into a second modded file so now I have no vanilla terraria.exe file? Is there any way to restore files in the folder or turn the modded one back into a vanilla one or a download to the vanilla terraria.exe? If you can help, please do. Thanks! ;)
You can get all the vanilla files back from within Steam. From your library, right click the game > Properties > Local Files, then click Verify Integrity of Game Files to get the Vanilla game back.

When I create a server with tModLoaderServer I can't join because it says ''you are not using the same version as this server'', i've tried to join with the newest 1.3.5.3 update and also the 1.3..5.2 version, neither of them work. help?
Sounds like either you are trying to join a vanilla server, or a tModLoader server that hasn't been updated yet. You can't join a vanilla server with tModLoader, but if it's a tModLoader server, you'll have to find out which version of tModLoader (not Terraria) it's running first.

Hey guys, what would be the easiest way to check if an item is currently in a player's inventory from the player class itself every frame? I see that there's a whole bunch of methods for frame updates in existence but I would specifically be looking for UpdateInventory which doesn't seem to exist in the player class. Would I simply use the UpdatePlayer method instead? Additionally, when checking to see if a player has a modded item, do you use the mod item's DisplayName when checking?

EDIT: I suppose I should clarify what I'm trying to do. I'm seeing if I can update the CompressedPotions mod to combine the buffs of the complex compressed potions so they don't take up the entire buff bar. My thought to do this was to use a ModPlayer to check if the item is in the inventory, and if it is, then manually apply the buffs. If the item is removed, the buffs would then be removed. What would be the best way of going about this?
Well, I haven't tested this, but I'd be surprised if this didn't work.
Code:
for (int i = 0; i < player.inventory.Length; i++)//for every item in my inventory
{
    if (player.inventory[1].type == mod.ItemType("nameOfItemsClass"))//if this item is the one I'm looking for
    {
        player.AddBuff(1234, 2); //apply the buff for one frame -- replace 1234 with the buff you want to apply
        break;
    }
}
I don't think that the player has an UpdatePlayer hook, but PerUpdate or PostUpdate should do the trick. Also, if the item is from a different mod, then you can't use mod.ItemType, you instead need to create a reference to the other mod. I'm not sure exactly how this is done, but I'm sure someone on here does.
 
Well, I haven't tested this, but I'd be surprised if this didn't work.
Code:
for (int i = 0; i < player.inventory.Length; i++)//for every item in my inventory
{
    if (player.inventory[1].type == mod.ItemType("nameOfItemsClass"))//if this item is the one I'm looking for
    {
        player.AddBuff(1234, 2); //apply the buff for one frame -- replace 1234 with the buff you want to apply
        break;
    }
}
I don't think that the player has an UpdatePlayer hook, but PerUpdate or PostUpdate should do the trick. Also, if the item is from a different mod, then you can't use mod.ItemType, you instead need to create a reference to the other mod. I'm not sure exactly how this is done, but I'm sure someone on here does.

Thanks for that! I think that should work.

As of this point, I was only going to use my own mod's items, so that won't be a problem at all.

I was actually looking at the player class itself and it appears as if the player's attributes are all reset every single frame, and then buffs are re-applied as the player class updates (wtf?). If that's true, then I assume I have to re-apply the buffs at every frame?
 
Would it be possible to make it automatically update the modloader? I'm afraid of messing up my modded world files cuz I have no idea how to update it. :/
 
Would it be possible to make it automatically update the modloader? I'm afraid of messing up my modded world files cuz I have no idea how to update it. :/
Go to steam, right click terraria in the library, go to properties, and find "integrity of local files" or whatever it's called.
Click that. Terraria will return to normal, but the memory/files are still there, they are just not in use.
Now download the new version and run the installer, and there ya go! if you go on it, your stuff's still there
 
Um...I open terraria, but nothing appears. so i check the Task Manager. and it says its open.... but.. i cant open it..??
basically its open but i dont see it.


NEVERMIND LOL IT OPENED AFTER 5 YEARS
 
Thanks for that! I think that should work.

As of this point, I was only going to use my own mod's items, so that won't be a problem at all.

I was actually looking at the player class itself and it appears as if the player's attributes are all reset every single frame, and then buffs are re-applied as the player class updates (wtf?). If that's true, then I assume I have to re-apply the buffs at every frame?
Any time.

The players attributes are reset and so are the effects from the buffs, but the buffs themselves don't need to be reapplied. The effects of a buff are automatically reapplied each frame. It may seem weird, but it's that way so that if you have multiple buffs that affect one stat, a buff can be removed and that stat will revert to how it should be.

Would it be possible to make it automatically update the modloader? I'm afraid of messing up my modded world files cuz I have no idea how to update it. :/
The safest way is to create a manual backup of your players and worlds before you update.
 
Failed to resolve assembly: 'Terraria, Version=1.3.5.1, Culture=neutral, PublicKeyToken=null'
at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
at Mono.Cecil.TypeReference.Resolve()
at Mono.Cecil.Mixin.CheckedResolve(TypeReference self)
at Mono.Cecil.SignatureReader.ReadCustomAttributeEnum(TypeReference enum_type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeElementValue(TypeReference type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeElement(TypeReference type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeFixedArrayArgument(ArrayType type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeFixedArgument(TypeReference type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeConstructorArguments(CustomAttribute attribute, Collection`1 parameters)
at Mono.Cecil.MetadataReader.ReadCustomAttributeSignature(CustomAttribute attribute)
at Mono.Cecil.CustomAttribute.<Resolve>b__34_0(CustomAttribute attribute, MetadataReader reader)
at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
at Mono.Cecil.CustomAttribute.Resolve()
at Mono.Cecil.CustomAttribute.get_ConstructorArguments()
at Mono.Cecil.ImmediateModuleReader.ReadCustomAttributes(ICustomAttributeProvider provider)
at Mono.Cecil.ImmediateModuleReader.ReadType(TypeDefinition type)
at Mono.Cecil.ImmediateModuleReader.ReadTypes(Collection`1 types)
at Mono.Cecil.ImmediateModuleReader.ReadModule(ModuleDefinition module)
at Mono.Cecil.ModuleWriter.WriteModuleTo(ModuleDefinition module, Stream stream, WriterParameters parameters)
at Mono.Cecil.ModuleDefinition.Write(Stream stream, WriterParameters parameters)
at Terraria.ModLoader.AssemblyManager.LoadedMod.EncapsulateReferences(Byte[] code)
at Terraria.ModLoader.AssemblyManager.LoadedMod.LoadAssemblies()
at Terraria.ModLoader.AssemblyManager.InstantiateMods(List`1 modsToLoad)

It may be important to note that I've tried to reload multiple mods, and none of them work. (I just got the new TModLoader update as well so it could be a bug)
 
Failed to resolve assembly: 'Terraria, Version=1.3.5.1, Culture=neutral, PublicKeyToken=null'
at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
at Mono.Cecil.TypeReference.Resolve()
at Mono.Cecil.Mixin.CheckedResolve(TypeReference self)
at Mono.Cecil.SignatureReader.ReadCustomAttributeEnum(TypeReference enum_type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeElementValue(TypeReference type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeElement(TypeReference type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeFixedArrayArgument(ArrayType type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeFixedArgument(TypeReference type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeConstructorArguments(CustomAttribute attribute, Collection`1 parameters)
at Mono.Cecil.MetadataReader.ReadCustomAttributeSignature(CustomAttribute attribute)
at Mono.Cecil.CustomAttribute.<Resolve>b__34_0(CustomAttribute attribute, MetadataReader reader)
at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
at Mono.Cecil.CustomAttribute.Resolve()
at Mono.Cecil.CustomAttribute.get_ConstructorArguments()
at Mono.Cecil.ImmediateModuleReader.ReadCustomAttributes(ICustomAttributeProvider provider)
at Mono.Cecil.ImmediateModuleReader.ReadType(TypeDefinition type)
at Mono.Cecil.ImmediateModuleReader.ReadTypes(Collection`1 types)
at Mono.Cecil.ImmediateModuleReader.ReadModule(ModuleDefinition module)
at Mono.Cecil.ModuleWriter.WriteModuleTo(ModuleDefinition module, Stream stream, WriterParameters parameters)
at Mono.Cecil.ModuleDefinition.Write(Stream stream, WriterParameters parameters)
at Terraria.ModLoader.AssemblyManager.LoadedMod.EncapsulateReferences(Byte[] code)
at Terraria.ModLoader.AssemblyManager.LoadedMod.LoadAssemblies()
at Terraria.ModLoader.AssemblyManager.InstantiateMods(List`1 modsToLoad)

It may be important to note that I've tried to reload multiple mods, and none of them work. (I just got the new TModLoader update as well so it could be a bug)
Rename the exe to Terraia.exe
 
Any time.

The players attributes are reset and so are the effects from the buffs, but the buffs themselves don't need to be reapplied. The effects of a buff are automatically reapplied each frame. It may seem weird, but it's that way so that if you have multiple buffs that affect one stat, a buff can be removed and that stat will revert to how it should be.

What if it's a manual buff? For example, in the case of the compressed potions mod, you may have an item that adds wrath, rage, endurance, etc. It's simple enough to just say AddBuff(whatever), but that would create an individual buff that takes up a buff slot for each effect. What I'm looking to do is combine the effects, so I imagine I would need to manually apply each effect that I want the buff to include.

It's possible that I'm just not really understanding how the mod buff system works. If you have any further insights into it, that would be helpful.
 
Hi everyone. So I want to make an armor set, that gives lifesteal on enemy hits as the set bonus. Anyone knows the code for it?
I know that the armor needs to have some stuff in the mod.cs or modplayer.cs
And that the lifesteal has to be an OnHitNPC(); dont know a thing past that tho :D
 
Last edited:
Hi everyone. so i`m trying to make a custom block in the game and heres the code i have so far:

using Terraria.ModLoader;
using Terraria.ID;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace novahand.Tiles
{
public class starshard : ModTile
{
public override void SetDefaults()
{
Main.tileSolid[Type] = true;
Main.tileMergeDirt[Type] = true;
Main.tileLighted[Type] = true;
Main.tileBlockLight[Type] = true;

drop = mod.ItemType("starshard");
ModTranslation name = CreateMapEntryName();
name.SetDefault("starshard");
AddMapEntry(new Color(255, 255, 255));
minPick = 59;
}
public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b)
{
r = 0.75f;
g = 0.25f;
b = 0.5f;
}
}
}

its pretty much an identical copy of the code from this tutorial: https://github.com/FoolsLynx/tutorial-mod/blob/master/Tiles/TutorialOreTile.cs
but whenever i build and reload, i get an error that says this:
c:\Users\danny\Documents\My Games\Terraria\ModLoader\Mod Sources\novahand\Tiles\starshard.cs(12,13)(13,13)(14,13)(15,13) : error CS0103: The name 'Main' does not exist in the current context
i know where the problem is, but i cant find what the problem is. there should be nothing wrong with the main part, because its exactly the same as the part in the tutorial. maybe the tutorial is outdated. maybe i need to set something else up or download something.
either way i don`t know what to do so please send help.
Thanks in advance to anyone that helps.
 
Hi everyone. so i`m trying to make a custom block in the game and heres the code i have so far:

using Terraria.ModLoader;
using Terraria.ID;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace novahand.Tiles
{
public class starshard : ModTile
{
public override void SetDefaults()
{
Main.tileSolid[Type] = true;
Main.tileMergeDirt[Type] = true;
Main.tileLighted[Type] = true;
Main.tileBlockLight[Type] = true;

drop = mod.ItemType("starshard");
ModTranslation name = CreateMapEntryName();
name.SetDefault("starshard");
AddMapEntry(new Color(255, 255, 255));
minPick = 59;
}
public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b)
{
r = 0.75f;
g = 0.25f;
b = 0.5f;
}
}
}

its pretty much an identical copy of the code from this tutorial: https://github.com/FoolsLynx/tutorial-mod/blob/master/Tiles/TutorialOreTile.cs
but whenever i build and reload, i get an error that says this:
c:\Users\danny\Documents\My Games\Terraria\ModLoader\Mod Sources\novahand\Tiles\starshard.cs(12,13)(13,13)(14,13)(15,13) : error CS0103: The name 'Main' does not exist in the current context
i know where the problem is, but i cant find what the problem is. there should be nothing wrong with the main part, because its exactly the same as the part in the tutorial. maybe the tutorial is outdated. maybe i need to set something else up or download something.
either way i don`t know what to do so please send help.
Thanks in advance to anyone that helps.
Main is in the Terraria namespace, so I think you'll need "using Terraria;" up top.
 
Would it be possible to make it automatically update the modloader? I'm afraid of messing up my modded world files cuz I have no idea how to update it. :/
Updating tML does not mess with your player and world saves.
[doublepost=1514201230,1514201168][/doublepost]
I feel like they should make it so that like how they have the mod browser, they should make it so there is a modPACK browser
Good idea and suggested multiple times.
Somewhere in the future the browser will be expanded more, no guarantees.
[doublepost=1514201377][/doublepost]
What can I do if terraria crashes on my pc when I have mods in the folder, but when I delete them, It loads perfectly fine. Anyway to fix this problem?
There is a mod with load issues that crashes the game. Hold left shift while loading to skip the mod loading, then load mods one by one to see which is causing issues.
 
What if it's a manual buff? For example, in the case of the compressed potions mod, you may have an item that adds wrath, rage, endurance, etc. It's simple enough to just say AddBuff(whatever), but that would create an individual buff that takes up a buff slot for each effect. What I'm looking to do is combine the effects, so I imagine I would need to manually apply each effect that I want the buff to include.

It's possible that I'm just not really understanding how the mod buff system works. If you have any further insights into it, that would be helpful.
Yeah, I'd say that you'd need to copy all of the effects from the individual buffs to the combined buff. It would probably be worth having the combined buff dispel all of the separate buffs on application so that you can't get twice the effect.
 
I was playing multi with my friend like 6 months ago. It was a little bit laggy, a little bit slow-motion for me sometimes, but playable. Now we are playing again, another playthrough with more mods. Now its lagging as hell, some items that should not lag the game are causing the lag. Also, if there is more than :red:ing 1 mob on the screen i get the slowmotion even if i play terraria on lowest video setting with frameskip set to subtle. My friend wants to play summoner but he can't because if he spawns minions server is going crazy and lags A LOT which makes that we can't pickup items, we can't see where is boss or even if he is alive or dead, we can't see even if we are dead or alive :O. Lags and slowmotion arealso happening alot while we are fighting bosses.

We are playing on newest tModLoader and compatibile mods with it.
Mod list:
AlchemistNPC
Antiaris
AutoTrash
Bismuth
Bluemagic
BossChecklist
Builder's Toolbox
CalamityMod
CrystiliumMod
DualWielding
Fargowitas
FKBossHealthBar
HerosMod
imkSushiMod
ItemChecklist
JoostMod
LongbowsFTW
MagicStorage
MaxStackPlux
MoreAccesssories
RecipeBrowser
ReducedGrinding
SacredTools
SpiritMod
Terranova
ThoriumMod
VeryShortRespawnTime
WeaponOut
WingSlotUpgraded
WMITF

My PC Specs:
CPU- Intel i5 4460 3.2GHz (Terraria+ Terraria console server are not even consuming 100% of the CPU)
GPU- Radeon RX Sapphire 480 4GB
RAM- 8GB (Terraria+ Terraria console server are not even consuming 100% of the RAM)
OS- Windows 10
SSD 256GB
HDD 500GB - Here is terraria and whole steam

I also tried hosting with HOST AND PLAY button on terraria, makes no difference, or makes it even worse i think.
Is there any difference anctually ? :O

I would be glad if someone could help, or even reply why this is happening :D

TY ! I will always love tModLoader and all creators that are developing it !
 
Back
Top Bottom