Advertisement
kaeza

Minetest: move_items

Dec 16th, 2013
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.62 KB | None | 0 0
  1. local function move_items(s_inv, s_listname, d_inv, d_listname)
  2.  
  3.     local s_size = s_inv:get_size(s_listname)
  4.     local s_index = 1
  5.  
  6.     while s_index <= s_size do
  7.         local stack = s_inv:get_stack(s_listname, s_index)
  8.         if stack and not stack:is_empty() then
  9.             local leftover = d_inv:add_item(d_listname, stack)
  10.             s_inv:set_stack(s_listname, s_index, leftover)
  11.         end
  12.         s_index = s_index + 1
  13.     end
  14.  
  15. end
  16.  
  17. minetest.register_tool(":default:asdf", {
  18.     inventory_image = "default_wood.png",
  19.     on_use = function(itemstack, user, pointed_thing)
  20.         local inv = user:get_inventory()
  21.         move_items(inv, "main", inv, "craft")
  22.     end,
  23. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement