1 local default_can_dig = function(pos, _)
2 local meta = minetest.get_meta(pos)
3 local inv = meta:get_inventory()
5 return inv:is_empty("main")
8 local xbg = default.gui_bg..default.gui_bg_img..default.gui_slots
10 local default_inventory_size = 32
11 local default_inventory_formspecs = {
12 ["8"] = "size[8,6]"..xbg..
13 "list[context;main;0,0;8,1;]"..
14 "list[current_player;main;0,2;8,4;]",
16 ["16"] = "size[8,7]"..xbg..
17 "list[context;main;0,0;8,2;]"..
18 "list[current_player;main;0,3;8,4;]",
20 ["24"] = "size[8,8]"..xbg..
21 "list[context;main;0,0;8,3;]"..
22 "list[current_player;main;0,4;8,4;]",
24 ["32"] = "size[8,9]"..xbg..
25 "list[context;main;0,0.3;8,4;]"..
26 "list[current_player;main;0,4.85;8,1;]"..
27 "list[current_player;main;0,6.08;8,3;8]"..
28 default.get_hotbar_bg(0, 4.85)
31 local function get_formspec_by_size(size)
32 local formspec = default_inventory_formspecs[tostring(size)]
33 return formspec or default_inventory_formspecs
36 function xdecor.register(name, def)
37 def.drawtype = def.drawtype or (def.node_box and "nodebox")
38 def.paramtype = def.paramtype or "light"
39 def.sounds = def.sounds or default.node_sound_defaults()
41 if not (def.drawtype == "glasslike_framed" or
42 def.drawtype == "glasslike_framed_optional" or def.drawtype == "plantlike" or
43 def.drawtype == "signlike" or def.drawtype == "normal") then
44 def.paramtype2 = def.paramtype2 or "facedir"
47 if def.drawtype == "plantlike" or def.drawtype == "torchlike" or
48 def.drawtype == "signlike" or def.drawtype == "fencelike" then
49 def.sunlight_propagates = true
52 local infotext = def.infotext
53 local inventory = def.inventory
57 def.on_construct = def.on_construct or function(pos)
58 local meta = minetest.get_meta(pos)
60 meta:set_string("infotext", infotext)
62 local size = inventory.size or default_inventory_size
63 local inv = meta:get_inventory()
64 inv:set_size("main", size)
65 meta:set_string("formspec", inventory.formspec or get_formspec_by_size(size))
68 def.can_dig = def.can_dig or default_can_dig
69 elseif infotext and not def.on_construct then
70 def.on_construct = function(pos)
71 local meta = minetest.get_meta(pos)
72 meta:set_string("infotext", infotext)
76 minetest.register_node("xdecor:".. name, def)