Standalone [1.3] tModLoader - A Modding API

Discussion in 'Works-in-Progress' started by blushiemagic, Jul 7, 2015.

  1. Eldrazi

    Eldrazi Eater of Worlds

    Those tileX and tileY coordinates are in tile dimensions, not pixel/world dimensions. So you'll want to multiply them by 16 for item spawning.
     
  2. Zwip-Zwap Zapony

    Zwip-Zwap Zapony Terrarian

    Whenever ModConfig becomes a thing for tModLoader, will it work by returning the configuration value or by overwriting a variable? In other words, can multiplying a ModConfig value by 2 work something like variable = ModConfig("configValName")*2;, or will it instead have to be something like ModConfig("configValName",variable); variable*=2;? Vanilla Terraria's "Preferences" thing seems to work in the latter way, while I definitely prefer the former and see no negatives about it (while I easily see a few negatives about the latter).
     
  3. SirGouki

    SirGouki Terrarian

    There actually is an obvious problem to your first method. C# is a strongly typed language, and if you do something like ModConfig("configValName") * 2; there's no garuntee that ModConfig() is returning a correct type. Doing something like
    Code:
    float c_hp_mod = 0;  //default in case loading fails
    try
    {
        c_hp_mod = ModConfig("config HP modifier");
    }
    catch (exception e)
    {
        debug_message = e.message;
        c_hp_mod = 0;
    }
    
    c_hp_mod *= 2;
    
    would be better and allows for exception handling on incorrect typing without causing errors to the player and/or failing and crashing the game.

    edit: forgot the *2 and to actually set the hp modifier incase the config wasn't loaded :sigh:
     
  4. Quethed

    Quethed Terrarian

    Thanks again.
    (I really should not post this) I have noticed you help constantly (Three times now) and you are the only one who helps. I am offering you to join me making mods because I am that desperate for more modders.
     
    Last edited: Oct 12, 2018 at 3:54 AM
  5. Eldrazi

    Eldrazi Eater of Worlds

    Sorry mate but I'll have to decline. Good luck with your mod, though :)
     
  6. Jofairden

    Jofairden The Destroyer

    Your example is unnecessarily complex.
    Yes, you will be able to get any property you add to your config. (What's the point of it if you couldn't?)
    ExampleMod.MyConfig.MyProperty
    Example config: https://paste.mod.gg/oqujujiwiq.cs
     
  7. Quethed

    Quethed Terrarian

    I personally hate when your code is unnecessarily complex. just saying.
     
  8. Jofairden

    Jofairden The Destroyer

    What are you trying to say?
     
  9. Quethed

    Quethed Terrarian

    Nothing important, just an opinion (NOT towards the person)
     
  10. Quethed

    Quethed Terrarian

    How do you make a block get placed facing the player, without using "TileObjectData" because the game wants to divide by 0
     
  11. Horcrux

    Horcrux Terrarian

    the most unstable thing I have ever seen, but still; its amazing. Its the reason I have like 200 hours THIS MONTH on terraria
     
  12. Zwip-Zwap Zapony

    Zwip-Zwap Zapony Terrarian

    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.
     
  13. jopojelly

    jopojelly Retinazer

    That method is static, it can't call GetPacket because GetPacket is not a static method
     
  14. Deathend

    Deathend Terrarian

    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
     
  15. Noodle Cult

    Noodle Cult Terrarian

    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?
     
  16. jopojelly

    jopojelly Retinazer

    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.
     
    Gokaiji likes this.
  17. Gokaiji

    Gokaiji Terrarian

    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?