mojira.dev
MC-262560

Previously held items in first person don't slide out of the screen when picking them up via the mouse cursor

The Bug:

Previously held items in first person don't slide out of the screen when picking them up via the mouse cursor.

With this problem, the previously held items instantly disappears and the player's hand is shown instead. This causes a jerky and misleading animation.

Steps to Reproduce:

  1. Begin holding any item in your hand.

  2. Open your inventory, pick up the said item via the mouse cursor, and watch the held item your hand closely as you do this.

  3. Take note as to whether or not previously held items in first person don't slide out of the screen when picking them up via the mouse cursor.

Observed Behavior:

Previously held items in first person don't slide out of the screen when picking them up via the mouse cursor.

Expected Behavior:

Previously held items in first person would slide out of the screen when picking them up via the mouse cursor. After the previously held item slides out, the player's hand should slide in.

Linked issues

Attachments

Comments 4

This issue also affects Minecraft snapshot 24w09a.

Code analysis (Yarn mappings)

I believe this issue to be caused by other code (in inventory management methods) mutating the stack and clearing it, causing the stack shown in the animation to become empty and display as a hand instead.

The following is a simplified version of events that I believe to occur during the swap:

1. Player clicks the slot to pick up the item
2. A new copy of the stack becomes the cursor stack, while the previous stack becomes an empty stack
3. The previous stack remains referenced by the held item renderer
4. On future renders, since the stack is now empty, a hand is rendered instead

I believe the correct solution is to maintain a copy of the hand stack so that mutations from unrelated systems like inventory do not interfere with the stack used for the swapping animation. In previous versions, such a change might have resulted in performance issues (or at minimum, might have removed premature optimization in avoiding checking value equality of NBT often), but I doubt the situation is the same today. After all, several systems already perform value equality checks against a copied stack, such as updating the armor of an entity that a player is watching. Item stack components introduced in Minecraft snapshot 24w09a may have better value equality check performance as well, though I'm not sure on that matter.

In short: within the HeldItemRenderer#updateHeldItems method, remove the ItemStack.areEqual checks that allow reference equality to be used more often, and copy the stacks when updating them during the midpoint of the animation.

It seems my bug report has been marked as a duplicate of yours. However, the summary and descriptions in your report seem somewhat unusual. I don't believe this can accurately be termed as "sliding," and it appears to lack organization, failing to mention that this wasn't a problem before version 1.11. Additionally, it's worth noting that this issue doesn't occur when removing items from the main hand using the number keys. A similar issue can be observed with items in the offhand. When clicked normally, the item disappears from the hand in first person without any animation. If done differently, you can see the animation of the item disappearing. I've included the videos from my duplicate report.

[media][media]

The traditional term for this feature is the "up and down animation," which occurs whenever there's any alteration to the item in your hand. I've mentioned this term in my comment to aid in locating this report through the search function, as I couldn't find your report. Describing this animation as "sliding" seems overly vague to me.

Also affects 1.20.5 pre-release.

Avoma

(Unassigned)

Confirmed

Platform

Low

Player Animation

1.19.4, 1.20 Pre-release 1, 1.20 Pre-release 6, 1.20, 1.20.1, ..., 24w14a, 1.21, 1.21.4, 1.21.5, 25w21a

Retrieved