--- Container which drops inventory on right click

minetest.register_node("hwmod:container_drop", {
  description = "spawn loot droppable container",
  tiles = {"hwmod_node.png"},
  groups = {cracky = 1},
  on_construct = function(pos)
    local meta = minetest.get_meta(pos)
    meta:set_string("formspec", "size[8,9]" ..
            "list[current_name;main;0,0;8,4;]" ..
            "list[current_player;main;0,5;8,4;]")
    meta:set_string("infotext", "Your Node")
    local inv = meta:get_inventory()
    inv:set_size("main", 1 * 4)
    local stack = ItemStack("default:stone 1")
    inv:add_item("main", stack)
    local stack = ItemStack("default:stone 1")
    inv:add_item("main", stack)
    local stack = ItemStack("default:stone 1")
    inv:add_item("main", stack)
  end,
  on_rightclick = function(pos, node, clicker, itemstack)
    print("must drop")
    local meta = minetest.get_meta(pos)
    local inv = meta:get_inventory()
    local drops = inv:get_list("main")
    for _, stack in ipairs(drops) do
        if stack then
            minetest.add_item(pos, stack)
        end
    end
    -- Clear the inventory after dropping items
    inv:set_list("main", {})
    return itemstack
  end,
})

Изменить пасту