Code: Select all
cabinet_num=0
form=""
kit_wood_cabs = {
["kitchen_wooden_cabinet_1"] = {
--form_size="",
{mode="closed", button = "kwc1_1", img_button = "close_button.png", listname = "kwc1_1", inv_list={}, inv_size=1},
{mode="closed", button = "kwc1_2", img_button = "close_button.png", listname = "kwc1_2", inv_list={}, inv_size=1}
},
["kitchen_wooden_cabinet_2"] = {
--form_size="",
{mode="opened", button = "kwc2_1", img_button = "open_button.png", listname = "kwc2_1", inv_list={}, inv_size=4*2},
{mode="closed", button = "kwc2_2", img_button = "close_button.png", listname = "kwc2_2", inv_list={}, inv_size=0},
not_in_creative_inventory=1
},
["kitchen_wooden_cabinet_3"] = {
--form_size="",
{mode="closed", button = "kwc3_1", img_button = "close_button.png", listname = "kwc3_1", inv_list={}, inv_size=0},
{mode="opened", button = "kwc3_2", img_button = "open_button.png", listname = "kwc3_2", inv_list={}, inv_size=4*2},
not_in_creative_inventory=1
},
["kitchen_wooden_cabinet_4"] = {
--form_size="",
{mode="opened", button = "kwc4_1", img_button = "open_button.png", listname = "kwc4_1", inv_list={}, inv_size=4*2},
{mode="opened", button = "kwc4_2", img_button = "open_button.png", listname = "kwc4_2", inv_list={}, inv_size=4*2},
not_in_creative_inventory=1
}
}
for cab, cab_boxes in pairs(kit_wood_cabs) do
cabinet_num = cabinet_num + 1
minetest.register_node("luxury_decor:"..cab, {
description = "Kitchen Wooden Cabinet",
visual_scale = 0.5,
inventory_image = "kitchen_wooden_cabinet_with_two_drawers.png",
mesh = cab..".obj",
tiles = {"bright_wood_material.png"},
paramtype = "light",
paramtype2 = "facedir",
groups = {choppy=3, not_in_creative_inventory = cab_boxes["not_in_creative_inventory"]},
drawtype = "mesh",
collision_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}
},
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}
},
sounds = default.node_sound_wood_defaults(),
on_construct = function (pos)
local name = minetest.get_node(pos).name
local img_button1 = "image_button[0.5, 0;1, 2;" .. cab_boxes[1].img_button ..";" .. cab_boxes[1].button .. ";]"
local img_button2 = "image_button[0.5, 3;1, 2;" .. cab_boxes[2].img_button .. ";" .. cab_boxes[2].button .. ";]"
local list1 = "list[nodemeta:".. pos.x .. "," .. pos.y .. "," .. pos.z .. ";".. cab_boxes[1].listname .. ";1.5, 0;4, 2]"
local list2 = "list[nodemeta:".. pos.x .. "," .. pos.y .. "," .. pos.z .. ";".. cab_boxes[2].listname .. ";1.5, 1;4, 2]"
form = "size[6,10]" .. img_button1 .. img_button2 .. list1 .. list2
-- cabinets.put_data_into_cabinet(pos, "kitchen_wooden_cabinet", tostring(cabinet_num), cab_boxes, {name=name, data=form})
-- local inv = minetest.get_inventory({type="node", pos=pos})
local inv=minetest.get_meta(pos):get_inventory()
inv:set_size(cab_boxes[1].listname, cab_boxes[1].inv_size)
inv:set_size(cab_boxes[2].listname, cab_boxes[2].inv_size)
inv:set_list(cab_boxes[1].listname, cab_boxes[1].inv_list)
inv:set_list(cab_boxes[2].listname, cab_boxes[2].inv_list)
--print(dump(inv:get_list(cab_boxes[1].listname)))
--print(dump(inv:get_list(cab_boxes[2].listname)))
-- Fills "form_size" of each cabinet with needed size and "form_data" of each box with datas to build formspec with lists.
--[[
for cab2, cab_boxes2 in pairs(kit_wood_cabs) do
cab_boxes2[cab2][form_size] = "size[8,4]"
for box_num, cab_data in ipairs(cab_boxes2[2]) do
cab_data[box_num][form_data] = inv_elems[1] .. "0.2, 0.1;0.5, 2" .. inv_elems[2]
if cab_data[
end
end
--]]
end,
on_rightclick = function (pos, node, clicker, itemstack, pointed_thing)
minetest.show_formspec(clicker:get_player_name(), cab, form)
end,
on_receive_fields = function (pos, formname, fields, sender)
minetest.debug("AAAAAAAAAAAAAAAAAAA")
local name = minetest.get_node(pos).name
local generalized_name = string.match(name, '^._-')
--[[for _, depart in ipairs(kit_wood_cabs[name]) do
if depart[button] == formname then
if depart[mode] == "closed" then
for _, depart2 in ipairs(kit_wood_cabs) do
if ]]
-- local defined_mode = cabinets.define_mode(formname, name)
if defined_mode == "closed" then
cabinets.open(sender, pos, cabinets.define_needed_cabinet(formname, name), generalized_name, formname, form)
elseif defined_mode == "opened" then
cabinets.close(sender, pos, cabinets.define_needed_cabinet(formname, name), generalized_name, formname, form)
end
end
})
end
i dont know why, but set inv:set_size before inv:set_list then it dont return nil
if you believe minetest.get_inventory is messing, try minetest.get_meta(pos):get_inventory() instead
removed .. "]" from
form = "size[6,10]" .. img_button1 .. img_button2 .. list1 .. list2 .. "]"
i don't know how the rest of the stuff works, but if it not working after restarting, is because the "form" variable's content is set in on_construct