tModLoader Official tModLoader Help Thread

Hi, I seem to have trouble replicating the paladin's hammer infinite piercing effect.

After a little browsing through terraria's source code, i understand that all boomerangs have their velocity reversed EXCEPT for type == 301, which is paladin's hammer.

However, despite my custom boomerang having the same aitype as paladin's hammer, its velocity is reversed upon doing damage like a normal boomerang.

Thanks in advance for any help!

Edit: I have solved the problem myself, for anyone who is interested; setting projectile.type = 301; setting projectile.texture; and getalpha(); within public override void AI() solves this problem.
 
Last edited:
I created a Animated tile ,and want to play some sound effect in specific frames.
The following is the code I tried,
Code:
public override void AnimateTile(ref int frame, ref int frameCounter)
        {
            frameCounter++;
            if (frameCounter > 16)
            {
                frameCounter = 0;
                frame++;
                if (frame == 3) 
                {
                    Main.PlaySound(mod.GetSoundSlot(SoundType.Item, "Sounds/Item/soundeffect"));
                  
                }
                if (frame > 3) 
                {
                    frame = 0;
                }
            }
        }
But the sound effect keeps playing even in the title screen.
Maybe I should play the sound effect in the position of every tile.
Like this
Main.PlaySound(mod.GetSoundSlot(SoundType.Item, "Sounds/Item/soundeffect",x,y));

