From d12f19fabf3fddc3f3bb83210ea80cf56f00fad8 Mon Sep 17 00:00:00 2001 From: luk3yx Date: Mon, 19 Jun 2023 17:50:22 +1200 Subject: [PATCH] Add no_change_anim group --- doc/lua_api.txt | 2 ++ src/client/camera.cpp | 11 ++++++++--- src/client/camera.h | 2 +- src/client/game.cpp | 3 ++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 92bfb1fa1..e65239b9b 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1708,6 +1708,8 @@ to games. ### Node, item and tool groups +* `no_change_anim`: Disables the wielditem changing animation when switching + to the item in the hotbar. * `not_in_creative_inventory`: (*) Special group for inventory mods to indicate that the item should be hidden in item lists. diff --git a/src/client/camera.cpp b/src/client/camera.cpp index 2d0076580..dd0ee985e 100644 --- a/src/client/camera.cpp +++ b/src/client/camera.cpp @@ -648,15 +648,20 @@ void Camera::setDigging(s32 button) m_digging_button = button; } -void Camera::wield(const ItemStack &item) +void Camera::wield(const ItemStack &item, const bool no_change_anim) { if (item.name != m_wield_item_next.name || item.metadata != m_wield_item_next.metadata) { m_wield_item_next = item; - if (m_wield_change_timer > 0) + if (no_change_anim) { + // Change items immediately + m_wieldnode->setItem(item, m_client); + m_wield_change_timer = 0.125f; + } else if (m_wield_change_timer > 0) { m_wield_change_timer = -m_wield_change_timer; - else if (m_wield_change_timer == 0) + } else if (m_wield_change_timer == 0) { m_wield_change_timer = -0.001; + } } } diff --git a/src/client/camera.h b/src/client/camera.h index 8ece70089..59cb7d54a 100644 --- a/src/client/camera.h +++ b/src/client/camera.h @@ -154,7 +154,7 @@ public: void setDigging(s32 button); // Replace the wielded item mesh - void wield(const ItemStack &item); + void wield(const ItemStack &item, const bool no_change_anim); // Draw the wielded tool. // This has to happen *after* the main scene is drawn. diff --git a/src/client/game.cpp b/src/client/game.cpp index a05e3ebfe..cf3746352 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -3948,7 +3948,8 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, // Update wielded tool ItemStack selected_item, hand_item; ItemStack &tool_item = player->getWieldedItem(&selected_item, &hand_item); - camera->wield(tool_item); + const ItemDefinition &item_def = tool_item.getDefinition(itemdef_manager); + camera->wield(tool_item, itemgroup_get(item_def.groups, "no_change_anim") > 0); } /*