CSM/SSM: Add on_mods_loaded callback (#7411)

* CSM/SSM: Add on_mods_loaded callback
This commit is contained in:
Loïc Blot 2018-06-06 12:53:59 +02:00 committed by GitHub
parent a2de439a91
commit ccc3af128c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 50 additions and 0 deletions

@ -59,6 +59,7 @@ local function make_registration()
end
core.registered_globalsteps, core.register_globalstep = make_registration()
core.registered_on_mods_loaded, core.register_on_mods_loaded = make_registration()
core.registered_on_shutdown, core.register_on_shutdown = make_registration()
core.registered_on_receiving_chat_message, core.register_on_receiving_chat_message = make_registration()
core.registered_on_sending_chat_message, core.register_on_sending_chat_message = make_registration()

@ -569,6 +569,7 @@ core.unregister_biome = make_wrap_deregistration(core.register_biome, core.clear
core.registered_on_chat_messages, core.register_on_chat_message = make_registration()
core.registered_globalsteps, core.register_globalstep = make_registration()
core.registered_playerevents, core.register_playerevent = make_registration()
core.registered_on_mods_loaded, core.register_on_mods_loaded = make_registration()
core.registered_on_shutdown, core.register_on_shutdown = make_registration()
core.registered_on_punchnodes, core.register_on_punchnode = make_registration()
core.registered_on_placenodes, core.register_on_placenode = make_registration()

@ -200,3 +200,8 @@ core.register_chatcommand("text", {
return core.localplayer:hud_change(id, "text", param)
end,
})
core.register_on_mods_loaded(function()
core.log("Yeah preview mod is loaded with other CSM mods.")
end)

@ -648,6 +648,8 @@ Call these functions only at load time!
* `minetest.register_globalstep(func(dtime))`
* Called every client environment step, usually interval of 0.1s
* `minetest.register_on_mods_loaded(func())`
* Called just after mods have finished loading.
* `minetest.register_on_shutdown(func())`
* Called before client shutdown
* **Warning**: If the client terminates abnormally (i.e. crashes), the registered

@ -2793,6 +2793,9 @@ Call these functions only at load time!
* `minetest.register_globalstep(func(dtime))`
* Called every server step, usually interval of 0.1s
* `minetest.register_on_mods_loaded(func())`
* Called after mods have finished loading and before the media is cached or the
aliases handled.
* `minetest.register_on_shutdown(func())`
* Called before server shutdown
* **Warning**: If the server terminates abnormally (i.e. crashes), the

@ -765,4 +765,9 @@ minetest.log("experimental modname="..dump(minetest.get_current_modname()))
minetest.log("experimental modpath="..dump(minetest.get_modpath("experimental")))
minetest.log("experimental worldpath="..dump(minetest.get_worldpath()))
core.register_on_mods_loaded(function()
core.log("Yeah experimental loaded mods.")
end)
-- END

@ -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