local mod_name = minetest.get_current_modname()
local S = minetest.get_translator(mod_name)




local formspec
do
    local fs, size = pmb_inventory.player.get_formspec(nil)
    local y = 12-size.y-2.3

    formspec = "size[24.00,12.0]"..
    pmb_inventory.get_9patch(4.5, y-2.79, 11, 4, pmb_inventory.get_bg9patch_texture("#65958d"), "false", 32)..
    pmb_inventory.get_itemslot_array(5, y-2.2, 10, 3)..
    "list[context;main;5,"..tostring(y-2.2)..";10,3;]"..
    "listring[context;main]"..
    "listring[current_player;main]"..
    fs
end



local function set_up_inventory(pos)
    local meta = minetest.get_meta(pos)
    local inv = meta:get_inventory()
    if meta:get_string("formspec") == formspec then return end
    inv:set_size("main", 10*3)
    meta:set_string("formspec", formspec)
    meta:set_string("infotext", "Chest");
    return true
end

minetest.register_node('pmb_storage:chest', {
    description = pmb_util.desc(S("Wooden Chest"), "grey"),
    _tt_long_desc = S("Stores items."),
    groups = { oddly_breakable_by_hand = 2, choppy = 1, solid = 1, suffocates = 0, wood = 1, item_wooden_chest = 1, storage = 1, chest = 1 },
    tiles = {"pmb_storage_chest.png"},
    mesh = "pmb_storage_chest.b3d",
    drawtype = "mesh",
    sounds = pmb_sounds.default_wood(),
    paramtype2 = "facedir",
    on_place = function(itemstack, placer, pointed_thing)
        return minetest.rotate_and_place(itemstack, placer, pointed_thing, nil, {force_floor=true})
    end,
    on_construct = function(pos)
        set_up_inventory(pos)
    end,
    on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
        set_up_inventory(pos)
    end,
    on_destruct = function(pos)
        pmb_inventory.drop_contents(pos)
    end,
    _on_node_update = function(pos, cause)
        if set_up_inventory(pos) then return true end
    end
})


if true then
    pmb_tcraft.register_group_craft({
            output = "pmb_storage:chest",
            items = {},
            group = "planks",
            group_count = 8
    })
end
