]> git.lizzy.rs Git - xdecor.git/blob - handlers/helpers.lua
Add settings and compatibility with moreblocks and stairs
[xdecor.git] / handlers / helpers.lua
1 -- Returns the greatest numeric key in a table.
2 function xdecor.maxn(T)
3         local n = 0
4         for k in pairs(T) do
5                 if k > n then n = k end
6         end
7         return n
8 end
9
10 -- Returns the length of an hash table.
11 function xdecor.tablelen(T)
12         local n = 0
13         for _ in pairs(T) do n = n + 1 end
14         return n
15 end
16
17 -- Deep copy of a table. Borrowed from mesecons mod (https://github.com/Jeija/minetest-mod-mesecons).
18 function xdecor.tablecopy(T)
19         if type(T) ~= "table" then return T end -- No need to copy.
20         local new = {}
21
22         for k, v in pairs(T) do
23                 if type(v) == "table" then
24                         new[k] = xdecor.tablecopy(v)
25                 else
26                         new[k] = v
27                 end
28         end
29         return new
30 end
31
32 -- Return true if a def is accepting for stair
33 function xdecor.stairs_valid_def(def)
34         return (def.drawtype == "normal" or def.drawtype:sub(1,5) == "glass") and
35                 (def.groups.cracky or def.groups.choppy) and
36                 not def.on_construct and
37                 not def.after_place_node and
38                 not def.on_rightclick and
39                 not def.on_blast and
40                 not def.allow_metadata_inventory_take and
41                 not (def.groups.not_in_creative_inventory == 1) and
42                 not (def.groups.not_cuttable == 1) and
43                 not def.groups.wool and
44                 (def.tiles and type(def.tiles[1]) == "string" and not
45                 def.tiles[1]:find("default_mineral")) and
46                 not def.mesecons and
47                 def.description and
48                 def.description ~= "" and
49         def.light_source == 0
50 end