But I don`t know how to get the x,y parameters.
Can anyone help me?
 
I'm trying to mod in a shotgun
and it's giving me the error "error CS0234: the type or namespace 'Items' does not exist in the namespace 'MOD' (are you missing an assembly reference?)
I've tried all the fixes that I've seen on the wiki but none work, this is my code:

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

namespace Mod.Items.NewItems.legend
{
public class ShotGun : ModItem
{
public override void SetDefaults()
{
{
DisplayName.SetDefault("Legend of Acrius");
Tooltip.SetDefault("A weapon built by beings bent on war");

}

item.damage = 600;
item.ranged = true;
item.width = 40;
item.height = 20;

item.useTime = 50;
item.useAnimation = 38;
item.useStyle = 5;
item.noMelee = true; //so the item's animation doesn't do damage
item.knockBack = 7;
item.value = 10000;
item.rare = 2;

item.autoReuse = false;
item.shoot = 10; //idk why but all the guns in the vanilla source have this
item.shootSpeed = 14f;
item.useAmmo = ProjectileID.Bullet;
}

public override void AddRecipes() //How to craft this gun
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.OnyxBlaster, 50); //you need 1 DirtBlock
recipe.AddTile(TileID.WorkBenches); //at work bench
recipe.SetResult(this);
recipe.AddRecipe();

}

public static Vector2[] randomSpread(float speedX, float speedY, int angle, int num)
{
var posArray = new Vector2[num];
float spread = (float)(angle * 0.0174532925);
float baseSpeed = (float)System.Math.Sqrt(speedX * speedX + speedY * speedY);
double baseAngle = System.Math.Atan2(speedX, speedY);
double randomAngle;
for (int i = 0; i < num; ++i)
{
randomAngle = baseAngle + (Main.rand.NextFloat() - 0.5f) * spread;
posArray = new Vector2(baseSpeed * (float)System.Math.Sin(randomAngle), baseSpeed * (float)System.Math.Cos(randomAngle));
}
return (Vector2[])posArray;
}

public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
Vector2[] speeds = randomSpread(speedX, speedY, 8, 6);
for (int i = 0; i < 5; ++i)
{
Projectile.NewProjectile(position.X, position.Y, speeds.X, speeds.Y, type, damage, knockBack, player.whoAmI);
}
return false;
}
}
};
 
I'm trying to mod in a shotgun
and it's giving me the error "error CS0234: the type or namespace 'Items' does not exist in the namespace 'MOD' (are you missing an assembly reference?)
I've tried all the fixes that I've seen on the wiki but none work, this is my code:

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

namespace Mod.Items.NewItems.legend
{
    public class ShotGun : ModItem
    {
        public override void SetDefaults()
        {
            {
                DisplayName.SetDefault("Legend of Acrius");
                Tooltip.SetDefault("A weapon built by beings bent on war");
             
            }

            item.damage = 600;
            item.ranged = true;
            item.width = 40;
            item.height = 20;

            item.useTime = 50;
            item.useAnimation = 38;
            item.useStyle = 5;
            item.noMelee = true; //so the item's animation doesn't do damage
            item.knockBack = 7;
            item.value = 10000;
            item.rare = 2;
         
            item.autoReuse = false;
            item.shoot = 10; //idk why but all the guns in the vanilla source have this
            item.shootSpeed = 14f;
            item.useAmmo = ProjectileID.Bullet;
        }

        public override void AddRecipes()  //How to craft this gun
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.OnyxBlaster, 50);   //you need 1 DirtBlock
            recipe.AddTile(TileID.WorkBenches);   //at work bench
            recipe.SetResult(this);
            recipe.AddRecipe();

        }

        public static Vector2[] randomSpread(float speedX, float speedY, int angle, int num)
        {
            var posArray = new Vector2[num];
            float spread = (float)(angle * 0.0174532925);
            float baseSpeed = (float)System.Math.Sqrt(speedX * speedX + speedY * speedY);
            double baseAngle = System.Math.Atan2(speedX, speedY);
            double randomAngle;
            for (int i = 0; i < num; ++i)
            {
                randomAngle = baseAngle + (Main.rand.NextFloat() - 0.5f) * spread;
                posArray[I] = new Vector2(baseSpeed * (float)System.Math.Sin(randomAngle), baseSpeed * (float)System.Math.Cos(randomAngle));
            }
            return (Vector2[])posArray;
        }

        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            Vector2[] speeds = randomSpread(speedX, speedY, 8, 6);
            for (int i = 0; i < 5; ++i)
            {
                Projectile.NewProjectile(position.X, position.Y, speeds[I].X, speeds[I].Y, type, damage, knockBack, player.whoAmI);
            }
            return false;
        }
    }
};

Try replacing 'Mod' with the name of your mod's folder.
 
XFzCBnp.png

last update: 10th of July, 2017
687474703a2f2f692e696d6775722e636f6d2f6b6463524f59502e706e67

Table of Contents
  1. Table of Contents
  2. Introduction
  3. What is tModLoader?
  4. Help
    1. Useful locations and paths
    2. Frequently asked questions (FAQ)
  5. Text-Editors and IDEs
    1. Text-editors
    2. IDEs
  6. Info (includes other useful guides/tutorials and mod specific wikis)
687474703a2f2f692e696d6775722e636f6d2f6b6463524f59502e706e67


Introduction

Hello and welcome to the tModLoader's official help thread! T
his thread was made to take some strain off the original thread, and is just an alternative place to get help. Also this place will house links to helpful guides and tutorials, as well as snippets of code with explanation, resources.. and so forth.

Back to top
687474703a2f2f692e696d6775722e636f6d2f6b6463524f59502e706e67


What is tModLoader?

tModLoader is like an API such as the old tConfig and discontinued tAPI. It is literally a mod to make mods. As a developer, you might already know that the Terraria src (source-code) is difficult to deal with for a modder. tModLoader aims to make it far easier for you to create your mod, as well as share your mod for others to use. Traditionally, stand-alone mods are created. An upside to this way of modding is that you can literally do whatever you want to without being limited to an API's possibilities. A downside is that stand-alone mods usually aren't compatible with each other, as well as the developer(s) needing to know the Terraria source-code.

0lopBGN.png

You can find all tModLoader methods, fields and properties in the official documentation which is on GitHub. (the new and improved documentation is here) Two other really useful sites are tConfig wikipedia or the tAPI documentation. These sites are outdated but still contain a lot of useful information. If you need help immediately, I suggest you join our Discord Channel. We're currently closing in to the 5000 members mark. There are always people around to help you!

Back to top
687474703a2f2f692e696d6775722e636f6d2f6b6463524f59502e706e67

Useful locations and paths

Below you can find folder locations which mind come in handy when using tModLoader. Only default paths are listed.

XNA .dll location / files
If you're on windows, navigate to C:\Windows\Microsoft.NET\assembly\GAC_32\
You can find the folders for the XNA framework in there. Alternatively, you could paste this search string in the path bar:
Code:
search-ms:displayname=Search%20Results%20in%20GAC_32&crumb=filename%3A~<Microsoft.XNA%20OR%20System.Generic.String%3AMicrosoft.XNA&crumb=fileextension%3A~<Microsoft.XNA*.dll%20filename%3A~<Microsoft.XNA*.dll%20OR%20System.Generic.String%3AMicrosoft.XNA*.dll&crumb=location:C%3A%5CWindows%5CMicrosoft.NET%5Cassembly%5CGAC_32
COPY these files, you should not move them or cut + paste.

Default Terraria location
Here the main files of Terraria are stored. These locations are default locations chosen during the installation of the Terraria game.

Mac: Library/Application Support/Steam/steamapps/common/Terraria/Terraria.app/Contents/MacOS
Linux: .local/share/Steam/steamapps/common/Terraria
Windows: C:\Program Files (x86)\Steam\steamapps\common\Terraria​

GoG Terraria location
Here the main files of Terraria are stored. These locations are default locations chosen during the installation of the Terraria game.

Mac: ??
Linux: ??
Windows: C:\GOG Games\Terraria​

Default Terraria documents location

Mac: /Users/account/Library/Application Support/Terraria
Linux: ~/.local/share/Terraria OR $XDG_DATA_HOME/Terraria
Windows: %UserProfile%\Documents\My Games\Terraria​

Default tModLoader documents location

Mac: /Users/account/Library/Application Support/Terraria/ModLoader
Linux: ~/.local/share/Terraria/ModLoader OR $XDG_DATA_HOME/Terraria/ModLoader
Windows: %UserProfile%\Documents\My Games\Terraria\ModLoader​

Default tModLoader mods' src folder
Here the sourcecode of mods are stored in their own folders. Usually you won't have this and is only available for the particular mods' developer(s).

Mac: /Users/account/Library/Application Support/Terraria/ModLoader/Mod Sources
Linux: ~/.local/share/Terraria/ModLoader/Mod Sources OR $XDG_DATA_HOME/Terraria/ModLoader/Mod Sources
Windows: %UserProfile%\Documents\My Games\Terraria\ModLoader\Mod Sources​

Default tModLoader 'mods' folder
Here, .tmod and .enabled files are stored. These files literally store the contents of a mod and if the mod is enabled in-game.

Mac: /Users/account/Library/Application Support/Terraria/ModLoader/Mods
Linux: ~/.local/share/Terraria/ModLoader/Mods OR $XDG_DATA_HOME/Terraria/ModLoader/Mods
Windows: %UserProfile%\Documents\My Games\Terraria\ModLoader\Mods​

Back to top
687474703a2f2f692e696d6775722e636f6d2f6b6463524f59502e706e67

Frequently Asked Questions (FAQ)

Remember you should ALWAYS show us the error(s) you've received when asking for help. Without showing us errors or code, we literally cannot help you with your troubles.
For actual How-To's/Guides, visit my next post in this thread.

"Why did I lose all my characters and worlds upon installation of tModLoader?"
"How do I make characters and worlds for tModLoader?"

tModLoader uses its own folders for storing worlds and characters. This makes sure your vanilla files are nicely seperated from tModLoader modded files. tModLoader worlds aren't compatible with vanilla anyway, vanilla worlds are compatible with tModLoader though. Navigate to the main Terraria documents path, which you can find above, and copy your vanilla world files and character files into the ModLoader/Worlds and ModLoader/Players paths.


"Can I copy my old json code to work with tModLoader?"
No, as of yet json is not supported and tModLoader solely uses c#.

"What is the autoload property in tModLoader?"
The autoload property, found in the SetModInfo() method, is a property which will automatically load your mods' files. If you do not set AutoLoad to true you'll need to load your files manually in the Load() method.

"How do I even install tModLoader?"
tModLoader comes packaged in a .zip file, which you can unzip using an unzipper such as WinRAR. All you need to do is navigate to the default Terraria location, which you can find above, make a backup of your origional files and copy the contents of the .zip file. Let the files overwrite when asked.

"How can I revert to vanilla Terraria?"
You should've made a backup of all files you had to replace when installing tModLoader. These include, but are not limited to: FNA.dll, MP3Sharp.dll, Terraria.exe
If you have, restore these files. If you haven't, you can delete these files and have Steam verify the integrity of game cache. (this'll redownload the vanilla files)
You should now have vanilla Terraria again.

"Which text-editor or IDE should I use?"

I've created a special section below for text-editors and IDE choices.

"Why are people reporting my mod doesn't work in multiplayer?"
This is likely due to your mod having some code that isn't optimized for multiplayer. This can be quite a difficult thing to do.
In case your users get errors, have them post them to your thread as well as the tML thread.
(please keep in mind tML is WIP, so MP is WIP too!)


"What is all the fuzz about converting to tile positions?"
A nice clear explanation by @Eldrazi:

"How can I create X thing? (your own item, npc, projectile etc.)"

Before you ask any questions, you should take a close look at the ExampleMod first. This mod contains almost everything that's possible, but of course the possibilities aren't limited to this mod's contents. Remember that you should create your files using the c# (c-sharp) language.

"Why can't I build / rebuild mods on Mac/Linux?"
If you want to build mods on mac/linux, you'll need to compile the dll file outside of tModLoader, then set precompile to true in build.txt

"Why are chests suddenly missing items?"
This should be fixed by now.

"How does the 'velocity' system work in Terraria?"

Go below to the 'Snippets' part, and look for a snippet on this subject.

Back to top
687474703a2f2f692e696d6775722e636f6d2f6b6463524f59502e706e67

Text-Editors and IDEs

Are you having trouble choosing your text-editor and/or IDE? Look no further!
I also have a tutorial on how to setup your mod in Microsoft Visual Studio!

Text-editors
  • Sublime text
  • Notepad
    • Major improvement to the regular notepad. Has features such as syntax highlighting, printing and mass replacement (with regex support)
    • http://notepad-plus-plus.org/
  • Vim
    • Vim is a highly configurable text editor built to make creating and changing any kind of text very efficient. It is included as "vi" with most UNIX systems and with Apple OS X.
    • http://www.vim.org/
  • Atom
    • Atom is a text editor that's modern, approachable, yet hackable to the core—a tool you can customize to do anything but also use productively without ever touching a config file. Created by Github.
    • https://atom.io/
  • Brackets
    • With focused visual tools and preprocessor support, Brackets is a modern text editor that makes it easy to design in the browser. It's crafted from the ground up for web designers and front-end developers. So, this editor is mostly for web developers, but could still be used for modding too if you like it enough.
    • http://brackets.io/
  • Visual Studio Code
    • Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications. Made by Microsoft. This editor is like a light-weight version of Visual Studio: you can even debug your code with it!
    • https://code.visualstudio.com/

IDEs (Integraded Development Environment)
Visual Studio: https://www.visualstudio.com
Tutorial on setting up Visual Studio: http://forums.terraria.org/index.ph...et-up-your-mod-using-visual-studio-mvs.26476/

Back to top
687474703a2f2f692e696d6775722e636f6d2f6b6463524f59502e706e67

PKgVGbQ.png

tModLoader developers: @bluemagic123, @jopojelly, @Chicken Bones, and I (@Jofairden)

Set up your tModLoader mod in MVS: (C# tutorials at the bottom) http://forums.terraria.org/index.ph...et-up-your-mod-using-visual-studio-mvs.26476/

Of course, thanks Re-Logic for creating Terraria, and thanks @bluemagic123 for creating tModLoader.


Useful sites, guides, tutorials.. and so forth


Sites

Guides/Tutorials
Utilities/Other
External Mod Wikis

Some popular mods have their own wikis. Use the links below to find information about them:
Here is a list of other useful mod specific pages hosted on the Terraria mods wiki.

Back to top
Things gotta get confusing..
How to import a mod in Visual Studio if I already started with Visual Studio Code?
I already downloaded the Visual Studio, and I don't know how to start...
 
Code:
System.ComponentModel.Win32Exception (0x80004005): Access is denied
   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at Terraria.Social.Steam.NetClientSocialModule.LaunchLocalServer(Process process, ServerMode mode)
   at Terraria.Main.DrawMenu(GameTime gameTime)
   at Terraria.Main.do_Draw(GameTime gameTime)
   at Terraria.Main.DoDraw(GameTime gameTime)
   at Terraria.Main.Draw(GameTime gameTime)
   at Microsoft.Xna.Framework.Game.DrawFrame()
   at Microsoft.Xna.Framework.Game.Tick()
   at Microsoft.Xna.Framework.Game.HostIdle(Object sender, EventArgs e)
   at Microsoft.Xna.Framework.GameHost.OnIdle()
   at Microsoft.Xna.Framework.WindowsGameHost.RunOneFrame()
   at Microsoft.Xna.Framework.WindowsGameHost.ApplicationIdle(Object sender, EventArgs e)
   at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at Microsoft.Xna.Framework.WindowsGameHost.Run()
   at Microsoft.Xna.Framework.Game.RunGame(Boolean useBlockingRun)
   at Terraria.Program.LaunchGame(String[] args, Boolean monoArgs)
Huuuge error that crashes the game and appears after trying to Host & Play with Steam on tModLoader. Any solutions? I really don't want to re-install tModLoader :(
 
Last edited:
pleaseeeeeeeeeeee who can help me with this
i'm trying to install the TML but this happend when i try to run terraria.exe

12/1/2017 9:50:22 AM
System.DllNotFoundException: Unable to load DLL 'CSteamworks': No se puede encontrar el módulo especificado. (Exception from HRESULT: 0x8007007E)
at Steamworks.NativeMethods.SteamAPI_RestartAppIfNecessary(AppId_t unOwnAppID)
at Terraria.Social.Steam.CoreSocialModule.Initialize()
at Terraria.Social.SocialAPI.Initialize(Nullable`1 mode)
at Terraria.Program.LaunchGame(String[] args, Boolean monoArgs)
 
