[CSM] Add enable_client_modding param (default: false)

This commit is contained in:
nerzhul 2017-03-13 15:55:30 +01:00 committed by Loïc Blot
parent 0727bb3ddd
commit 44ca9c9cb2
9 changed files with 41 additions and 14 deletions

View File

@ -264,6 +264,9 @@ show_entity_selectionbox (Show entity selection boxes) bool true
# when connecting to the server. # when connecting to the server.
enable_remote_media_server (Connect to external media server) bool true 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. # URL to the server list displayed in the Multiplayer Tab.
serverlist_url (Serverlist URL) string servers.minetest.net serverlist_url (Serverlist URL) string servers.minetest.net

View File

@ -282,6 +282,11 @@
# type: bool # type: bool
# enable_remote_media_server = true # 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. # URL to the server list displayed in the Multiplayer Tab.
# type: string # type: string
# serverlist_url = servers.minetest.net # serverlist_url = servers.minetest.net

View File

@ -248,7 +248,8 @@ Client::Client(
m_recommended_send_interval(0.1), m_recommended_send_interval(0.1),
m_removed_sounds_check_timer(0), m_removed_sounds_check_timer(0),
m_state(LC_Created), m_state(LC_Created),
m_localdb(NULL) m_localdb(NULL),
m_script(NULL)
{ {
// Add local player // Add local player
m_env.setLocalPlayer(new LocalPlayer(this, playername)); m_env.setLocalPlayer(new LocalPlayer(this, playername));
@ -262,6 +263,7 @@ Client::Client(
g_settings->getBool("enable_bumpmapping") || g_settings->getBool("enable_bumpmapping") ||
g_settings->getBool("enable_parallax_occlusion")); g_settings->getBool("enable_parallax_occlusion"));
m_modding_enabled = g_settings->getBool("enable_client_modding");
m_script = new ClientScripting(this); m_script = new ClientScripting(this);
m_env.setScript(m_script); m_env.setScript(m_script);
} }
@ -270,6 +272,11 @@ void Client::initMods()
{ {
m_script->loadMod(getBuiltinLuaPath() + DIR_DELIM "init.lua", BUILTIN_MOD_NAME); 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()); ClientModConfiguration modconf(getClientModsLuaPath());
std::vector<ModSpec> mods = modconf.getMods(); std::vector<ModSpec> mods = modconf.getMods();
std::vector<ModSpec> unsatisfied_mods = modconf.getUnsatisfiedMods(); std::vector<ModSpec> unsatisfied_mods = modconf.getUnsatisfiedMods();
@ -327,6 +334,7 @@ const ModSpec* Client::getModSpec(const std::string &modname) const
void Client::Stop() void Client::Stop()
{ {
// Don't disable this part when modding is disabled, it's used in builtin
m_script->on_shutdown(); m_script->on_shutdown();
//request all client managed threads to stop //request all client managed threads to stop
m_mesh_update_thread.stop(); m_mesh_update_thread.stop();

View File

@ -572,6 +572,7 @@ public:
} }
ClientScripting *getScript() { return m_script; } ClientScripting *getScript() { return m_script; }
const bool moddingEnabled() const { return m_modding_enabled; }
inline void pushToEventQueue(const ClientEvent &event) inline void pushToEventQueue(const ClientEvent &event)
{ {
@ -722,6 +723,7 @@ private:
bool m_cache_use_tangent_vertices; bool m_cache_use_tangent_vertices;
ClientScripting *m_script; ClientScripting *m_script;
bool m_modding_enabled;
DISABLE_CLASS_COPY(Client); DISABLE_CLASS_COPY(Client);
}; };

View 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 A quick draft of lava damage

View File

@ -54,6 +54,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("curl_file_download_timeout", "300000"); settings->setDefault("curl_file_download_timeout", "300000");
settings->setDefault("curl_verify_cert", "true"); settings->setDefault("curl_verify_cert", "true");
settings->setDefault("enable_remote_media_server", "true"); settings->setDefault("enable_remote_media_server", "true");
settings->setDefault("enable_client_modding", "false");
// Keymap // Keymap
settings->setDefault("remote_port", "30000"); settings->setDefault("remote_port", "30000");

View File

@ -179,6 +179,8 @@ struct LocalFormspecHandler : public TextDest {
return; return;
} }
} }
// Don't disable this part when modding is disabled, it's used in builtin
m_client->getScript()->on_formspec_input(m_formname, fields); 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()) { for ( ; event.type != CE_NONE; event = client->getClientEvent()) {
if (event.type == CE_PLAYER_DAMAGE && if (event.type == CE_PLAYER_DAMAGE && client->getHP() != 0) {
client->getHP() != 0) { if (client->moddingEnabled()) {
client->getScript()->on_damage_taken(event.player_damage.amount); client->getScript()->on_damage_taken(event.player_damage.amount);
}
*damage_flash += 95.0 + 3.2 * event.player_damage.amount; *damage_flash += 95.0 + 3.2 * event.player_damage.amount;
*damage_flash = MYMIN(*damage_flash, 127.0); *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_yaw = event.player_force_move.yaw;
cam->camera_pitch = event.player_force_move.pitch; cam->camera_pitch = event.player_force_move.pitch;
} else if (event.type == CE_DEATHSCREEN) { } else if (event.type == CE_DEATHSCREEN) {
// This should be enabled for death formspec in builtin
client->getScript()->on_death(); client->getScript()->on_death();
/* Handle visualization */ /* Handle visualization */
@ -3902,7 +3906,7 @@ void Game::handleDigging(GameRunData *runData,
if (!runData->digging) { if (!runData->digging) {
infostream << "Started digging" << std::endl; infostream << "Started digging" << std::endl;
if (client->getScript()->on_punchnode(nodepos, n)) if (client->moddingEnabled() && client->getScript()->on_punchnode(nodepos, n))
return; return;
client->interact(0, pointed); client->interact(0, pointed);
runData->digging = true; runData->digging = true;
@ -3971,7 +3975,7 @@ void Game::handleDigging(GameRunData *runData,
} else { } else {
infostream << "Digging completed" << std::endl; infostream << "Digging completed" << std::endl;
client->setCrack(-1, v3s16(0, 0, 0)); client->setCrack(-1, v3s16(0, 0, 0));
runData->dig_time = 0; runData->dig_time = 0;
runData->digging = false; runData->digging = false;
@ -3993,9 +3997,10 @@ void Game::handleDigging(GameRunData *runData,
bool is_valid_position; bool is_valid_position;
MapNode wasnode = map.getNodeNoEx(nodepos, &is_valid_position); MapNode wasnode = map.getNodeNoEx(nodepos, &is_valid_position);
if (is_valid_position) { if (is_valid_position) {
bool block = client->getScript()->on_dignode(nodepos, wasnode); if (client->moddingEnabled()) {
if (block) { if (client->getScript()->on_dignode(nodepos, wasnode)) {
return; return;
}
} }
client->removeNode(nodepos); client->removeNode(nodepos);
} }

View File

@ -413,7 +413,7 @@ void Client::handleCommand_ChatMessage(NetworkPacket* pkt)
} }
// If chat message not consummed by client lua API // 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); pushToChatQueue(message);
} }
} }
@ -526,7 +526,9 @@ void Client::handleCommand_HP(NetworkPacket* pkt)
player->hp = hp; player->hp = hp;
m_script->on_hp_modification(hp); if (moddingEnabled()) {
m_script->on_hp_modification(hp);
}
if (hp < oldhp) { if (hp < oldhp) {
// Add to ClientEvent queue // Add to ClientEvent queue

View File

@ -155,8 +155,7 @@ bool ScriptApiClient::on_dignode(v3s16 p, MapNode node)
// Call functions // Call functions
runCallbacks(2, RUN_CALLBACKS_MODE_OR); runCallbacks(2, RUN_CALLBACKS_MODE_OR);
bool blocked = lua_toboolean(L, -1); return lua_toboolean(L, -1);
return blocked;
} }
bool ScriptApiClient::on_punchnode(v3s16 p, MapNode node) bool ScriptApiClient::on_punchnode(v3s16 p, MapNode node)