]> git.lizzy.rs Git - xdecor.git/blob - handlers/registration.lua
680c202abed747fd9454ea4669af5f45fae99972
[xdecor.git] / handlers / registration.lua
1 xbg = default.gui_bg..default.gui_bg_img..default.gui_slots
2 local default_inventory_size = 32
3
4 local default_inventory_formspecs = {
5         ["8"] = [[ size[8,6]
6                 list[context;main;0,0;8,1;]
7                 list[current_player;main;0,2;8,4;]
8                 listring[current_player;main]
9                 listring[context;main] ]]
10                 ..default.get_hotbar_bg(0,2),
11
12         ["16"] = [[ size[8,7]
13                 list[context;main;0,0;8,2;]
14                 list[current_player;main;0,3;8,4;]
15                 listring[current_player;main]
16                 listring[context;main] ]]
17                 ..default.get_hotbar_bg(0,3),
18
19         ["24"] = [[ size[8,8]
20                 list[context;main;0,0;8,3;]
21                 list[current_player;main;0,4;8,4;]
22                 listring[current_player;main]
23                 listring[context;main]" ]]
24                 ..default.get_hotbar_bg(0,4),
25
26         ["32"] = [[ size[8,9]
27                 list[context;main;0,0.3;8,4;]
28                 list[current_player;main;0,4.85;8,1;]
29                 list[current_player;main;0,6.08;8,3;8]
30                 listring[current_player;main]
31                 listring[context;main] ]]
32                 ..default.get_hotbar_bg(0,4.85)
33 }
34
35 local function get_formspec_by_size(size)
36         local formspec = default_inventory_formspecs[tostring(size)]
37         return formspec or default_inventory_formspecs
38 end
39
40 local default_can_dig = function(pos)
41         local inv = minetest.get_meta(pos):get_inventory()
42         return inv:is_empty("main")
43 end
44
45 function xdecor.register(name, def)
46         def.drawtype = def.drawtype
47                 or (def.mesh and "mesh")
48                 or (def.node_box and "nodebox")
49
50         def.sounds = def.sounds or default.node_sound_defaults()
51
52         if not (def.drawtype == "normal" or def.drawtype == "signlike" or
53                         def.drawtype == "plantlike" or def.drawtype == "glasslike_framed" or
54                         def.drawtype == "glasslike_framed_optional") then
55                 def.paramtype2 = def.paramtype2 or "facedir"
56         end
57
58         if def.sunlight_propagates ~= false and
59                         (def.drawtype == "plantlike" or def.drawtype == "torchlike" or
60                         def.drawtype == "signlike" or def.drawtype == "fencelike") then
61                 def.sunlight_propagates = true
62         end
63
64         if not def.paramtype and
65                 (def.light_source or def.sunlight_propagates or
66                 def.drawtype == "nodebox" or def.drawtype == "mesh") then
67                 def.paramtype = "light"
68         end
69
70         local infotext = def.infotext
71         local inventory = def.inventory
72         def.inventory = nil
73
74         if inventory then
75                 def.on_construct = def.on_construct or function(pos)
76                         local meta = minetest.get_meta(pos)
77                         if infotext then meta:set_string("infotext", infotext) end
78
79                         local size = inventory.size or default_inventory_size
80                         local inv = meta:get_inventory()
81                         inv:set_size("main", size)
82                         meta:set_string("formspec", (inventory.formspec or get_formspec_by_size(size))..xbg)
83                 end
84                 def.can_dig = def.can_dig or default_can_dig
85         elseif infotext and not def.on_construct then
86                 def.on_construct = function(pos)
87                         local meta = minetest.get_meta(pos)
88                         meta:set_string("infotext", infotext)
89                 end
90         end
91
92         minetest.register_node("xdecor:"..name, def)
93 end