Skip to content

Commit fcf86de

Browse files
authoredDec 13, 2021
Disable inventory if player's inventory formspec is blank (#11827)
1 parent 84efe27 commit fcf86de

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed
 

‎doc/lua_api.txt

+1
Original file line numberDiff line numberDiff line change
@@ -6690,6 +6690,7 @@ object you are working with still exists.
66906690
* `set_inventory_formspec(formspec)`
66916691
* Redefine player's inventory form
66926692
* Should usually be called in `on_joinplayer`
6693+
* If `formspec` is `""`, the player's inventory is disabled.
66936694
* `get_inventory_formspec()`: returns a formspec string
66946695
* `set_formspec_prepend(formspec)`:
66956696
* the formspec string will be added to every formspec shown to the user,

‎src/client/game.cpp

+14-7
Original file line numberDiff line numberDiff line change
@@ -2060,15 +2060,22 @@ void Game::openInventory()
20602060
InventoryLocation inventoryloc;
20612061
inventoryloc.setCurrentPlayer();
20622062

2063-
if (!client->modsLoaded()
2064-
|| !client->getScript()->on_inventory_open(fs_src->m_client->getInventory(inventoryloc))) {
2065-
TextDest *txt_dst = new TextDestPlayerInventory(client);
2066-
auto *&formspec = m_game_ui->updateFormspec("");
2067-
GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(),
2068-
&input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound);
2063+
if (client->modsLoaded() && client->getScript()->on_inventory_open(fs_src->m_client->getInventory(inventoryloc))) {
2064+
delete fs_src;
2065+
return;
2066+
}
20692067

2070-
formspec->setFormSpec(fs_src->getForm(), inventoryloc);
2068+
if (fs_src->getForm().empty()) {
2069+
delete fs_src;
2070+
return;
20712071
}
2072+
2073+
TextDest *txt_dst = new TextDestPlayerInventory(client);
2074+
auto *&formspec = m_game_ui->updateFormspec("");
2075+
GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(),
2076+
&input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound);
2077+
2078+
formspec->setFormSpec(fs_src->getForm(), inventoryloc);
20722079
}
20732080

20742081

0 commit comments

Comments
 (0)
Please sign in to comment.