^ Do you have a Steam account? Is Steam installed on your computer?


----------
Sorry for the length of this post. (TL;DR How do I modify vanilla values without the use of items? Right now all the Tmodloader functions that I know that fit this niche are virtual functions, which cannot be used to modify VANILLA stats.)
I've been modding for a while, and now I finally decided to try to make something new: Terraria wind physics. I made a working item that, when in your inventory, will push you, projectiles, enemies, and dusts based on the world's wind speed at the moment. It's been fun, but it wastes an extra inventory slot, so I decided that I wanted to make these wind physics work without using any items.
However! When I tried to use classes like GlobalProjectile to fix the problem, it didn't work. No error messages. No funky glitches. It loaded in with everything else... yet the wind just wasn't working. Then I realized: All of these functions in these classes are virtual, so they can't modify vanilla values! If I try to use the override constructor instead, which would work except for what I'm about to say, it returns this beautiful line of code: no suitable method found to override. So I ask, how can I edit vanilla values every frame without using an item? I would really appreciate feedback.
P.S. I haven't updated to 0.10 yet. There's too little work ethic for me and too many items for me to want to go through and change all their name formats
Code:
//Wind physics item code, in case you want to reuse this in your mod.
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.GameContent;
using Terraria.ObjectData;
using Terraria.GameContent.Events;
using System;

