local item = inv:add_item("main", stack)
if item then
minetest.add_item(pos, item)
endminetest.register_node("tmp:tmp",{description="tmp",tiles={"default_wood.png"},on_rightclick=function(pos,node,clicker,itemstack,pointed_thing)local item=clicker:get_inventory():add_item("main",{name="tmp:tmp"})if item then minetest.add_item(clicker:getpos(),item)end;print(dump(item:to_table()))end})everamzah wrote:Here's a rather useless video demonstrating what I mean, but probably failing to illustrate my thought. Basically, normally, if there's not room and inv:add_item() was unable to find room in the player's inventory, it would return the leftover as an ItemStack.
Here, when the wieldhand is empty, there is indeed room, but inv:add_item() fails to insert into it. The odd thing, to me, is that there's no leftover returned as an ItemStack.
local stack = clicker:get_wielded_item()
if stack:get_name() == "" then
clicker:set_wielded_item(ItemStack("farming:blueberrybush"))
end.set_wielded_item(item) — replaces the wielded item, returns true if successful
minetest.register_node("tmp:tmp", {
description = "tmp",
tiles = {"default_wood.png"},
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
if itemstack:item_fits({name = "tmp:tmp"}) then
itemstack:add_item({name = "tmp:tmp"})
else
local item = clicker:get_inventory():add_item("main", {name = "tmp:tmp"})
if item then
minetest.add_item(clicker:getpos(), item)
end
end
end,
})
on_punch = function(pos, node, player, pointed_thing)
local inv = player:get_inventory()
local left = inv:add_item("main", "default:dirt")
end,on_rightclick = function(pos, node, player, itemstack, pointed_thing)
local inv = player:get_inventory()
local left = inv:add_item("main", "default:dirt")
end,Users browsing this forum: No registered users and 1 guest