question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AltFunctionUse (right click) causing a tick of delay between consecutive uses

See original GitHub issue

Description

With a weapon’s right-click use, there is a single tick of pause between consecutive uses, where the hand returns to resting position. At lower use speeds this makes the hand appear to glitch out, moving back and forth rapidly. Normally, with left click, the hand just stays out as long as the weapon is in use.

Steps to Reproduce

  1. Create a weapon with override bool AltFunctionUse(Player player) returning true, and item.autoReuse set to true in SetDefaults().
  2. Run the game with the modded weapon active.
  3. Select the weapon and hold Right Click.

Expected behavior

There is 1 frame where nothing happens between uses of the weapon, the hand moving back to resting position and then back to the use animation.

Actual behavior

The hand should stay out, as left click does, and no delay should occur between uses.

Reproduction frequency

Every time, with any standard weapon with an altFunctionUse. This is most noticeable with useStyles 3 and 5, however.

Versions

tModLoader v0.10.1

Additional Information

It appears that this happens because the alternate function code is called near the end of the player update method, and there’s the check if (this.itemAnimation == 0 || PlayerInput.Triggers.JustPressed.MouseRight), the logical conclusion being that the code for using the weapon doesn’t run unless the player has already stopped swinging, causing the 1 tick of pause.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
hollowstrawberrycommented, Nov 25, 2017

Ah, you meant player.itemAnimation, sorry!

It’s a good idea to try setting it to 0, but sadly it didn’t work in either ModItem.CanUseItem, ModPlayer.PreUpdate or ModPlayer.PostUpdate.

However, after a lot of trial and error I got the following to work inside GetWeaponDamage! It’s a little hacky but it got the job done. It depends on GetWeaponDamage running every tick of the player’s useAnimation.

if (player.altFuctionUse == 2)
{
    if (player.itemAnimation == 1) //Doesn't let the hand return to resting position
    {
        player.altFunctionUse = 1;
        player.controlUseItem = true;
    }
    if (PlayerInput.Triggers.JustReleased.MouseRight) //Stops the animation manually
    {
        player.altFunctionUse = 0;
        player.controlUseItem = false;
        return false;
    }
}

Edit 2: I suppose there is a much cleaner way to do it, by simply looping the animation back before it reaches 0 and replaying the use sound. It probably has its own issues; I think it effectively lowers the total useAnimation of the item by 1, so keep that in mind:

    if (player.itemAnimation == 1) //Resets the animation so it doesn't let the hand return to resting position
    {
        player.itemAnimation = item.useAnimation;
        Main.PlaySound(item.UseSound, player.Center);
    }
    if (PlayerInput.Triggers.JustReleased.MouseRight) //Stops the animation manually
    {
        player.itemAnimation = 0;
        return false;
    }

Edit 1: The bug has a related effect that makes it normally impossible to have an alternate use without autoReuse. Here is how you could fix that, inside CanUseItem:

if (player.altFuctionUse == 2)
{
    if (!PlayerInput.Triggers.JustPressed.MouseRight) return false; //Equivalent to autoReuse being set to false, as that flag is bugged with alternate use
}

These are probably not very good solutions, but there’s that for anyone who might be looking into this.

If there’s nothing else to be said, should we close the issue?

0reactions
Chicken-Bonescommented, Apr 21, 2023

This was probably fixed by #2351 and related issues

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove the 5 tick delay between right-clicking with ...
Players playing on newer Minecraft versions are at disadvantage in Classic PVP servers due to the delay of shield usage.
Read more >
How long is a redstone repeater tick? - Old School Gamers
When initially placed, a redstone repeater has a delay of 1 redstone tick (equivalent to 2 game ticks, or 0.1 seconds barring lag)....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found