diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/game.cpp | 11 | ||||
-rw-r--r-- | src/script/cpp_api/s_client.cpp | 22 | ||||
-rw-r--r-- | src/script/cpp_api/s_client.h | 1 |
3 files changed, 29 insertions, 5 deletions
diff --git a/src/game.cpp b/src/game.cpp index 66c8859c8..612bd2536 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -3895,17 +3895,20 @@ void Game::handleDigging(GameRunData *runData, const PointedThing &pointed, const v3s16 &nodepos, const ToolCapabilities &playeritem_toolcap, f32 dtime) { + + LocalPlayer *player = client->getEnv().getLocalPlayer(); + ClientMap &map = client->getEnv().getClientMap(); + MapNode n = client->getEnv().getClientMap().getNodeNoEx(nodepos); + if (!runData->digging) { infostream << "Started digging" << std::endl; + if (client->getScript()->on_punchnode(nodepos, n)) + return; client->interact(0, pointed); runData->digging = true; runData->ldown_for_dig = true; } - LocalPlayer *player = client->getEnv().getLocalPlayer(); - ClientMap &map = client->getEnv().getClientMap(); - MapNode n = client->getEnv().getClientMap().getNodeNoEx(nodepos); - // NOTE: Similar piece of code exists on the server side for // cheat detection. // Get digging parameters diff --git a/src/script/cpp_api/s_client.cpp b/src/script/cpp_api/s_client.cpp index 2c8fee334..8c5e3796b 100644 --- a/src/script/cpp_api/s_client.cpp +++ b/src/script/cpp_api/s_client.cpp @@ -157,4 +157,24 @@ bool ScriptApiClient::on_dignode(v3s16 p, MapNode node) runCallbacks(2, RUN_CALLBACKS_MODE_OR); bool blocked = lua_toboolean(L, -1); return blocked; -}
\ No newline at end of file +} + +bool ScriptApiClient::on_punchnode(v3s16 p, MapNode node) +{ + SCRIPTAPI_PRECHECKHEADER + + INodeDefManager *ndef = getClient()->ndef(); + + // Get core.registered_on_punchgnode + lua_getglobal(L, "core"); + lua_getfield(L, -1, "registered_on_punchnode"); + + // Push data + push_v3s16(L, p); + pushnode(L, node, ndef); + + // Call functions + runCallbacks(2, RUN_CALLBACKS_MODE_OR); + bool blocked = lua_toboolean(L, -1); + return blocked; +} diff --git a/src/script/cpp_api/s_client.h b/src/script/cpp_api/s_client.h index 09fd3a691..93e9558f2 100644 --- a/src/script/cpp_api/s_client.h +++ b/src/script/cpp_api/s_client.h @@ -46,5 +46,6 @@ public: void on_formspec_input(const std::string &formname, const StringMap &fields); bool on_dignode(v3s16 p, MapNode node); + bool on_punchnode(v3s16 p, MapNode node); }; #endif |