]> git.lizzy.rs Git - xdecor.git/blobdiff - handlers/registration.lua
Don't set paramtype="light" by default, unless it's expectable to propagate light.
[xdecor.git] / handlers / registration.lua
index cf2e9fdb71d388d668f0958cf10146e926d51e8e..680c202abed747fd9454ea4669af5f45fae99972 100644 (file)
@@ -1,35 +1,35 @@
-xdecor = xdecor or {}
-
-local default_can_dig = function(pos,player)
-       local meta = minetest.get_meta(pos)
-       return meta:get_inventory():is_empty("main")
-end
-
-xdecor.wood = default.node_sound_wood_defaults()
-xdecor.glass = default.node_sound_glass_defaults()
-xdecor.leaves = default.node_sound_leaves_defaults()
-xdecor.stone = default.node_sound_stone_defaults()
-xdecor.fancy_gui = default.gui_bg..default.gui_bg_img..default.gui_slots
-
+xbg = default.gui_bg..default.gui_bg_img..default.gui_slots
 local default_inventory_size = 32
+
 local default_inventory_formspecs = {
-       ["8"]="size[8,6]"..xdecor.fancy_gui..
-       "list[context;main;0,0;8,1;]"..
-       "list[current_player;main;0,2;8,4;]",
+       ["8"] = [[ size[8,6]
+               list[context;main;0,0;8,1;]
+               list[current_player;main;0,2;8,4;]
+               listring[current_player;main]
+               listring[context;main] ]]
+               ..default.get_hotbar_bg(0,2),
 
-       ["16"]="size[8,7]"..xdecor.fancy_gui..
-       "list[context;main;0,0;8,2;]"..
-       "list[current_player;main;0,3;8,4;]",
+       ["16"] = [[ size[8,7]
+               list[context;main;0,0;8,2;]
+               list[current_player;main;0,3;8,4;]
+               listring[current_player;main]
+               listring[context;main] ]]
+               ..default.get_hotbar_bg(0,3),
 
-       ["24"]="size[8,8]"..xdecor.fancy_gui..
-       "list[context;main;0,0;8,3;]"..
-       "list[current_player;main;0,4;8,4;]",
+       ["24"] = [[ size[8,8]
+               list[context;main;0,0;8,3;]
+               list[current_player;main;0,4;8,4;]
+               listring[current_player;main]
+               listring[context;main]" ]]
+               ..default.get_hotbar_bg(0,4),
 
-       ["32"]="size[8,9]"..xdecor.fancy_gui..
-       "list[context;main;0,0.3;8,4;]"..
-       "list[current_player;main;0,4.85;8,1;]"..
-       "list[current_player;main;0,6.08;8,3;8]"..
-       default.get_hotbar_bg(0, 4.85)
+       ["32"] = [[ size[8,9]
+               list[context;main;0,0.3;8,4;]
+               list[current_player;main;0,4.85;8,1;]
+               list[current_player;main;0,6.08;8,3;8]
+               listring[current_player;main]
+               listring[context;main] ]]
+               ..default.get_hotbar_bg(0,4.85)
 }
 
 local function get_formspec_by_size(size)
@@ -37,22 +37,36 @@ local function get_formspec_by_size(size)
        return formspec or default_inventory_formspecs
 end
 
+local default_can_dig = function(pos)
+       local inv = minetest.get_meta(pos):get_inventory()
+       return inv:is_empty("main")
+end
+
 function xdecor.register(name, def)
-       def.drawtype = def.drawtype or (def.node_box and "nodebox")
-       def.paramtype = def.paramtype or "light"
+       def.drawtype = def.drawtype
+               or (def.mesh and "mesh")
+               or (def.node_box and "nodebox")
+
        def.sounds = def.sounds or default.node_sound_defaults()
-       
-       if not (def.drawtype == "glasslike_framed" or
-                       def.drawtype == "glasslike_framed_optional" or def.drawtype == "plantlike" or
-                       def.drawtype == "signlike" or def.drawtype == "normal") then
+
+       if not (def.drawtype == "normal" or def.drawtype == "signlike" or
+                       def.drawtype == "plantlike" or def.drawtype == "glasslike_framed" or
+                       def.drawtype == "glasslike_framed_optional") then
                def.paramtype2 = def.paramtype2 or "facedir"
        end
 
-       if def.drawtype == "plantlike" or def.drawtype == "torchlike" or
-                       def.drawtype == "signlike" or def.drawtype == "fencelike" then
+       if def.sunlight_propagates ~= false and
+                       (def.drawtype == "plantlike" or def.drawtype == "torchlike" or
+                       def.drawtype == "signlike" or def.drawtype == "fencelike") then
                def.sunlight_propagates = true
        end
 
+       if not def.paramtype and
+               (def.light_source or def.sunlight_propagates or
+               def.drawtype == "nodebox" or def.drawtype == "mesh") then
+               def.paramtype = "light"
+       end
+
        local infotext = def.infotext
        local inventory = def.inventory
        def.inventory = nil
@@ -60,14 +74,13 @@ function xdecor.register(name, def)
        if inventory then
                def.on_construct = def.on_construct or function(pos)
                        local meta = minetest.get_meta(pos)
-                       if infotext then
-                               meta:set_string("infotext", infotext)
-                       end
+                       if infotext then meta:set_string("infotext", infotext) end
+
                        local size = inventory.size or default_inventory_size
-                       meta:get_inventory():set_size("main", size)
-                       meta:set_string("formspec", inventory.formspec or get_formspec_by_size(size))
+                       local inv = meta:get_inventory()
+                       inv:set_size("main", size)
+                       meta:set_string("formspec", (inventory.formspec or get_formspec_by_size(size))..xbg)
                end
-
                def.can_dig = def.can_dig or default_can_dig
        elseif infotext and not def.on_construct then
                def.on_construct = function(pos)
@@ -76,5 +89,5 @@ function xdecor.register(name, def)
                end
        end
 
-       minetest.register_node("xdecor:" .. name, def)
+       minetest.register_node("xdecor:"..name, def)
 end