mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-22 17:18:39 +00:00
[CSM] Add on_dignode
callback (#5140)
This commit is contained in:
parent
ba66fce833
commit
073f5cf03d
6 changed files with 57 additions and 13 deletions
34
src/game.cpp
34
src/game.cpp
|
@ -3967,20 +3967,8 @@ void Game::handleDigging(GameRunData *runData,
|
|||
client->setCrack(runData->dig_index, nodepos);
|
||||
} else {
|
||||
infostream << "Digging completed" << std::endl;
|
||||
client->interact(2, pointed);
|
||||
client->setCrack(-1, v3s16(0, 0, 0));
|
||||
bool is_valid_position;
|
||||
MapNode wasnode = map.getNodeNoEx(nodepos, &is_valid_position);
|
||||
if (is_valid_position)
|
||||
client->removeNode(nodepos);
|
||||
|
||||
if (m_cache_enable_particles) {
|
||||
const ContentFeatures &features =
|
||||
client->getNodeDefManager()->get(wasnode);
|
||||
client->getParticleManager()->addDiggingParticles(client, smgr,
|
||||
player, nodepos, wasnode, features);
|
||||
}
|
||||
|
||||
|
||||
runData->dig_time = 0;
|
||||
runData->digging = false;
|
||||
|
||||
|
@ -3999,6 +3987,26 @@ void Game::handleDigging(GameRunData *runData,
|
|||
if (runData->nodig_delay_timer < mindelay)
|
||||
runData->nodig_delay_timer = mindelay;
|
||||
|
||||
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;
|
||||
}
|
||||
client->removeNode(nodepos);
|
||||
}
|
||||
|
||||
client->interact(2, pointed);
|
||||
|
||||
if (m_cache_enable_particles) {
|
||||
const ContentFeatures &features =
|
||||
client->getNodeDefManager()->get(wasnode);
|
||||
client->getParticleManager()->addDiggingParticles(client, smgr,
|
||||
player, nodepos, wasnode, features);
|
||||
}
|
||||
|
||||
|
||||
// Send event to trigger sound
|
||||
MtEvent *e = new NodeDugEvent(nodepos, wasnode);
|
||||
client->event()->put(e);
|
||||
|
|
|
@ -21,6 +21,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "s_client.h"
|
||||
#include "s_internal.h"
|
||||
#include "client.h"
|
||||
#include "common/c_converter.h"
|
||||
#include "common/c_content.h"
|
||||
|
||||
void ScriptApiClient::on_shutdown()
|
||||
{
|
||||
|
@ -136,3 +138,23 @@ void ScriptApiClient::on_formspec_input(const std::string &formname,
|
|||
}
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_OR_SC);
|
||||
}
|
||||
|
||||
bool ScriptApiClient::on_dignode(v3s16 p, MapNode node)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
INodeDefManager *ndef = getClient()->ndef();
|
||||
|
||||
// Get core.registered_on_dignode
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "registered_on_dignode");
|
||||
|
||||
// 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;
|
||||
}
|
|
@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
#include "cpp_api/s_base.h"
|
||||
#include "util/string.h"
|
||||
#include "mapnode.h"
|
||||
|
||||
#ifdef _CRT_MSVCP_CURRENT
|
||||
#include <cstdint>
|
||||
|
@ -43,5 +44,7 @@ public:
|
|||
void on_death();
|
||||
void environment_step(float dtime);
|
||||
void on_formspec_input(const std::string &formname, const StringMap &fields);
|
||||
|
||||
bool on_dignode(v3s16 p, MapNode node);
|
||||
};
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue