Standalone PreClick Weapon use: Improved behavior for all non-autofire weapons

Mail

Official Terrarian
This mod prevents clicks and button presses from doing nothing if you attack slightly early when using an item.

If you continue holding down an attack button with this mod, it will attack once the weapon is ready.

This is not the same as autofire, since it will only ever attack one time per click/button press.

Things to try with this mod:

Use early game bows and see how much more consistent the fire rate is. All single fire weapons have extremely consistent fire rates with this mod and feel effortless to use.

Melee weapons see considerable benefits from this mod. Without this mod, if you accidentally click too early, you will have to click an extra time. This attack pause may allow an enemy to close in and deal damage. The more consistent attack speed helps melee players without auto-swing avoid damage.

Click and hold after throwing a boomerang. You will attack again as soon as you catch it.

Quickly double click using the Venus Magnum. With the mod you will often shoot two shots compared to vanilla, where you are much more likely to randomly shoot one or two. (depends on your click speed)


Exactly how much this change influences game balance really depends on your reflexes. Perfect timing means this mod does nothing. Freeing up player concentration that was dedicated to attack timing to focus on other things probably helps the player more than the small increase it might give to attack speed. The average increase in attack speed this mod gives compared to random clicking is proportional to the speed the player is required to click to maintain full dps.

I would like for PreClick item use to be included in the official 1.4.1 patch, but if that fails, I will try to incorporate this mod into an unofficial community patch.


Instructions:

This mod currently works on Terraria 1.4.0.5 and 1.4.1.0

I no longer suggest patching your game exe directly to test this, since I have added Terraria Tweaker 2 compatible plugins. Only download the 7z file if you don't want to use Terraria Tweaker 2, and would instead prefer to patch your game directly.

PreClick.cs

This is intended if you just want to play the game with the mod enabled.

PreClick_Testing.cs

This extended mod has extra features to help understand what this mod does.

If you equip the Guide Voodoo Doll, it will disable the mod's PreClick behavior so you can easily compare the mod to vanilla.

If you equip the Clothier Voodoo Doll, autofire will be disabled for all weapons. This is intended to help identify weapons that might currently have autofire but don't really need it with this mod.

If you equip the Clothier Voodoo Doll together with any knockback glove, autofire will be enabled for all weapons. This is intended to help you compare how close your PreClick attacks can come to actual autofire.

SlowerSingleUseItems.cs

This mod probably needs to be redone with a more specific set of nerfs, so I don't suggest using it right now. This mod globally nerfs the attack speed of all single fire weapons by just one frame. You can edit the script if you want to nerf them by more. Be warned this also nerfs the use time of weapons that don't naturally have autofire, but instead get it from the knockback glove. Also weapons that shoot projectiles will have a longer projectile cooldown. (starfury, beam sword, etc) Rather than using this mod directly, you should modify the plugin to only nerf the weapons that you think this mod makes overpowered.

TModLoader edition now available

All changes are limited to the function Player.ItemCheck

At the top of the function Player.ItemCheck add a boolean named didUseItem.

Added code:
Code:
 bool didUseItem = false;


after the call to ItemCheck_StartActualUse() set didUseItem to true

Original code:
Code:
if (...)
{
    ItemCheck_StartActualUse(...);
}
or
Code:
if (...)
    ItemCheck_StartActualUse(...);
Modified code:
Code:
if (...)
{
    ItemCheck_StartActualUse(...);
    didUseItem = true;
}


The following code will be enclosed in an if statement:

Code:
this.releaseUseItem = !this.controlUseItem;

It will be changed to:

Code:
if (didUseItem || !this.controlUseItem || !this.releaseUseItem)
{
    this.releaseUseItem = !this.controlUseItem;
}

The end result is that if you pressed a button, but nothing happened, the game will act as if you pressed again next frame.

releaseUseItem has a somewhat confusing naming, but it is simply the opposite of what controlUseItem was last frame. This means it is true if the button to use an item was not pressed.

Both weapons with autofire and having the knockback glove set releaseUseItem to true every frame. The difference between this mod and autofire is that this mod keeps track of whether ItemCheck_StartActualUse was called so it will stop retrying after the item is used once.

The Terraria Tweaker 2 plugin works slightly differently because I did not want to make modifications to any existing functions for maximum mod compatibility. Instead of blocking releaseUseItem from being set to false in the function it waits to change it back to true after the function ends.
 

Attachments

Last edited:
Some extra notes about game balance and how input is handled:

I could be incorrect on a few points, since I haven't studied the game's code all that well.

Terraria can only register a click or button press every other frame. A button must be released one frame, then pressed the next frame in order to make an attack.

