]> git.lizzy.rs Git - xdecor.git/blob - handlers/nodeboxes.lua
Bowl of soup : use minetest.item_eat when hunger mod installed
[xdecor.git] / handlers / nodeboxes.lua
1 xdecor.box = {
2         slab_y = function(height, shift)
3                 return { -0.5, -0.5+(shift or 0), -0.5, 0.5, -0.5+height+(shift or 0), 0.5 }
4         end,
5         slab_z = function(depth)
6                 return { -0.5, -0.5, -0.5+depth, 0.5, 0.5, 0.5 }
7         end,
8         bar_y = function(radius)
9                 return { -radius, -0.5, -radius, radius, 0.5, radius }
10         end,
11         cuboid = function(radius_x, radius_y, radius_z)
12                 return { -radius_x, -radius_y, -radius_z, radius_x, radius_y, radius_z }
13         end
14 }
15
16 xdecor.nodebox = {
17         regular = { type = "regular" },
18         null = { type = "fixed", fixed = { 0, 0, 0, 0, 0, 0 } }
19 }
20
21 local mt = {}
22 mt.__index = function(table, key)
23         local ref = xdecor.box[key]
24         local ref_type = type(ref)
25
26         if ref_type == "function" then
27                 return function(...)
28                         return { type = "fixed", fixed = ref(...) }
29                 end
30         elseif ref_type == "table" then
31                 return { type = "fixed", fixed = ref }
32         elseif ref_type == "nil" then
33                 error(key.."could not be found among nodebox presets and functions")
34         end
35
36         error("unexpected datatype "..tostring(type(ref)).." while looking for "..key)
37 end
38
39 setmetatable(xdecor.nodebox, mt)
40