namespace Varion.Items.Accessories
{
    public class BookOfWind : ModItem
    {
        public static float verticalDraft = 0f;
        public override void SetDefaults()
        {

            item.name = "Weather Handler (Server)";
            item.width = 35;
            item.height = 40;
            item.toolTip = "You only need one of these. Keep it in your inventory to be able to experience weather physics.";
            item.value = 6700;
            item.rare = 12;
         

        }
            public override void UpdateInventory(Player player)
            {
                item.toolTip2 = ("Current updraft speed: "+((int)verticalDraft*4));
                item.favorited = true;
                if (Main.rand.Next(1, 500) == 1)
                {
                    verticalDraft += (float)(Main.rand.Next(-2,2)) / 4f;
                    if (player.ZoneDesert == true && verticalDraft < 5f)
                    {
                        verticalDraft -= 0.25f;
                    }
                    if (player.ZoneSnow= true && verticalDraft > -5f)
                    {
                        verticalDraft += 0.25f;
                    }
                    if (player.ZoneRain = true && verticalDraft > -5f)
                    {
                        if (Main.rand.Next(1, 2) == 1)
                        { 
                            verticalDraft += 0.25f;
                        }
                    }
                    if (Main.campfire)
                    {
                        verticalDraft -= 0.5f;
                    }
                    if (verticalDraft < -8f)
                    {
                        verticalDraft += 2.5f;
                    }
                    if (verticalDraft > 8f)
                    {
                        verticalDraft -= 2.5f;
                    }
                }
                for (int i = 0; i < 200; i++)
                {
                    if (Main.rand.Next(0,1 + 500 / (1 + (int)(Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet))) == 0)
                    {
                        Main.projectile[i].velocity.Y += (int)(verticalDraft * 1/6);
                        if (Main.windSpeedSet > 0)
                        {
                            Main.projectile[i].velocity.X += 1;
                        }
                        else
                        {
                            Main.projectile[i].velocity.X -= 1; 
                        }
                    }
                    if (Main.rand.Next(0,1 + 500 / (1 + (int)(Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet))) == 0)
                    {
                        Main.projectile[i].velocity.Y += (int)(verticalDraft * 1/6);
                        if (Main.windSpeedSet > 0)
                        {
                            Main.projectile[i].velocity.X += 1; 
                        }
                        else
                        {
                            Main.projectile[i].velocity.X -= 1; 
                        }
                    }
                    if (Main.rand.Next(0,1 + 3000 / (1 + (int)(Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet))) == 0 && Main.npc[i].friendly == false)
                    {
                        Main.npc[i].velocity.Y += (int)(verticalDraft * 1/6);
                        if (Main.windSpeedSet > 0)
                        {
                            Main.npc[i].velocity.X += 1;
                        }
                        else
                        {
                            Main.npc[i].velocity.X -= 1;
                        }
                    }
                    if (Main.rand.Next(0,1 + 50 / (1 + (int)(Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet))) == 0 && Main.npc[i].friendly == false)
                    {
                        Main.dust[i].velocity.Y += (int)(verticalDraft * 1/6);
                        if (Main.windSpeedSet > 0)
                        {
                            Main.dust[i].velocity.X += 1;
                        }
                        else
                        {
                            Main.dust[i].velocity.X -= 1;
                        }
                    }
                    if (Main.rand.Next(0,1 + 10000 / (1 + (int)(Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet))) == 0 && Main.campfire == false)
                    {
                        player.velocity.Y += (int)(verticalDraft * 1/6);
                        if (Main.windSpeedSet > 0 && player.noKnockback == false)
                        {
                            player.velocity.X += 1;
                        }
                        else
                        {
                            if (player.noKnockback == false)
                            {
                                player.velocity.X -= 1;
                            }
                        }
                    }
                    if (player.ZoneSandstorm && player.ZoneDesert)
                    {
                        if (Main.rand.Next(0,1000000 / (int)(Sandstorm.Severity * 100f)) == 0)
                        {
                            Projectile.NewProjectile(player.position.X + Main.rand.Next(-1000,1000), player.position.Y + Main.rand.Next(-500,0), Main.rand.Next(20 * (int)Sandstorm.Severity, 50 * (int)Sandstorm.Severity), 0, 31, 10, 3, 0);
                        }
                    }
                    if (player.ZoneSandstorm && player.ZoneSnow)
                    {
                        if (Main.rand.Next(0,1000000 / (int)(Sandstorm.Severity * 100f)) == 0)
                        {
                            Projectile.NewProjectile(player.position.X + Main.rand.Next(-1000,1000), player.position.Y + Main.rand.Next(-500,0), Main.rand.Next(50 * (int)Sandstorm.Severity, 100 * (int)Sandstorm.Severity), 0, 109, 10, 3, 0);
                        }
                    }
                }
            }
     
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient("Cloud in a Bottle", 1);
            recipe.AddIngredient("Book", 1);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }





    }
}
 
