[CSM] Add enable_client_modding param (default: false)
authornerzhul <loic.blot@unix-experience.fr>
Mon, 13 Mar 2017 14:55:30 +0000 (15:55 +0100)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Mon, 13 Mar 2017 22:56:05 +0000 (23:56 +0100)
builtin/settingtypes.txt
minetest.conf.example
src/client.cpp
src/client.h
src/clientenvironment.cpp
src/defaultsettings.cpp
src/game.cpp
src/network/clientpackethandler.cpp
src/script/cpp_api/s_client.cpp

index cba03e9831361d63fdd5b79517cafc02ae8f4922..ff17973fad92d12a40405948aebaf69e8ba8479a 100644 (file)
@@ -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
 
index 8caeeb7d23d75c89807a902267f0045eae61c5f9..283dc13f158c86f5c991e9d8dcfafab0cddd270a 100644 (file)
 #    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
index 049616c63c9dbb49f4b086a1bf06efdb21c1f5b6..4ddabd8145a0b7ab5526471547c02bad306f19a8 100644 (file)
@@ -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<ModSpec> mods = modconf.getMods();
        std::vector<ModSpec> 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();
index dc4469350283b0f48aba91d01ea1fd7d11a97330..7f9cc559bcb5000fe118448a108a8b04644c6e3a 100644 (file)
@@ -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);
 };
index 1175d00c0bc837c7c4d381c88ae0dcad78315bad..7a74c897c875fd9572cbbe9895fbf0337fe064bd 100644 (file)
@@ -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
index d67a60b0780a2e9ecc584c79de38c8b1e293c07d..fbf15b2eae650fd66154596e1781ce0ca9f019d5 100644 (file)
@@ -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");
index 612bd25363d3c95c5378bd811be17b4d5cdf1e70..10ec5d59471a66542903759d934deb7c046e1037 100644 (file)
@@ -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);
                }
index 97fa93e9593a82ba9123566ed5c19fb41a900845..9bcc58110ddfb025878d181f837a751419abc439 100644 (file)
@@ -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
index 8c5e3796b1620094b0b66688737d15b8a490c8a0..154dd61947dcc5395423937fffb99e24371b9779 100644 (file)
@@ -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)