Talk:InvRef

From Minetest Developer Wiki
Revision as of 10:44, 10 May 2014 by Hybrid Dog (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

please add something like room_for_items() to test if more items can find place in the inventory Hybrid Dog (talk) 14:21, 10 May 2014 (MSK)

	on_drop = function(itemstack, dropper)
		local inv = dropper:get_inventory()
		if not inv then
			return
		end
		local free_slots = 0
		for _,i in ipairs(inv:get_list("main")) do
			if i:get_count() == 0 then
				free_slots = free_slots+1
			end
		end
		if free_slots < 2 then
			return
		end
		itemstack:take_item()
		inv:add_item("main", "nether:fruit_leaf")
		inv:add_item("main", "nether:fruit_no_leaf")
		return itemstack
	end,

I need to do it this way instead. Hybrid Dog (talk) 14:44, 10 May 2014 (MSK)