Last edited:
^ Do you have a Steam account? Is Steam installed on your computer?


----------
Sorry for the length of this post. (TL;DR How do I modify vanilla values without the use of items? Right now all the Tmodloader functions that I know that fit this niche are virtual functions, which cannot be used to modify VANILLA stats.)
I've been modding for a while, and now I finally decided to try to make something new: Terraria wind physics. I made a working item that, when in your inventory, will push you, projectiles, enemies, and dusts based on the world's wind speed at the moment. It's been fun, but it wastes an extra inventory slot, so I decided that I wanted to make these wind physics work without using any items.
However! When I tried to use classes like GlobalProjectile to fix the problem, it didn't work. No error messages. No funky glitches. It loaded in with everything else... yet the wind just wasn't working. Then I realized: All of these functions in these classes are virtual, so they can't modify vanilla values! If I try to use the override constructor instead, which would work except for what I'm about to say, it returns this beautiful line of code: no suitable method found to override. So I ask, how can I edit vanilla values every frame without using an item? I would really appreciate feedback.
P.S. I haven't updated to 0.10 yet. There's too little work ethic for me and too many items for me to want to go through and change all their name formats
Code:
//Wind physics item code, in case you want to reuse this in your mod.
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.GameContent;
using Terraria.ObjectData;
using Terraria.GameContent.Events;
using System;

