]> git.lizzy.rs Git - minetest.git/commitdiff
Disable inventory if player's inventory formspec is blank (#11827)
authorROllerozxa <temporaryemail4meh+github@gmail.com>
Mon, 13 Dec 2021 16:43:29 +0000 (17:43 +0100)
committerGitHub <noreply@github.com>
Mon, 13 Dec 2021 16:43:29 +0000 (17:43 +0100)
doc/lua_api.txt
src/client/game.cpp

index e26497555c57bce4d1ed3d2708d372d9c50dc1b2..ee7d631018b443902a9e2018a598e1a0dd1872f4 100644 (file)
@@ -6690,6 +6690,7 @@ object you are working with still exists.
 * `set_inventory_formspec(formspec)`
     * Redefine player's inventory form
     * Should usually be called in `on_joinplayer`
+    * If `formspec` is `""`, the player's inventory is disabled.
 * `get_inventory_formspec()`: returns a formspec string
 * `set_formspec_prepend(formspec)`:
     * the formspec string will be added to every formspec shown to the user,
index 7394097613cac06bdc3a7c3e89b9851d3338f87a..853a52ecfb811fa224dc041996677321a9e56349 100644 (file)
@@ -2060,15 +2060,22 @@ void Game::openInventory()
        InventoryLocation inventoryloc;
        inventoryloc.setCurrentPlayer();
 
-       if (!client->modsLoaded()
-                       || !client->getScript()->on_inventory_open(fs_src->m_client->getInventory(inventoryloc))) {
-               TextDest *txt_dst = new TextDestPlayerInventory(client);
-               auto *&formspec = m_game_ui->updateFormspec("");
-               GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(),
-                       &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound);
+       if (client->modsLoaded() && client->getScript()->on_inventory_open(fs_src->m_client->getInventory(inventoryloc))) {
+               delete fs_src;
+               return;
+       }
 
-               formspec->setFormSpec(fs_src->getForm(), inventoryloc);
+       if (fs_src->getForm().empty()) {
+               delete fs_src;
+               return;
        }
+
+       TextDest *txt_dst = new TextDestPlayerInventory(client);
+       auto *&formspec = m_game_ui->updateFormspec("");
+       GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(),
+               &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound);
+
+       formspec->setFormSpec(fs_src->getForm(), inventoryloc);
 }