Skip to content

Commit

Permalink
[CSM] Add enable_client_modding param (default: false)
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzhul committed Mar 13, 2017
1 parent 0727bb3 commit 44ca9c9
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 14 deletions.
3 changes: 3 additions & 0 deletions builtin/settingtypes.txt
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions minetest.conf.example
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/client.cpp
Expand Up @@ -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));
Expand All @@ -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);
}
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/client.h
Expand Up @@ -572,6 +572,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
}

ClientScripting *getScript() { return m_script; }
const bool moddingEnabled() const { return m_modding_enabled; }

inline void pushToEventQueue(const ClientEvent &event)
{
Expand Down Expand Up @@ -722,6 +723,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
bool m_cache_use_tangent_vertices;

ClientScripting *m_script;
bool m_modding_enabled;

DISABLE_CLASS_COPY(Client);
};
Expand Down
4 changes: 3 additions & 1 deletion src/clientenvironment.cpp
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/defaultsettings.cpp
Expand Up @@ -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");
Expand Down
21 changes: 13 additions & 8 deletions src/game.cpp
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand All @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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);
}
Expand Down
6 changes: 4 additions & 2 deletions src/network/clientpackethandler.cpp
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/script/cpp_api/s_client.cpp
Expand Up @@ -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)
Expand Down

0 comments on commit 44ca9c9

Please sign in to comment.