namespace Varion.Items.Accessories
{
    public class BookOfWind : ModItem
    {
        public static float verticalDraft = 0f;
        public override void SetDefaults()
        {

            item.name = "Weather Handler (Server)";
            item.width = 35;
            item.height = 40;
            item.toolTip = "You only need one of these. Keep it in your inventory to be able to experience weather physics.";
            item.value = 6700;
            item.rare = 12;
        

        }
            public override void UpdateInventory(Player player)
            {
                item.toolTip2 = ("Current updraft speed: "+((int)verticalDraft*4));
                item.favorited = true;
                if (Main.rand.Next(1, 500) == 1)
                {
                    verticalDraft += (float)(Main.rand.Next(-2,2)) / 4f;
                    if (player.ZoneDesert == true && verticalDraft < 5f)
                    {
                        verticalDraft -= 0.25f;
                    }
                    if (player.ZoneSnow= true && verticalDraft > -5f)
                    {
                        verticalDraft += 0.25f;
                    }
                    if (player.ZoneRain = true && verticalDraft > -5f)
                    {
                        if (Main.rand.Next(1, 2) == 1)
                        {
                            verticalDraft += 0.25f;
                        }
                    }
                    if (Main.campfire)
                    {
                        verticalDraft -= 0.5f;
                    }
                    if (verticalDraft < -8f)
                    {
                        verticalDraft += 2.5f;
                    }
                    if (verticalDraft > 8f)
                    {
                        verticalDraft -= 2.5f;
                    }
                }
                for (int i = 0; i < 200; i++)
                {
                    if (Main.rand.Next(0,1 + 500 / (1 + (int)(Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet))) == 0)
                    {
                        Main.projectile[i].velocity.Y += (int)(verticalDraft * 1/6);
                        if (Main.windSpeedSet > 0)
                        {
                            Main.projectile[i].velocity.X += 1;
                        }
                        else
                        {
                            Main.projectile[i].velocity.X -= 1;
                        }
                    }
                    if (Main.rand.Next(0,1 + 500 / (1 + (int)(Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet))) == 0)
                    {
                        Main.projectile[i].velocity.Y += (int)(verticalDraft * 1/6);
                        if (Main.windSpeedSet > 0)
                        {
                            Main.projectile[i].velocity.X += 1;
                        }
                        else
                        {
                            Main.projectile[i].velocity.X -= 1;
                        }
                    }
                    if (Main.rand.Next(0,1 + 3000 / (1 + (int)(Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet))) == 0 && Main.npc[i].friendly == false)
                    {
                        Main.npc[i].velocity.Y += (int)(verticalDraft * 1/6);
                        if (Main.windSpeedSet > 0)
                        {
                            Main.npc[i].velocity.X += 1;
                        }
                        else
                        {
                            Main.npc[i].velocity.X -= 1;
                        }
                    }
                    if (Main.rand.Next(0,1 + 50 / (1 + (int)(Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet))) == 0 && Main.npc[i].friendly == false)
                    {
                        Main.dust[i].velocity.Y += (int)(verticalDraft * 1/6);
                        if (Main.windSpeedSet > 0)
                        {
                            Main.dust[i].velocity.X += 1;
                        }
                        else
                        {
                            Main.dust[i].velocity.X -= 1;
                        }
                    }
                    if (Main.rand.Next(0,1 + 10000 / (1 + (int)(Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet))) == 0 && Main.campfire == false)
                    {
                        player.velocity.Y += (int)(verticalDraft * 1/6);
                        if (Main.windSpeedSet > 0 && player.noKnockback == false)
                        {
                            player.velocity.X += 1;
                        }
                        else
                        {
                            if (player.noKnockback == false)
                            {
                                player.velocity.X -= 1;
                            }
                        }
                    }
                    if (player.ZoneSandstorm && player.ZoneDesert)
                    {
                        if (Main.rand.Next(0,1000000 / (int)(Sandstorm.Severity * 100f)) == 0)
                        {
                            Projectile.NewProjectile(player.position.X + Main.rand.Next(-1000,1000), player.position.Y + Main.rand.Next(-500,0), Main.rand.Next(20 * (int)Sandstorm.Severity, 50 * (int)Sandstorm.Severity), 0, 31, 10, 3, 0);
                        }
                    }
                    if (player.ZoneSandstorm && player.ZoneSnow)
                    {
                        if (Main.rand.Next(0,1000000 / (int)(Sandstorm.Severity * 100f)) == 0)
                        {
                            Projectile.NewProjectile(player.position.X + Main.rand.Next(-1000,1000), player.position.Y + Main.rand.Next(-500,0), Main.rand.Next(50 * (int)Sandstorm.Severity, 100 * (int)Sandstorm.Severity), 0, 109, 10, 3, 0);
                        }
                    }
                }
            }
    
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient("Cloud in a Bottle", 1);
            recipe.AddIngredient("Book", 1);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }





    }
}
Use the GlobalItem class.
 
