Standalone [1.3] tModLoader - A Modding API

How do you make a block get placed facing the player, without using "TileObjectData" because the game wants to divide by 0
 
the most unstable thing I have ever seen, but still; its amazing. Its the reason I have like 200 hours THIS MONTH on terraria
 
Is there a tutorial/guide for custom multiplayer synchronization?

When I try to compile a mod that I'm working on, tModLoader says "...\RegenFromBosses_NetSynch.cs(21,21) : error CS0120: An object reference is required for the non-static field, method, or property 'Mod.GetPacket(int)' ", however when I compile ExampleMod (which also has custom synchronization), no such error occurs, which means that the error is on my part somehow.

This is the current RegenFromBosses_NetSynch.cs file, minus two methods to keep the post shorter:
Code:
using System.IO;
using System.Linq; //For C#6 compiling
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;

//This file is all about synchronizing the regenLife variable in multiplayer
//It has a function that sends regenLife from the server to all clients (NetSendRegen()),
//and a function that lets clients ask the server to do the above (NetGetRegen())

//Note that despite what this file is for, this mod's multiplayer synchronization compatibility is still completely unknown at the time

namespace RegenFromBosses
{
    public partial class RegenFromBosses : Mod
    {
        public static void NetSendRegen() //Send the current life regeneration value from the server to all clients
        {
            if (Main.netMode==NetmodeID.Server) //If hosting the server...
            {
/*ERROR*/       ModPacket packet=GetPacket(); //...create a new network packet...
                packet.Write((byte)PacketType.ServerSendRegenToClient); //...write what the packet is for...
                packet.Write(regenLife); //...write the current life regeneration value...
                packet.Send(); //...and send the packet
            }
        }
        //public static void NetGetRegen() { ... } //Ask the server to transmit the current life regeneration value
        //public override void HandlePacket(BinaryReader reader,int whoAmI) { ... } //Do stuff with network packets
    }
    enum PacketType : byte //Multiplayer synchronization network packet types
    {
        ServerSendRegenToClient,     //Used when the server sends the current life regeneration value to a client
        ClientRequestRegenFromServer //Used when a client requests the current life regeneration value from the server
    }
}

Again, ExampleMod doesn't have this issue. Even if I actually copy some similar synchronization code that works in ExampleMod (or other open-source tModLoader mods) and paste it in this place, along with all of the "using" directives, it still errors when compiling.

What annoys me and made me make this post isn't that I get an error, but that I get an error when doing the exact same thing as something else that does not get an error.
 
Is there a tutorial/guide for custom multiplayer synchronization?

When I try to compile a mod that I'm working on, tModLoader says "...\RegenFromBosses_NetSynch.cs(21,21) : error CS0120: An object reference is required for the non-static field, method, or property 'Mod.GetPacket(int)' ", however when I compile ExampleMod (which also has custom synchronization), no such error occurs, which means that the error is on my part somehow.

This is the current RegenFromBosses_NetSynch.cs file, minus two methods to keep the post shorter:
Code:
using System.IO;
using System.Linq; //For C#6 compiling
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;

//This file is all about synchronizing the regenLife variable in multiplayer
//It has a function that sends regenLife from the server to all clients (NetSendRegen()),
//and a function that lets clients ask the server to do the above (NetGetRegen())

//Note that despite what this file is for, this mod's multiplayer synchronization compatibility is still completely unknown at the time

namespace RegenFromBosses
{
    public partial class RegenFromBosses : Mod
    {
        public static void NetSendRegen() //Send the current life regeneration value from the server to all clients
        {
            if (Main.netMode==NetmodeID.Server) //If hosting the server...
            {
/*ERROR*/       ModPacket packet=GetPacket(); //...create a new network packet...
                packet.Write((byte)PacketType.ServerSendRegenToClient); //...write what the packet is for...
                packet.Write(regenLife); //...write the current life regeneration value...
                packet.Send(); //...and send the packet
            }
        }
        //public static void NetGetRegen() { ... } //Ask the server to transmit the current life regeneration value
        //public override void HandlePacket(BinaryReader reader,int whoAmI) { ... } //Do stuff with network packets
    }
    enum PacketType : byte //Multiplayer synchronization network packet types
    {
        ServerSendRegenToClient,     //Used when the server sends the current life regeneration value to a client
        ClientRequestRegenFromServer //Used when a client requests the current life regeneration value from the server
    }
}

