-- default: minetest.item_place
on_secondary_use = function(itemstack, user, pointed_thing),
- -- Same as on_place but called when pointing at nothing.
+ -- Same as on_place but called when not pointing at a node.
-- The user may be any ObjectRef or nil.
- -- pointed_thing: always { type = "nothing" }
+ -- default: nil
on_drop = function(itemstack, dropper, pos),
-- Shall drop item and return the leftover itemstack.
<< pointed_object->getDescription() << std::endl;
// Do stuff
+ if (m_script->item_OnSecondaryUse(
+ selected_item, playersao, pointed)) {
+ if (playersao->setWieldedItem(selected_item)) {
+ SendInventory(playersao, true);
+ }
+ }
+
pointed_object->rightClick(playersao);
} else if (m_script->item_OnPlace(
selected_item, playersao, pointed)) {
actionstream << player->getName() << " activates "
<< selected_item.name << std::endl;
+ pointed.type = POINTEDTHING_NOTHING; // can only ever be NOTHING
+
if (m_script->item_OnSecondaryUse(
- selected_item, playersao)) {
+ selected_item, playersao, pointed)) {
if (playersao->setWieldedItem(selected_item)) {
SendInventory(playersao, true);
}
return true;
}
-bool ScriptApiItem::item_OnSecondaryUse(ItemStack &item, ServerActiveObject *user)
+bool ScriptApiItem::item_OnSecondaryUse(ItemStack &item,
+ ServerActiveObject *user, const PointedThing &pointed)
{
SCRIPTAPI_PRECHECKHEADER
LuaItemStack::create(L, item);
objectrefGetOrCreate(L, user);
- PointedThing pointed;
- pointed.type = POINTEDTHING_NOTHING;
pushPointedThing(pointed);
PCALL_RES(lua_pcall(L, 3, 1, error_handler));
if (!lua_isnil(L, -1)) {
bool item_OnUse(ItemStack &item,
ServerActiveObject *user, const PointedThing &pointed);
bool item_OnSecondaryUse(ItemStack &item,
- ServerActiveObject *user);
+ ServerActiveObject *user, const PointedThing &pointed);
bool item_OnCraft(ItemStack &item, ServerActiveObject *user,
const InventoryList *old_craft_grid, const InventoryLocation &craft_inv);
bool item_CraftPredict(ItemStack &item, ServerActiveObject *user,