Not what I was looking for, but thanks.:pslime:


(Don't waste your time helping me with this if you don't want to, but how can I make it so that public virtual void SetDefaults(Projectile projectile) {} will act like public override void SetDefaults(Projectile projectile) {} while inside the GlobalProjectile class without it saying 'no suitable method found to override' ?

My current code is
Code:
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.GameContent;
using Terraria.ObjectData;
using System;

namespace Terraria.ModLoader //also does not work with Varion.Mechanics
{
    public class GlobalProjectile
    {

        public virtual bool PostAI(Projectile projectile)
        {
              
                        if (Main.rand.Next(0,1 + 500 / (1 + (int)(Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet))) == 0)
                        {
                            if (Main.windSpeedSet > 0)
                            {
                                projectile.velocity.X += 1;
                            }
                            else
                            {
                                projectile.velocity.X -= 1;  
                            }
                        }
                        if (Main.rand.Next(0,1 + 500 / (1 + (int)(Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet * Main.windSpeedSet))) == 0)
                        {
                            if (Main.windSpeedSet > 0)
                            {
                                projectile.velocity.X += 1;  
                            }
                            else
                            {
                                projectile.velocity.X -= 1;  
                            }
                        }
                    return true;
        }
      
    }
}
 
Last edited:
PostAI is a void method, meaning it doesn't have a return value, but you are returning a bool.

Also, you forgot override there.

Come to discord, seems like it would help./
 
I tried asking in the discord, but is there anything I can do to fix an fps issue? In single player, I get normal fps, but if I try to play on a multiplayer tmodloader server I get 1-5 fps. Changing resolution and other options doesn't help.
 
^ Do you have a Steam account? Is Steam installed on your computer?

yup i have steam, but i have a GOG version and the patch for GOG version is a different build no? but i dont know if support 1.3.5.3 version i think only 1.3.4.4
so what can i do? :( i want to play calamity
 
Back
Top Bottom