kaeza

Minetest: Move items between inventory lists

Dec 17th, 2013
62
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.         while stack and not stack:is_empty() do
  9.             local oneitem = ItemStack({name=stack:get_name(), count=1})
  10.             if not d_inv:room_for_item(d_listname, oneitem) then
  11.                 break
  12.             end
  13.             stack = d_inv:add_item(d_listname, stack)
  14.         end
  15.         s_inv:set_stack(s_listname, s_index, stack)
  16.         s_index = s_index + 1
  17.     end
  18.  
  19. end
RAW Paste Data