mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
CSM/SSM: Add on_mods_loaded callback (#7411)
* CSM/SSM: Add on_mods_loaded callback
This commit is contained in:
parent
a2de439a91
commit
ccc3af128c
12 changed files with 50 additions and 0 deletions
|
@ -172,6 +172,8 @@ void Client::loadMods()
|
|||
for (const ModSpec &mod : m_mods)
|
||||
m_script->loadModFromMemory(mod.name);
|
||||
|
||||
// Run a callback when mods are loaded
|
||||
m_script->on_mods_loaded();
|
||||
m_mods_loaded = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "common/c_content.h"
|
||||
#include "s_item.h"
|
||||
|
||||
void ScriptApiClient::on_mods_loaded()
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
// Get registered shutdown hooks
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "registered_on_mods_loaded");
|
||||
// Call callbacks
|
||||
runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
|
||||
}
|
||||
|
||||
void ScriptApiClient::on_shutdown()
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
|
|
@ -37,6 +37,9 @@ class ClientEnvironment;
|
|||
class ScriptApiClient : virtual public ScriptApiBase
|
||||
{
|
||||
public:
|
||||
// Calls when mods are loaded
|
||||
void on_mods_loaded();
|
||||
|
||||
// Calls on_shutdown handlers
|
||||
void on_shutdown();
|
||||
|
||||
|
|
|
@ -147,6 +147,17 @@ bool ScriptApiServer::on_chat_message(const std::string &name,
|
|||
return ate;
|
||||
}
|
||||
|
||||
void ScriptApiServer::on_mods_loaded()
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
// Get registered shutdown hooks
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "registered_on_mods_loaded");
|
||||
// Call callbacks
|
||||
runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
|
||||
}
|
||||
|
||||
void ScriptApiServer::on_shutdown()
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
|
|
@ -30,6 +30,9 @@ public:
|
|||
// Returns true if script handled message
|
||||
bool on_chat_message(const std::string &name, const std::string &message);
|
||||
|
||||
// Calls when mods are loaded
|
||||
void on_mods_loaded();
|
||||
|
||||
// Calls on_shutdown handlers
|
||||
void on_shutdown();
|
||||
|
||||
|
|
|
@ -75,6 +75,9 @@ void ServerModManager::loadMods(ServerScripting *script)
|
|||
std::chrono::steady_clock::now() - t).count() * 0.001f
|
||||
<< " seconds" << std::endl;
|
||||
}
|
||||
|
||||
// Run a callback when mods are loaded
|
||||
script->on_mods_loaded();
|
||||
}
|
||||
|
||||
// clang-format on
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue