Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cabinets = {}
- cabinets_funcs = {}
- --[[Arguments:
- *cabinet - table that contains name and position of the cabinet
- *cabinet_boxes_data - table with cabinet data in what are names of cabinets are set in-world, position of each cabinet and their boxes datas, their modes ("opened"/"closed") and inventory formspecs.
- ]]
- cabinets_funcs.put_data_into_cabinet = function (cabinet, cabinet_boxes_data)
- local name = cabinet[1]
- if not cabinets[name] then
- cabinets[name] = {}
- end
- local pos = cabinet[2]
- cabinets[name][pos] = {}
- for box_name, box in pairs(cabinet_boxes_data) do
- local box = cabinet_boxes_data[box_name]
- cabinets[name][pos][box_name] = box
- local meta = minetest.get_meta(cabinets[name][pos][box_name][2])
- meta:set_string("inventory", cabinets[name][pos][box_name][4])
- --minetest.debug(dump(cabinet_boxes_data[box_name][2]))
- --minetest.debug(dump(cabinet_boxes_data[box_name][1].name))
- minetest.set_node(cabinet_boxes_data[box_name][2], cabinet_boxes_data[box_name][1])
- --minetest.debug("DGSDGDSGFDSGSFDGSDGSD")
- local box_meta = minetest.get_meta(cabinet_boxes_data[box_name][2])
- box_meta:set_string(cabinet_boxes_data[box_name][1].name, minetest.serialize({cabinet[1], cabinet[2]}))
- --minetest.debug("DDDDDDDDDDDD")
- end
- minetest.debug(dump(cabinets[name][pos]))
- end
- --[[Arguments:
- *opener - Player
- *cabinet - table that contains name and position of the cabinet
- *cabinets_data - table that contains "name" field of the cabinet inside "pos" field of each set the cabinet in-world and its data (list of boxes inside)
- *cabinet_box - table that contains data of clicked box (name, itemstring, pos, mode and inv)
- *offset - table with coordinates (x, y, z) that means how many coordinate points this is needed to offset
- *formspec - table that contains listname, itemstacks_list, formname and formspec itself]]
- cabinets_funcs.open = function (opener, cabinet, cabinets_data, cabinet_box, offset, formspec)
- local name = cabinet[1]
- local pos = cabinet[3]
- local cabinet_box_name = cabinet_box[1]
- if cabinets_data[name] then
- if cabinets_data[pos] then
- --for _, box in ipairs(cabinets_data[pos]) do
- local inv = minetest.get_inventory({type="node", pos = pos})
- local lists = inv:get_lists()
- local list = lists[1]
- cabinets[name][pos][cabinet_box_name][4] = {formspec[1], formspec[2], formspec[3], formspec[4]}
- cabinets[name][pos][cabinet_box_name][3] = "opened"
- --cabinets_data[cabinet_pos][cabinet_box[2] .. tostring(#cabinets_data[cabinet_pos])][3] = list
- --cabinets_data[cabinet_pos][cabinet_box[2] .. tostring(#cabinets_data[cabinet_pos])][4] = formspec_data_field
- minetest.remove_node(cabinet_box[2])
- local new_pos = {x=pos.x + offset.x, y=pos.y + offset.y, z=pos.z + offset.z}
- cabinets[name][pos][cabinet_box_name][2] = new_pos
- minetest.set_node(new_pos, cabinet_box[2])
- local meta = minetest.get_meta(new_pos)
- meta:set_string("inventory", cabinets[name][pos][cabinet_box_name][4][4])
- local new_inv = minetest.get_inventory({type="node", pos=new_pos})
- local new_lists = new_inv:get_lists()
- local new_list = new_lists[1]
- for _, itemstack in ipairs(new_list) do
- new_inv:add_item(cabinets[name][pos][cabinet_box_name][4][1], itemstack:get_count())
- end
- minetest.show_formspec(opener, cabinets[name][pos][cabinet_box_name][4][3], cabinets[name][pos][cabinet_box_name][4][4])
- end
- end
- end
- --[[Arguments:
- *Same ones as for cabinets_funcs.open(), expect "offset" where should be new position for new node placing]]
- cabinets_funcs.close = function (closer, cabinet, cabinets_data, cabinet_box, offset)
- local name = cabinet[1]
- local pos = cabinet[2]
- local cabinet_box_name = cabinet_box[1]
- local inv = minetest.get_inventory({type="node", pos=pos})
- local lists = inv:get_lists()
- local list = lists[1]
- cabinets[name][pos][cabinet_box_name][4][2] = list
- cabinets[name][pos][cabinet_box_name][3] = "closed"
- minetest.remove_node(cabinet_box[2])
- local new_pos = {x=pos.x + offset.x, y=pos.y + offset.y, z=pos.z + offset.z}
- cabinets[name][pos][cabinet_box_name][1] = new_pos
- minetest.add_node(new_pos, cabinet_box[2])
- end
- minetest.register_node("luxury_decor:kitchen_wooden_cabinet", {
- description = "Kitchen Wooden Cabinet",
- visual_scale = 0.5,
- mesh = "kitchen_wooden_cabinet.obj",
- tiles = {"wood_material.png"},
- --inventory_image = "simple_wooden_table_inv.png",
- paramtype = "light",
- paramtype2 = "facedir",
- groups = {choppy = 3.5},
- drawtype = "mesh",
- collision_box = {
- type = "fixed",
- fixed = {
- --[[{-0.5, -0.5, -0.5, -0.4, 0.5, 0.5}, -- Left nodebox
- {0.4, -0.5, -0.5, 0.5, 0.5, 0.5},]] -- Right nodebox
- {-0.4, 0.4, -0.5, 0.5, 0.5, 0.5}, -- Upper nodebox
- --[[{-0.4, -0.5, -0.6, 0.4, -0.4, 0.5}, -- Downer nodebox
- {-0.4, -0.4, 0.5, 0.4, -0.4, 0.4}, -- Back nodebox
- {-0.4, -0.05, -0.5, 0.4, 0.05, 0.4},]] -- Shelf Nodebox
- }
- },
- selection_box = {
- type = "fixed",
- fixed = {
- {-0.415, -0.415, -0.45, -0.5, 0.42, 0.45}, -- Left nodebox
- {0.415, -0.415, -0.45, 0.5, 0.42, 0.45}, -- Right nodebox
- {-0.5, 0.42, -0.45, 0.5, 0.5, 0.45}, -- Upper nodebox
- {-0.5, -0.42, -0.45, 0.5, -0.5, 0.45}, -- Downer nodebox
- {-0.45, -0.42, 0.37, 0.45, 0.42, 0.45}, -- Back nodebox
- {-0.41, -0.037, -0.45, 0.41, 0.037, 0.45}, -- Shelf Nodebox
- }
- },
- sounds = default.node_sound_wood_defaults(),
- on_construct = function (pos)
- local name = minetest.get_node(pos).name
- local cabinet_data = {
- {minetest.get_node(pos).name, pos},
- --{"box1", "box2"},
- {
- ["box1"] = {
- {
- name="luxury_decor:kitchen_wooden_cabinet_box",
- param1 = minetest.get_node(pos).param1,
- param2 = minetest.get_node(pos).param2
- },
- {x=pos.x, y=pos.y+0.25, z=pos.z},
- "closed",
- "box_inventory[{"..pos.x..","..pos.y..","..pos.z.."}]", "size[8, 4][nodemeta:"..pos.x..",".. pos.y+0.25 ..","..pos.z..";main;0, 1;8, 3]list[current_player;main;0, 5;8, 3]"
- },
- ["box2"] = {
- {
- name="luxury_decor:kitchen_wooden_cabinet_box",
- param1 = minetest.get_node(pos).param1,
- param2 = minetest.get_node(pos).param2
- },
- {x=pos.x, y=pos.y-0.25, z=pos.z},
- "closed",
- "box_inventory[{"..pos.x..","..pos.y..","..pos.z.."}]", "size[8, 4][nodemeta:"..pos.x..",".. pos.y-0.25 ..","..pos.z..";main;0, 1;8, 3]list[current_player;main;0, 5;8, 3]"
- }
- }
- }
- cabinets_funcs.put_data_into_cabinet(cabinet_data[1], cabinet_data[2])
- --[[local name = minetest.get_node(pos).name
- if not cabinets[name] then
- cabinets[name] = {}
- end
- cabinets[name][pos] = {}
- cabinets[name][pos][ = {{x=pos.x, y=pos.y+0.25, z=pos.z}, "closed"}
- kitchen_wooden_cabinets[pos]["box2"] = {{x=pos.x, y=pos.y-0.25, z=pos.z}, "closed"}
- minetest.add_node({x=pos.x, y=pos.y+0.25, z=pos.z}, "luxury_decor:kitchen_wooden_cabinet_box")
- minetest.add_node({x=pos.x, y=pos.y-0.25, z=pos.z}, "luxury_decor:kitchen_wooden_cabinet_box")]]
- end
- })
- minetest.register_node("luxury_decor:kitchen_wooden_cabinet_box", {
- description = "Kitchen Wooden Cabinet Box",
- visual_scale = 0.5,
- mesh = "kitchen_wooden_cabinet_box.obj",
- tiles = {"wood_material.png"},
- --inventory_image = "simple_wooden_table_inv.png",
- paramtype = "light",
- paramtype2 = "facedir",
- groups = {choppy = 3.5, not_in_creative_inventory=1},
- drawtype = "mesh",
- collision_box = {
- type = "fixed",
- fixed = {
- {-0.45, 0.05, -0.475, 0.45, 0.43, 0.48},
- }
- },
- selection_box = {
- type = "fixed",
- fixed = {
- {-0.45, 0.05, -0.475, 0.45, 0.43, 0.48},
- }
- },
- sounds = default.node_sound_wood_defaults(),
- on_rightclick = function (pos, node, clicker, itemstack, pointed_thing)
- local meta = minetest.get_meta(pos)
- --minetest.debug(meta[1])
- --minetest.debug(meta[2])
- local cabinet_name, cabinet_pos = meta:get_string(meta[1]), meta:get_string(meta[2])
- if cabinet_name ~= nil or cabinet_name ~= "" then
- local cabinet_data = cabinets[cabinet_name][cabinet_pos]
- for box_name, box in ipairs(cabinet_data) do
- if cabinet_data[box_name][1].name == node.name then
- local cabinet = {meta[1], meta[2]}
- local cabinet_box = {box_name, cabinet_data[box_name][1].name, cabinet_data[box_name][2], cabinet_data[box_name][3], cabinet_data[box_name][4]}
- local offset = {x=0, y=0, z=-0.7}
- cabinets_funcs.open(clicker:get_player_name(), cabinet, cabinets, cabinet_box, offset, {"main", {}, "box_formspec", cabinets_data[box_name][4][4]})
- break
- end
- end
- end
- end,
- on_receive_fields = function (pos, formname, fields, sender)
- if fields.quit then
- local meta = minetest.get_meta(pos)
- local cabinet_name, cabinet_pos, cabinet_data = meta:get_string(meta[1]), meta:get_string(meta[2]), cabinets[cabinet_name][cabinet_pos]
- for box_name, box in ipairs(cabinet_data) do
- if cabinet_data[box_name][1].name == node.name then
- local cabinet_box = {box_name, cabinet_data[box_name][1].name, cabinet_data[box_name][2], cabinet_data[box_name][3], cabinet_data[box_name][4]}
- cabinets_funcs.close(sender:get_player_name(), {meta[1], meta[2]}, cabinets, cabinet_box, offset)
- break
- end
- end
- end
- end
- })
Advertisement
Add Comment
Please, Sign In to add comment