kaeza

Minetest: move_items v0

Dec 16th, 2013
78
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_list = s_inv:get_list(s_listname)
  4.     local d_list = d_inv:get_list(d_listname)
  5.  
  6.     local s_index = 1
  7.     local d_index = 1
  8.  
  9.     while s_index <= #s_list do
  10.         if s_list[s_index] and not s_list[s_index]:is_empty() then
  11.             while d_list[d_index] and (not d_list[d_index]:is_empty()) do
  12.                 d_index = d_index + 1
  13.             end
  14.             if d_index <= #d_list then
  15.                 d_list[d_index] = s_list[s_index]
  16.                 s_list[s_index] = nil
  17.             else
  18.                 break
  19.             end
  20.         end
  21.         s_index = s_index + 1
  22.     end
  23.  
  24.     d_inv:set_list(d_listname, d_list)
  25.     s_inv:set_list(s_listname, s_list)
  26.  
  27. end
  28.  
  29. minetest.register_tool(":default:asdf", {
  30.     inventory_image = "default_wood.png",
  31.     on_use = function(itemstack, user, pointed_thing)
  32.         local inv = user:get_inventory()
  33.         move_items(inv, "main", inv, "craft")
  34.     end,
  35. })
RAW Paste Data