Skip to content

Commit 4d668f3

Browse files
committedNov 10, 2019
Call on_secondary_use when object is right-clicked
1 parent 3b0df97 commit 4d668f3

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed
 

‎doc/lua_api.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -6432,9 +6432,9 @@ Used by `minetest.register_node`, `minetest.register_craftitem`, and
64326432
-- default: minetest.item_place
64336433

64346434
on_secondary_use = function(itemstack, user, pointed_thing),
6435-
-- Same as on_place but called when pointing at nothing.
6435+
-- Same as on_place but called when not pointing at a node.
64366436
-- The user may be any ObjectRef or nil.
6437-
-- pointed_thing: always { type = "nothing" }
6437+
-- default: nil
64386438

64396439
on_drop = function(itemstack, dropper, pos),
64406440
-- Shall drop item and return the leftover itemstack.

‎src/network/serverpackethandler.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,13 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)
13161316
<< pointed_object->getDescription() << std::endl;
13171317

13181318
// Do stuff
1319+
if (m_script->item_OnSecondaryUse(
1320+
selected_item, playersao, pointed)) {
1321+
if (playersao->setWieldedItem(selected_item)) {
1322+
SendInventory(playersao, true);
1323+
}
1324+
}
1325+
13191326
pointed_object->rightClick(playersao);
13201327
} else if (m_script->item_OnPlace(
13211328
selected_item, playersao, pointed)) {
@@ -1376,8 +1383,10 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)
13761383
actionstream << player->getName() << " activates "
13771384
<< selected_item.name << std::endl;
13781385

1386+
pointed.type = POINTEDTHING_NOTHING; // can only ever be NOTHING
1387+
13791388
if (m_script->item_OnSecondaryUse(
1380-
selected_item, playersao)) {
1389+
selected_item, playersao, pointed)) {
13811390
if (playersao->setWieldedItem(selected_item)) {
13821391
SendInventory(playersao, true);
13831392
}

‎src/script/cpp_api/s_item.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ bool ScriptApiItem::item_OnUse(ItemStack &item,
115115
return true;
116116
}
117117

118-
bool ScriptApiItem::item_OnSecondaryUse(ItemStack &item, ServerActiveObject *user)
118+
bool ScriptApiItem::item_OnSecondaryUse(ItemStack &item,
119+
ServerActiveObject *user, const PointedThing &pointed)
119120
{
120121
SCRIPTAPI_PRECHECKHEADER
121122

@@ -126,8 +127,6 @@ bool ScriptApiItem::item_OnSecondaryUse(ItemStack &item, ServerActiveObject *use
126127

127128
LuaItemStack::create(L, item);
128129
objectrefGetOrCreate(L, user);
129-
PointedThing pointed;
130-
pointed.type = POINTEDTHING_NOTHING;
131130
pushPointedThing(pointed);
132131
PCALL_RES(lua_pcall(L, 3, 1, error_handler));
133132
if (!lua_isnil(L, -1)) {

‎src/script/cpp_api/s_item.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ScriptApiItem
4242
bool item_OnUse(ItemStack &item,
4343
ServerActiveObject *user, const PointedThing &pointed);
4444
bool item_OnSecondaryUse(ItemStack &item,
45-
ServerActiveObject *user);
45+
ServerActiveObject *user, const PointedThing &pointed);
4646
bool item_OnCraft(ItemStack &item, ServerActiveObject *user,
4747
const InventoryList *old_craft_grid, const InventoryLocation &craft_inv);
4848
bool item_CraftPredict(ItemStack &item, ServerActiveObject *user,

0 commit comments

Comments
 (0)
Please sign in to comment.