When clicking very fast, the input at all may not register at all. Since input is checked once per frame, if a button transitions from pressed to release multiple times between frames, those inputs are ignored. Any inputs faster than alternating press and release each frame results in many dropped inputs and a slower and more inconsistent attack speed.

With maximum speed nonstop clicks, you can only click half as many times as the framerate. Optimal non-stop clicking will only click on even/odd frames. This means that weapons with a cooldown that is an odd number of frames will attack one frame slower than they should when using maximum speed fast clicking. If clicking is slowed to sync with the weapon's cooldown the attack attack delay can be reduced by one frame compared to maximum speed clicking.

If multiple keys/buttons are bound to attack and are being clicked/pressed rapidly, the game will see the input as being pressed if any of them are pressed. This interferes with the game's ability to notice when a key is released and the player may end up attacking slower than if they were using a single keybind.

Some game engines handle these special cases, but it isn't uncommon to have these issues. Valve's source engine specifically tracks what happens with keys and buttons between frames.
 
I am intrigued by this plugin you made, i don't totally understand it how it works but you provided some extra functionality to test/compare it so am definitely going check it out. 2-3 years back when i started playing Terraria, i quickly noticed the clunkiness when using non auto-fire melee weapons, i.e., clicking faster typically results in slower attack speed.

The auto-fire mods out there have always felt too cheaty for me. Based on your description, it seems like you are saying that we'll still need to click the same amount of times (i.e., 3 clicks for 3 attacks) but now clicking early won't either delay or prevent the attack from registering, which sounds sweet. I'll see for myself though a bit later. Thank you!

Btw, I saw your post on the Terraria Tweaker 2 page, so thanks for linking this from there. I probably wouldn't have found it otherwise.

------------

EDIT:
So i just got through trying out your mod/plugin for a good while. I used the "PreClick_Testing" file and did try out all 3 of the additional testing/compare functions it offers. It is definitely an improvement across the board imo (only tested melee swords fyi). I am very happy with this plugin, thank you!

With the plugin running in it's default setting (no dolls or glove equipped), I am still able to attack a bit faster with slow weapons (basically the Fiery Greatsword) by deliberately timing my mouse clicks. Although, when not timing my clicks, your plugin definitely improves how often misfires occur and how quickly the attack animations get back in sync when delays do happen.

I personally didn't experience any increase in speeds (decrease in use time) from vanilla. Although, w/ the Fiery Greatsword, clicking super fast appeared to give more consistent results in keeping it's speed on par w/ perfectly timed clicks (/ with autofire cheat enabled). When i first started playing Terraria, i searched online to see if other people had the same "issue" where, if mouse clicks weren't timed perfectly, swords' attack animations wouldn't get registered, misfire, delay, etc.. I was surprised in how difficult it was to find any1 talk about the same thing. To me, it seemed most ppl didn't even notice. So i would suspect some may have gotten "used" to slower speeds.
 
