mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-08 20:41:49 +00:00
Merge pull request #808 from Xertis/main
Made on_inventory_interact + update hud
This commit is contained in:
commit
1f7696e972
11 changed files with 134 additions and 4 deletions
|
|
@ -140,6 +140,15 @@ static int l_get_block_inventory(lua::State* L) {
|
|||
}
|
||||
}
|
||||
|
||||
static int l_get_second_inventory(lua::State* L) {
|
||||
auto inventory = hud->getSecondInventory();
|
||||
if (inventory == nullptr) {
|
||||
return lua::pushinteger(L, 0);
|
||||
} else {
|
||||
return lua::pushinteger(L, inventory->getId());
|
||||
}
|
||||
}
|
||||
|
||||
static int l_get_player(lua::State* L) {
|
||||
auto player = hud->getPlayer();
|
||||
return lua::pushinteger(L, player->getId());
|
||||
|
|
@ -153,6 +162,10 @@ static int l_is_inventory_open(lua::State* L) {
|
|||
return lua::pushboolean(L, hud->isInventoryOpen());
|
||||
}
|
||||
|
||||
static int l_is_player_inventory_open(lua::State* L) {
|
||||
return lua::pushboolean(L, hud->isPlayerInventoryOpen());
|
||||
}
|
||||
|
||||
static int l_is_content_access(lua::State* L) {
|
||||
return lua::pushboolean(L, hud->isContentAccess());
|
||||
}
|
||||
|
|
@ -202,11 +215,13 @@ const luaL_Reg hudlib[] = {
|
|||
{"open_permanent", wrap_hud<l_open_permanent>},
|
||||
{"show_overlay", wrap_hud<l_show_overlay>},
|
||||
{"get_block_inventory", wrap_hud<l_get_block_inventory>},
|
||||
{"get_second_inventory", wrap_hud<l_get_second_inventory>},
|
||||
{"close", wrap_hud<l_close>},
|
||||
{"pause", wrap_hud<l_pause>},
|
||||
{"resume", wrap_hud<l_resume>},
|
||||
{"is_paused", wrap_hud<l_is_paused>},
|
||||
{"is_inventory_open", wrap_hud<l_is_inventory_open>},
|
||||
{"is_player_inventory_open", wrap_hud<l_is_player_inventory_open>},
|
||||
{"get_player", wrap_hud<l_get_player>},
|
||||
{"_is_content_access", wrap_hud<l_is_content_access>},
|
||||
{"_set_content_access", wrap_hud<l_set_content_access>},
|
||||
|
|
|
|||
|
|
@ -108,6 +108,7 @@ namespace scripting {
|
|||
|
||||
void on_inventory_open(const Player* player, const Inventory& inventory);
|
||||
void on_inventory_closed(const Player* player, const Inventory& inventory);
|
||||
void on_inventory_interact(int invid, int slot, int mode, int action);
|
||||
|
||||
void on_player_tick(Player* player, int tps);
|
||||
|
||||
|
|
|
|||
|
|
@ -93,6 +93,23 @@ void scripting::on_frontend_close() {
|
|||
scripting::post_processing = nullptr;
|
||||
}
|
||||
|
||||
void scripting::on_inventory_interact(int invid, int slot, int mode, int action) {
|
||||
auto L = lua::get_main_state();
|
||||
for (auto& pack : content_control->getAllContentPacks()) {
|
||||
lua::emit_event(
|
||||
L,
|
||||
pack.id + ":.inventoryinteract",
|
||||
[&](lua::State* L) {
|
||||
lua::pushinteger(L, invid);
|
||||
lua::pushinteger(L, slot);
|
||||
lua::pushinteger(L, mode);
|
||||
lua::pushinteger(L, action);
|
||||
return 4;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void scripting::load_hud_script(
|
||||
const scriptenv& senv,
|
||||
const std::string& packid,
|
||||
|
|
@ -109,6 +126,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_inventory_interact", packid + ":.inventoryinteract");
|
||||
}
|
||||
|
||||
gui::PageLoaderFunc scripting::create_page_loader() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue