moved interact from world to hud

This commit is contained in:
Xertis 2026-03-06 23:58:51 +03:00
parent 55f30caa35
commit 3d301f13d7
3 changed files with 17 additions and 19 deletions

View file

@ -127,7 +127,6 @@ struct WorldFuncsSet {
bool onchunkremove;
bool oninventoryopen;
bool oninventoryclosed;
bool oninventoryinteract;
};
class ContentPackRuntime {

View file

@ -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(

View file

@ -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() {