Skip to content

set_wielded_item: option to disable item change animation#17020

Open
Zughy wants to merge 7 commits intoluanti-org:masterfrom
Zughy:wield_noanim
Open

set_wielded_item: option to disable item change animation#17020
Zughy wants to merge 7 commits intoluanti-org:masterfrom
Zughy:wield_noanim

Conversation

@Zughy
Copy link
Copy Markdown
Contributor

@Zughy Zughy commented Mar 14, 2026

Closes #9377

I've used Copilot to understand the client / server architecture. I've opted for adding a new packet instead of reusing e.g. TOCLIENT_INVENTORY. Hopefully it's cleaner and it can be used for future features - but it's my first time fiddling with something (for me) this big.

No crashes with old clients; just, the animation is played either way

To do

This PR is Ready for Review.

How to test

  1. Hold down left click with the following item to change it without animation (hue will change on every iteration)
  2. Right click does the same but it'll play the change animation
local hue = 0

local function loop_col(player, key, stack, skip_anim)
    core.chat_send_all("Looping. Hue = " .. hue)
    hue = hue <= 180 and hue + 5 or -180
    stack:get_meta():set_string("inventory_image", "server_favorite.png^[hsl:" .. hue)
    player:set_wielded_item(stack, skip_anim)
    core.after(0.1, function()
        if not player:get_player_control()[key] then return end
        loop_col(player, key, stack, skip_anim)
    end)
end

core.register_node("test:node", {
    description = "Test node",
    wield_image = "server_favorite.png",
    inventory_image = "server_favorite.png",
    groups = {cracky = 3},

    on_use = function(itemstack, user, pointed_thing)
        loop_col(user, "dig", itemstack, true)
        return
    end,
    
    on_place = function(itemstack, placer, pointed_thing)
        return
    end,
    
    on_secondary_use = function(itemstack, user, pointed_thing)
        loop_col(user, "place", itemstack)
    end
})

@Zughy Zughy added @ Script API Feature ✨ PRs that add or enhance a feature Roadmap: supported by core dev PR not adhering to the roadmap, yet some core dev decided to take care of it @ Client / Audiovisuals labels Mar 14, 2026
Copy link
Copy Markdown
Member

@SmallJoker SmallJoker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple change - I like it.

Copy link
Copy Markdown
Member

@SmallJoker SmallJoker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works

@Zughy Zughy added this to the 5.16.0 milestone Mar 15, 2026
@CandyFiend
Copy link
Copy Markdown

The flag is set when the TOCLIENT_WIELD_ITEM packet is received and is reset in the same game loop iteration when consumeSkipNextWieldAnimation() is called. It is then passed to camera->wield() with animate = false, which prevents the item swap animation timer from starting.

However, it's important to use set_wielded_item(item, skip_anim) correctly in your implementation. For items like the compass, which update their metadata (and consequently their texture) based on the player's viewing direction, there is a nuance.

If you update all compass instances in the inventory using set_stack(), the equipped compass will trigger an item swap animation. To avoid this, you need to:

  • handle the compass in the active slot separately;
  • use set_wielded_item() with skip_anim = true for it, which updates the appearance without animation;
  • continue using set_stack() for the other compasses in the inventory.

This means that in globalstep, you need to distinguish whether the compass being updated is currently in the player's hand, and apply the appropriate update method accordingly.

Did I understand correctly how your implementation works and the specifics of its use in the item replacement code?

@Zughy
Copy link
Copy Markdown
Contributor Author

Zughy commented Mar 24, 2026

@CandyFiend correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

@ Client / Audiovisuals Feature ✨ PRs that add or enhance a feature One approval ✅ ◻️ Protocol bump Roadmap: supported by core dev PR not adhering to the roadmap, yet some core dev decided to take care of it @ Script API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change the wield item with no animation

4 participants