Okay, so 1.0 doesn't work perfectly. If I have several ItemStacks of the relevant node type in my inventory, only the one currently in hand gets used. I've been looking at the documentation and reading the forum, and I could use some help. Here is the relevant snippets of code where I attempt to handle the issue:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
local inv = placer:get_inventory()
...
minetest.debug('before take '..itemstack:to_string())
itemstack:take_item(1)
minetest.debug(' after take '..itemstack:to_string())
if not itemstack:is_empty() then
minetest.env:add_node(npos, {name = pname})
elseif inv:contains_item("main", pname) then
minetest.debug('before remove '..itemstack:to_string())
itemstack = inv:remove_item("main", {name=pname, count=99})
minetest.debug(' after remove '..itemstack:to_string())
...
minetest.debug('before add '..itemstack:to_string())
inv:add_item("main", itemstack)
minetest.debug(' after add '..itemstack:to_string())
Let's say I have four glass in my hand, and four elsewhere in my inventory. The output of placing those four in a shape requiring five nodes is as follows:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
before take default:glass 3
after take default:glass 2
before take default:glass 2
after take default:glass
before take default:glass
after take
before remove
after remove default:glass 7
before add default:glass 7
after add default:glass 7
Everything up to 'after remove' makes sense to me. Once we do 'after remove', I completely lose track. I've already placed four glass, so all I should have is four, unless the other nodes have been taken from the itemstack but remain in the inventory. And what about the failure to add the items back to the inventory. Indeed, the second stack of glass is gone from the inventory.
I must be reading the documentation badly, but I've even been delving into the source and I can't see where I'm going wrong. Any assistance is appreciated.