From 3d301f13d7bbb1413af33ba43b2fd096853f0321 Mon Sep 17 00:00:00 2001 From: Xertis <118364459+Xertis@users.noreply.github.com> Date: Fri, 6 Mar 2026 23:58:51 +0300 Subject: [PATCH] moved interact from world to hud --- src/content/ContentPack.hpp | 1 - src/logic/scripting/scripting.cpp | 18 ------------------ src/logic/scripting/scripting_hud.cpp | 17 +++++++++++++++++ 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/content/ContentPack.hpp b/src/content/ContentPack.hpp index 676bdffa3..a4548d038 100644 --- a/src/content/ContentPack.hpp +++ b/src/content/ContentPack.hpp @@ -127,7 +127,6 @@ struct WorldFuncsSet { bool onchunkremove; bool oninventoryopen; bool oninventoryclosed; - bool oninventoryinteract; }; class ContentPackRuntime { diff --git a/src/logic/scripting/scripting.cpp b/src/logic/scripting/scripting.cpp index 713018503..e3c23ee1e 100644 --- a/src/logic/scripting/scripting.cpp +++ b/src/logic/scripting/scripting.cpp @@ -540,22 +540,6 @@ void scripting::on_inventory_closed(const Player* player, const Inventory& inven } } -void scripting::on_inventory_interact(int invid, int slot, int action) { - auto args = [invid, slot, action](lua::State* L) { - lua::pushinteger(L, invid); - lua::pushinteger(L, slot); - lua::pushinteger(L, action); - return 3; - }; - for (auto& [packid, pack] : content->getPacks()) { - if (pack->worldfuncsset.oninventoryinteract) { - lua::emit_event( - lua::get_main_state(), packid + ":.inventoryinteract", args - ); - } - } -} - void scripting::on_player_tick(Player* player, int tps) { auto args = [=](lua::State* L) { lua::pushinteger(L, player ? player->getId() : -1); @@ -777,8 +761,6 @@ void scripting::load_world_script( register_event(env, "on_inventory_open", prefix + ":.inventoryopen"); funcsset.oninventoryclosed = register_event(env, "on_inventory_closed", prefix + ":.inventoryclosed"); - funcsset.oninventoryinteract = - register_event(env, "on_inventory_interact", prefix + ":.inventoryinteract"); } void scripting::load_layout_script( diff --git a/src/logic/scripting/scripting_hud.cpp b/src/logic/scripting/scripting_hud.cpp index da72b031b..62dd0781a 100644 --- a/src/logic/scripting/scripting_hud.cpp +++ b/src/logic/scripting/scripting_hud.cpp @@ -93,6 +93,22 @@ void scripting::on_frontend_close() { scripting::post_processing = nullptr; } +void scripting::on_inventory_interact(int invid, int slot, int action) { + auto L = lua::get_main_state(); + for (auto& pack : content_control->getAllContentPacks()) { + lua::emit_event( + L, + pack.id + ":.hudinventoryinteract", + [&](lua::State* L) { + lua::pushinteger(L, invid); + lua::pushinteger(L, slot); + lua::pushinteger(L, action); + return 3; + } + ); + } +} + void scripting::load_hud_script( const scriptenv& senv, const std::string& packid, @@ -109,6 +125,7 @@ void scripting::load_hud_script( register_event(env, "on_hud_open", packid + ":.hudopen"); register_event(env, "on_hud_render", packid + ":.hudrender"); register_event(env, "on_hud_close", packid + ":.hudclose"); + register_event(env, "on_hud_inventory_interact", packid + ":.hudinventoryinteract"); } gui::PageLoaderFunc scripting::create_page_loader() {