]> git.lizzy.rs Git - xdecor.git/blob - handlers/registration.lua
Localize some global variables
[xdecor.git] / handlers / registration.lua
1 local default_can_dig = function(pos, _)
2         local meta = minetest.get_meta(pos)
3         local inv = meta:get_inventory()
4
5         return inv:is_empty("main")
6 end
7
8 local xbg = default.gui_bg..default.gui_bg_img..default.gui_slots
9
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;]",
15
16         ["16"] = "size[8,7]"..xbg..
17         "list[context;main;0,0;8,2;]"..
18         "list[current_player;main;0,3;8,4;]",
19
20         ["24"] = "size[8,8]"..xbg..
21         "list[context;main;0,0;8,3;]"..
22         "list[current_player;main;0,4;8,4;]",
23
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)
29 }
30
31 local function get_formspec_by_size(size)
32         local formspec = default_inventory_formspecs[tostring(size)]
33         return formspec or default_inventory_formspecs
34 end
35
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()
40         
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"
45         end
46
47         if def.drawtype == "plantlike" or def.drawtype == "torchlike" or
48                         def.drawtype == "signlike" or def.drawtype == "fencelike" then
49                 def.sunlight_propagates = true
50         end
51
52         local infotext = def.infotext
53         local inventory = def.inventory
54         def.inventory = nil
55
56         if inventory then
57                 def.on_construct = def.on_construct or function(pos)
58                         local meta = minetest.get_meta(pos)
59                         if infotext then
60                                 meta:set_string("infotext", infotext)
61                         end
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))
66                 end
67
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)
73                 end
74         end
75
76         minetest.register_node("xdecor:".. name, def)
77 end