Again, ExampleMod doesn't have this issue. Even if I actually copy some similar synchronization code that works in ExampleMod (or other open-source tModLoader mods) and paste it in this place, along with all of the "using" directives, it still errors when compiling.

What annoys me and made me make this post isn't that I get an error, but that I get an error when doing the exact same thing as something else that does not get an error.
That method is static, it can't call GetPacket because GetPacket is not a static method
 
I don´t know if this is the right place to ask but, some of my modded biomes have vanished, for example, in the place were the Abyss is suposed to be, there´s just a giant crater. I´ve reinstalled my mods, tmod, and my worlds several times, yet the craters are still there. Also, Whenever i´m creating a world that has a modded biome in it, when it gets to the part of creating the biome, Terraria crashes. Please someone help me out!
if you are using calamity + overhaul they lately dont go well in world creation, if you want to create a world with calamity remove overhaul for the world creation and add it later, also i think spirit mod is having some incompatibilities too
worldgen previewer also crashes with calamity world gen, and since calamity makes worlds a little bigger i recomend using large world enabler to remove some issues like hell side of map being distorted
 
Hiya,
I've downloaded the Windows version but the application in my files is called 'tModLoaderMac' and wont run on my PC. When I troubleshoot it says its an incompatible version. So how do I get the Windows version?
 
Hiya,
I've downloaded the Windows version but the application in my files is called 'tModLoaderMac' and wont run on my PC. When I troubleshoot it says its an incompatible version. So how do I get the Windows version?
tModLoaderMac is a file in the ModCompile folder within the downloaded zip file. You don't run that file, you run Terraria.exe from the zip. Read the readme.txt.
 
in the new version i have 2 problems with 2 mods ,the thorium and calamity with this mods when i select a character the terraria just crash ,and i cant play alone ,anyone can help me pls?
 
Is it possible to override Terraria.Main.checkHalloween() and Terraria.Main.checkXMas()? (If not, I'd like to request that to be possible.) I can't find them in the "patch" things of tModLoader's GitHub page, and I'm trying to make a mod which's sole purpose is to do stuff in those methods (while that mod currently says that those methods can't be overriden).

Edit: Or perhaps instead of an overrideable checkHalloween() and checkXMas(), maybe some kind of new tModLoader-specific checkDate() that runs when checkHalloween() and checkXMas() usually would, or something specifically for when night passes to day naturally (and vice-versa)? Either thing would be helpful for this mod in any case.
 
Last edited:
Just out of curiosity, the ultimate apocalypse guys claim to have a 64bit Tmodloader. Does any one here know if it's possible? Since terraria it self is 32 bit and all.
 
Hola, tengo un problema con el Terraria, el Terraria funciona correctamente pero cuando extraigo los archivos de Modloader v0.10.1.5 me sale este error Ayuda
 

Attachments

  • Error terraria.PNG
    Error terraria.PNG
    10.5 KB · Views: 203
Does tModLoader crash on exit for anyone else? Sorry if it's been reported already. Quite a few posts to go through. Here's my crash log. It even happens with no mods enabled.

Silently Caught Exception: Object reference not set to an instance of an object. at Terraria.ModLoader.IO.ItemIO.Save(Item item) at Terraria.ModLoader.ModCompile.<>c.<ActivateExceptionReporting>b__15_0(Object sender, FirstChanceExceptionEventArgs exceptionArgs)
at Terraria.ModLoader.IO.ItemIO.Save(Item item)
at Terraria.ModLoader.IO.PlayerIO.SaveInventory(Item[] inv)
at Terraria.ModLoader.IO.WorldIO.SaveChests()
at Terraria.ModLoader.IO.WorldIO.Save(String path, Boolean isCloudSave)
at Terraria.IO.WorldFile.saveWorld(Boolean useCloudSaving, Boolean resetTime)
at Terraria.WorldGen.saveAndPlayCallBack(Object threadContext)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

It also crashes at random. No cause in particular.

I should specify that this is a custom TerraCustom world I imported from Vanilla into tModLoader. I'll bet that would make a difference.
 
Last edited:
Looking to make a mod, but I'm really not the best at spriting... Anyone who can sprite I would love to talk to! I have a few ideas, but if you have a sprite and details of what you want something to do, I'd be more than happy to implament them. In the tooltip would be the name of the person who sprited the item(s) (Unless you don't want that, and for it to be anonomyous, or have a fake name/Terraria name/ whatever you really want I don't care...).
you can ask me about this on this forum (which I'll be checking periodically), or as a conversation, or email me! My email is: [email protected]
 
Back
Top Bottom