From: nerzhul Date: Mon, 13 Mar 2017 14:55:30 +0000 (+0100) Subject: [CSM] Add enable_client_modding param (default: false) X-Git-Tag: 0.4.16~390 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=44ca9c9cb2079fa97068adb8ee894c5ae13a9975;p=oweals%2Fminetest.git [CSM] Add enable_client_modding param (default: false) --- diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index cba03e983..ff17973fa 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -264,6 +264,9 @@ show_entity_selectionbox (Show entity selection boxes) bool true # when connecting to the server. enable_remote_media_server (Connect to external media server) bool true +# Enable Lua modding support on client. +enable_client_modding (Client modding) bool false + # URL to the server list displayed in the Multiplayer Tab. serverlist_url (Serverlist URL) string servers.minetest.net diff --git a/minetest.conf.example b/minetest.conf.example index 8caeeb7d2..283dc13f1 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -282,6 +282,11 @@ # type: bool # enable_remote_media_server = true +# Enable Lua modding support on client. +# This support is experimental and API can change. +# type: bool +enable_client_modding (Client modding) bool false + # URL to the server list displayed in the Multiplayer Tab. # type: string # serverlist_url = servers.minetest.net diff --git a/src/client.cpp b/src/client.cpp index 049616c63..4ddabd814 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -248,7 +248,8 @@ Client::Client( m_recommended_send_interval(0.1), m_removed_sounds_check_timer(0), m_state(LC_Created), - m_localdb(NULL) + m_localdb(NULL), + m_script(NULL) { // Add local player m_env.setLocalPlayer(new LocalPlayer(this, playername)); @@ -262,6 +263,7 @@ Client::Client( g_settings->getBool("enable_bumpmapping") || g_settings->getBool("enable_parallax_occlusion")); + m_modding_enabled = g_settings->getBool("enable_client_modding"); m_script = new ClientScripting(this); m_env.setScript(m_script); } @@ -270,6 +272,11 @@ void Client::initMods() { m_script->loadMod(getBuiltinLuaPath() + DIR_DELIM "init.lua", BUILTIN_MOD_NAME); + // If modding is not enabled, don't load mods, just builtin + if (!m_modding_enabled) { + return; + } + ClientModConfiguration modconf(getClientModsLuaPath()); std::vector mods = modconf.getMods(); std::vector unsatisfied_mods = modconf.getUnsatisfiedMods(); @@ -327,6 +334,7 @@ const ModSpec* Client::getModSpec(const std::string &modname) const void Client::Stop() { + // Don't disable this part when modding is disabled, it's used in builtin m_script->on_shutdown(); //request all client managed threads to stop m_mesh_update_thread.stop(); diff --git a/src/client.h b/src/client.h index dc4469350..7f9cc559b 100644 --- a/src/client.h +++ b/src/client.h @@ -572,6 +572,7 @@ public: } ClientScripting *getScript() { return m_script; } + const bool moddingEnabled() const { return m_modding_enabled; } inline void pushToEventQueue(const ClientEvent &event) { @@ -722,6 +723,7 @@ private: bool m_cache_use_tangent_vertices; ClientScripting *m_script; + bool m_modding_enabled; DISABLE_CLASS_COPY(Client); }; diff --git a/src/clientenvironment.cpp b/src/clientenvironment.cpp index 1175d00c0..7a74c897c 100644 --- a/src/clientenvironment.cpp +++ b/src/clientenvironment.cpp @@ -245,7 +245,9 @@ void ClientEnvironment::step(float dtime) } } - m_script->environment_step(dtime); + if (m_client->moddingEnabled()) { + m_script->environment_step(dtime); + } /* A quick draft of lava damage diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index d67a60b07..fbf15b2ea 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -54,6 +54,7 @@ void set_default_settings(Settings *settings) settings->setDefault("curl_file_download_timeout", "300000"); settings->setDefault("curl_verify_cert", "true"); settings->setDefault("enable_remote_media_server", "true"); + settings->setDefault("enable_client_modding", "false"); // Keymap settings->setDefault("remote_port", "30000"); diff --git a/src/game.cpp b/src/game.cpp index 612bd2536..10ec5d594 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -179,6 +179,8 @@ struct LocalFormspecHandler : public TextDest { return; } } + + // Don't disable this part when modding is disabled, it's used in builtin m_client->getScript()->on_formspec_input(m_formname, fields); } @@ -3185,9 +3187,10 @@ void Game::processClientEvents(CameraOrientation *cam, float *damage_flash) for ( ; event.type != CE_NONE; event = client->getClientEvent()) { - if (event.type == CE_PLAYER_DAMAGE && - client->getHP() != 0) { - client->getScript()->on_damage_taken(event.player_damage.amount); + if (event.type == CE_PLAYER_DAMAGE && client->getHP() != 0) { + if (client->moddingEnabled()) { + client->getScript()->on_damage_taken(event.player_damage.amount); + } *damage_flash += 95.0 + 3.2 * event.player_damage.amount; *damage_flash = MYMIN(*damage_flash, 127.0); @@ -3202,6 +3205,7 @@ void Game::processClientEvents(CameraOrientation *cam, float *damage_flash) cam->camera_yaw = event.player_force_move.yaw; cam->camera_pitch = event.player_force_move.pitch; } else if (event.type == CE_DEATHSCREEN) { + // This should be enabled for death formspec in builtin client->getScript()->on_death(); /* Handle visualization */ @@ -3902,7 +3906,7 @@ void Game::handleDigging(GameRunData *runData, if (!runData->digging) { infostream << "Started digging" << std::endl; - if (client->getScript()->on_punchnode(nodepos, n)) + if (client->moddingEnabled() && client->getScript()->on_punchnode(nodepos, n)) return; client->interact(0, pointed); runData->digging = true; @@ -3971,7 +3975,7 @@ void Game::handleDigging(GameRunData *runData, } else { infostream << "Digging completed" << std::endl; client->setCrack(-1, v3s16(0, 0, 0)); - + runData->dig_time = 0; runData->digging = false; @@ -3993,9 +3997,10 @@ void Game::handleDigging(GameRunData *runData, bool is_valid_position; MapNode wasnode = map.getNodeNoEx(nodepos, &is_valid_position); if (is_valid_position) { - bool block = client->getScript()->on_dignode(nodepos, wasnode); - if (block) { - return; + if (client->moddingEnabled()) { + if (client->getScript()->on_dignode(nodepos, wasnode)) { + return; + } } client->removeNode(nodepos); } diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index 97fa93e95..9bcc58110 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -413,7 +413,7 @@ void Client::handleCommand_ChatMessage(NetworkPacket* pkt) } // If chat message not consummed by client lua API - if (!m_script->on_receiving_message(wide_to_utf8(message))) { + if (!moddingEnabled() || !m_script->on_receiving_message(wide_to_utf8(message))) { pushToChatQueue(message); } } @@ -526,7 +526,9 @@ void Client::handleCommand_HP(NetworkPacket* pkt) player->hp = hp; - m_script->on_hp_modification(hp); + if (moddingEnabled()) { + m_script->on_hp_modification(hp); + } if (hp < oldhp) { // Add to ClientEvent queue diff --git a/src/script/cpp_api/s_client.cpp b/src/script/cpp_api/s_client.cpp index 8c5e3796b..154dd6194 100644 --- a/src/script/cpp_api/s_client.cpp +++ b/src/script/cpp_api/s_client.cpp @@ -155,8 +155,7 @@ bool ScriptApiClient::on_dignode(v3s16 p, MapNode node) // Call functions runCallbacks(2, RUN_CALLBACKS_MODE_OR); - bool blocked = lua_toboolean(L, -1); - return blocked; + return lua_toboolean(L, -1); } bool ScriptApiClient::on_punchnode(v3s16 p, MapNode node)