aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp3
-rw-r--r--src/script/cpp_api/s_client.cpp17
-rw-r--r--src/script/cpp_api/s_client.h3
3 files changed, 22 insertions, 1 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 416320e5d..61282b463 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -3553,7 +3553,8 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
runData.repeat_rightclick_timer = 0;
if (playeritem_def.usable && isLeftPressed()) {
- if (getLeftClicked())
+ if (getLeftClicked() && (!client->moddingEnabled()
+ || !client->getScript()->on_item_use(playeritem, pointed)))
client->interact(4, pointed);
} else if (pointed.type == POINTEDTHING_NODE) {
ToolCapabilities playeritem_toolcap =
diff --git a/src/script/cpp_api/s_client.cpp b/src/script/cpp_api/s_client.cpp
index 4bc368d1d..d5ec52407 100644
--- a/src/script/cpp_api/s_client.cpp
+++ b/src/script/cpp_api/s_client.cpp
@@ -207,6 +207,23 @@ bool ScriptApiClient::on_placenode(const PointedThing &pointed, const ItemDefini
return lua_toboolean(L, -1);
}
+bool ScriptApiClient::on_item_use(const ItemStack &item, const PointedThing &pointed)
+{
+ SCRIPTAPI_PRECHECKHEADER
+
+ // Get core.registered_on_item_use
+ lua_getglobal(L, "core");
+ lua_getfield(L, -1, "registered_on_item_use");
+
+ // Push data
+ LuaItemStack::create(L, item);
+ push_pointed_thing(L, pointed);
+
+ // Call functions
+ runCallbacks(2, RUN_CALLBACKS_MODE_OR);
+ return lua_toboolean(L, -1);
+}
+
void ScriptApiClient::setEnv(ClientEnvironment *env)
{
ScriptApiBase::setEnv(env);
diff --git a/src/script/cpp_api/s_client.h b/src/script/cpp_api/s_client.h
index f252cf499..9133637a6 100644
--- a/src/script/cpp_api/s_client.h
+++ b/src/script/cpp_api/s_client.h
@@ -26,6 +26,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapnode.h"
#include "itemdef.h"
#include "util/string.h"
+#include "util/pointedthing.h"
+#include "lua_api/l_item.h"
#ifdef _CRT_MSVCP_CURRENT
#include <cstdint>
@@ -54,6 +56,7 @@ public:
bool on_dignode(v3s16 p, MapNode node);
bool on_punchnode(v3s16 p, MapNode node);
bool on_placenode(const PointedThing &pointed, const ItemDefinition &item);
+ bool on_item_use(const ItemStack &item, const PointedThing &pointed);
void setEnv(ClientEnvironment *env);
};