1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Formspec: Show/update the player inv using core.show_formspec

'core.show_formspec' now shows and updates the inventory formspec as if
it was opened using the hotkey on client-side.
This commit is contained in:
SmallJoker 2025-03-30 10:59:59 +02:00
parent aba2b6638e
commit bf6ca40b27
3 changed files with 23 additions and 7 deletions

View file

@ -6872,9 +6872,10 @@ Formspec
* `core.show_formspec(playername, formname, formspec)` * `core.show_formspec(playername, formname, formspec)`
* `playername`: name of player to show formspec * `playername`: name of player to show formspec
* `formname`: name passed to `on_player_receive_fields` callbacks. * `formname`: name passed to `on_player_receive_fields` callbacks.
It should follow the `"modname:<whatever>"` naming convention. * It should follow the `"modname:<whatever>"` naming convention.
* `formname` must not be empty, unless you want to reshow * If empty: Reshows the inventory formspec. Servers and
the inventory formspec without updating it for future opens. clients >= 5.13.0 will update the inventory formspec
(`ObjectRef:set_inventory_formspec`) for future opens.
* `formspec`: formspec to display * `formspec`: formspec to display
* `core.close_formspec(playername, formname)` * `core.close_formspec(playername, formname)`
* `playername`: name of player to close formspec * `playername`: name of player to close formspec

View file

@ -2714,11 +2714,21 @@ void Game::handleClientEvent_DeathscreenLegacy(ClientEvent *event, CameraOrienta
void Game::handleClientEvent_ShowFormSpec(ClientEvent *event, CameraOrientation *cam) void Game::handleClientEvent_ShowFormSpec(ClientEvent *event, CameraOrientation *cam)
{ {
m_game_formspec.showFormSpec(*event->show_formspec.formspec, auto &fs = event->show_formspec;
*event->show_formspec.formname);
delete event->show_formspec.formspec; if (fs.formname->empty() && !fs.formspec->empty()) {
delete event->show_formspec.formname; // Overwrite the inventory formspec
LocalPlayer *player = client->getEnv().getLocalPlayer();
player->inventory_formspec = *fs.formspec;
m_game_formspec.showPlayerInventory();
} else {
m_game_formspec.showFormSpec(*fs.formspec,
*fs.formname);
}
delete fs.formspec;
delete fs.formname;
} }
void Game::handleClientEvent_ShowCSMFormSpec(ClientEvent *event, CameraOrientation *cam) void Game::handleClientEvent_ShowCSMFormSpec(ClientEvent *event, CameraOrientation *cam)

View file

@ -3397,6 +3397,11 @@ bool Server::showFormspec(const char *playername, const std::string &formspec,
if (!player) if (!player)
return false; return false;
if (formname.empty() && !formspec.empty()) {
// Overwrite the inventory formspec
player->inventory_formspec = formspec;
}
SendShowFormspecMessage(player->getPeerId(), formspec, formname); SendShowFormspecMessage(player->getPeerId(), formspec, formname);
return true; return true;
} }