Last edited:
Just tried it now, and it feels significantly more responsive to my clicks. Mashing the button however kind of makes it feels like the useTime has been reduced (then again, the vanilla one doesn't respond immediately to clicks so that could be the case?), but yeah; it's a really good plugin. Thanks for sharing it with us!
 
Just tried it now, and it feels significantly more responsive to my clicks. Mashing the button however kind of makes it feels like the useTime has been reduced (then again, the vanilla one doesn't respond immediately to clicks so that could be the case?), but yeah; it's a really good plugin. Thanks for sharing it with us!

You could argue that non-autofire weapon attack speed is inflated in vanilla to compensate for less responsive controls.

If use times are increased with this change it becomes a nerf for high skill players.

If use times are not increased, it is probably a very noticeable buff for low skill players. Players with very unstable framerates might see it as a massive buff, but that is probably a good thing.
 
Last edited:
You could argue that non-autofire weapon attack speed is inflated in vanilla to compensate for less responsive controls. . . .
That gives me an brilliant videa to make a plugin with yours. . .
(Plugin that will have to make the player "wait" for the weapon to charge up so that it registers 100% damage if done so (like Minecraft weapons). Charging rates also depends on the weapon's dps ((60 / useTime•) * damage).

• - does not work for melee weapons that shoot projectiles, gonna find a way in a later edit
 
(Plugin that will have to make the player "wait" for the weapon to charge up so that it registers 100% damage if done so (like Minecraft weapons). Charging rates also depends on the weapon's dps ((60 / useTime•) * damage).

• - does not work for melee weapons that shoot projectiles, gonna find a way in a later edit
Just a warning:
It would be tricky to allow shorter than normal use time on a weapon due to the way weapon use time, attack animations, and collision detection are inter-related. It might look strange if a faster swing did less damage and it will definitely look glitchy if you allow a player to restart a weapon attack mid-swing. Changes to weapon damage also scale poorly with higher armor values. If your mod enables fast weak attacks then the player wastes more damage on armor.

Honestly, weapon charging and animations in Minecraft look stiff and twitchy, and I don't think that's something you want to bring to Terraria.

If you want to go the route of charging bonus damage, crit chance might seem like a good candidate since it does not bypass armor, but projectiles or magic fired by the player will retroactively have their critical hit chances changed if you alter the player's critical hit chance. You can even boost the crit chance of your spells by casting a spell and equipping a high crit rate melee or ranged weapon before the damage is dealt.
 
Just a warning:
It would be tricky to allow shorter than normal use time on a weapon due to the way weapon use time, attack animations, and collision detection are inter-related.
Before the plugin was introduced, I actually had a recent successful project on modifying all weapons by making them use mana, with some weapon logic changed. It's pretty ok to shorten useTime or useAnimation, except on special weapons that use channeling (Note: Never reduce useTime/Animation to 1 or lower. If it registers as 0, there's a likely chance the projectile won't be spawned at all, and modifiers or buffs could also reduce that, also why you don't go for 1 as well)

If you want to go the route of charging bonus damage, crit chance might seem like a good candidate since it does not bypass armor . . .
Oh yeah, forgot about critical hit for a moment there. Would keep in mind.

Projectiles or magic fired by the player will retroactively have their critical hit chances changed if you alter the player's critical hit chance. You can even boost the crit chance of your spells by casting a spell and equipping a high crit rate melee or ranged weapon before the damage is dealt.
I didn't really knew this info before . . . For me this can go for 2 ways; I fix the problem using a plugin (problematic but ok), or I just apply the charging feature to true melee weapons (Come to think about it this gives weapons like ore spears and swords a good buff so that they would be level with the ranger class, would do this instead)


I wasn't expecting you to critique/examine my idea, but the info you released there has some pretty vital insights for my project. Thanks!
 
I personally didn't experience any increase in speeds (decrease in use time) from vanilla. Although, w/ the Fiery Greatsword, clicking super fast appeared to give more consistent results in keeping it's speed on par w/ perfectly timed clicks (/ with autofire cheat enabled). When i first started playing Terraria, i searched online to see if other people had the same "issue" where, if mouse clicks weren't timed perfectly, swords' attack animations wouldn't get registered, misfire, delay, etc.. I was surprised in how difficult it was to find any1 talk about the same thing. To me, it seemed most ppl didn't even notice. So i would suspect some may have gotten "used" to slower speeds.

This is very good feedback. I am glad to see some people are not seeing this as a buff. You might have above average reflexes/timing if you feel this way, which could also be why you noticed this as being an issue in the first place.
 
Last edited:
I noticed the last update on this page that you made was on August 10th, which is after I downloaded the PreClick_Testing.cs file and after you posted the alternative SingleSlowerUseTime.cs file. I only have the PreClick_Testing file and can see it is still the latest version. Just checking if you made any changes to the regular PreClick.cs file? Maybe just edited the page and not anything with the plugin files?
 
I noticed the last update on this page that you made was on August 10th, which is after I downloaded the PreClick_Testing.cs file and after you posted the alternative SingleSlowerUseTime.cs file. I only have the PreClick_Testing file and can see it is still the latest version. Just checking if you made any changes to the regular PreClick.cs file? Maybe just edited the page and not anything with the plugin files?
I have not made any changes at all to PreClick.cs since I posted it. If you take a look at it in a text editor, you can see that it is a very small mod. I don't expect to update it. It is a low risk for causing bugs or conflicts with other mods. It also has a high probability of working with past and future versions of the game. Edit: Does not work on versions before 1.4

It is possible I might have bugs in this mod that only sometimes appear when using specific weapons in multiplayer, so I can't say for sure it will never be updated.

If someone uses this mod in multiplayer or a version other than 1.4.0.5 and it works fine, please mention it in this thread.
 
Last edited:
I have not made any changes at all to PreClick.cs since I posted it. If you take a look at it in a text editor, you can see that it is a very small mod. I don't expect to update it. It is a low risk for causing bugs or conflicts with other mods. It also has a high probability of working with past and future versions of the game.

It is possible I might have bugs in this mod that only sometimes appear when using specific weapons in multiplayer, so I can't say for sure it will never be updated.

If someone uses this mod in multiplayer or a version other than 1.4.0.5 and it works fine, please mention it in this thread.
Thanks for the reply. Hopefully I didn't give the impression that i'm experiencing any problems, because i'm not. It's been great. And sure thing, if I ever try the mod out in multiplayer or on a different version, i'll let you know if it works okay.
 
Back
Top Bottom