2015-06-09 15:04:57 +03:00
|
|
|
xdecor.box = {
|
2016-01-03 16:04:15 +03:00
|
|
|
slab_y = function(height, shift)
|
2019-07-23 15:03:20 +03:00
|
|
|
return {
|
|
|
|
-0.5,
|
|
|
|
-0.5 + (shift or 0),
|
|
|
|
-0.5,
|
|
|
|
0.5,
|
|
|
|
-0.5 + height + (shift or 0),
|
|
|
|
0.5
|
|
|
|
}
|
2016-01-03 16:04:15 +03:00
|
|
|
end,
|
|
|
|
slab_z = function(depth)
|
2016-12-05 14:58:35 +03:00
|
|
|
return {-0.5, -0.5, -0.5 + depth, 0.5, 0.5, 0.5}
|
2016-01-03 16:04:15 +03:00
|
|
|
end,
|
|
|
|
bar_y = function(radius)
|
2016-12-05 14:58:35 +03:00
|
|
|
return {-radius, -0.5, -radius, radius, 0.5, radius}
|
2016-01-03 16:04:15 +03:00
|
|
|
end,
|
|
|
|
cuboid = function(radius_x, radius_y, radius_z)
|
2016-12-05 14:58:35 +03:00
|
|
|
return {-radius_x, -radius_y, -radius_z, radius_x, radius_y, radius_z}
|
2016-01-03 16:04:15 +03:00
|
|
|
end
|
2015-06-09 15:04:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
xdecor.nodebox = {
|
2019-07-23 15:03:20 +03:00
|
|
|
regular = {type = "regular"},
|
|
|
|
null = {
|
|
|
|
type = "fixed", fixed = {0,0,0,0,0,0}
|
|
|
|
}
|
2015-06-09 15:04:57 +03:00
|
|
|
}
|
|
|
|
|
2016-02-04 18:02:28 +03:00
|
|
|
xdecor.pixelbox = function(size, boxes)
|
2016-01-16 15:21:35 +03:00
|
|
|
local fixed = {}
|
2019-07-23 15:03:20 +03:00
|
|
|
for _, box in ipairs(boxes) do
|
2016-02-12 17:00:44 +03:00
|
|
|
-- `unpack` has been changed to `table.unpack` in newest Lua versions.
|
|
|
|
local x, y, z, w, h, l = unpack(box)
|
2019-07-23 15:03:20 +03:00
|
|
|
fixed[#fixed + 1] = {
|
2016-01-16 15:21:35 +03:00
|
|
|
(x / size) - 0.5,
|
|
|
|
(y / size) - 0.5,
|
|
|
|
(z / size) - 0.5,
|
2016-01-16 23:25:10 +03:00
|
|
|
((x + w) / size) - 0.5,
|
|
|
|
((y + h) / size) - 0.5,
|
|
|
|
((z + l) / size) - 0.5
|
2016-01-16 15:21:35 +03:00
|
|
|
}
|
|
|
|
end
|
2019-07-23 15:03:20 +03:00
|
|
|
|
|
|
|
return {type = "fixed", fixed = fixed}
|
2016-01-16 15:21:35 +03:00
|
|
|
end
|
|
|
|
|
2015-06-09 15:04:57 +03:00
|
|
|
local mt = {}
|
2019-07-23 15:03:20 +03:00
|
|
|
|
2015-06-09 15:04:57 +03:00
|
|
|
mt.__index = function(table, key)
|
|
|
|
local ref = xdecor.box[key]
|
|
|
|
local ref_type = type(ref)
|
2016-01-03 16:04:15 +03:00
|
|
|
|
2015-06-09 15:04:57 +03:00
|
|
|
if ref_type == "function" then
|
|
|
|
return function(...)
|
2019-07-23 15:03:20 +03:00
|
|
|
return {type = "fixed", fixed = ref(...)}
|
2015-06-09 15:04:57 +03:00
|
|
|
end
|
|
|
|
elseif ref_type == "table" then
|
2019-07-23 15:03:20 +03:00
|
|
|
return {type = "fixed", fixed = ref}
|
2015-06-09 15:04:57 +03:00
|
|
|
elseif ref_type == "nil" then
|
2019-07-23 15:03:20 +03:00
|
|
|
error(key .. "could not be found among nodebox presets and functions")
|
2015-06-09 15:04:57 +03:00
|
|
|
end
|
2016-01-03 16:04:15 +03:00
|
|
|
|
2019-07-23 15:03:20 +03:00
|
|
|
error("unexpected datatype " .. tostring(type(ref)) .. " while looking for " .. key)
|
2015-06-09 15:04:57 +03:00
|
|
|
end
|
2016-01-03 16:04:15 +03:00
|
|
|
|
2015-06-09 15:04:57 +03:00
|
|
|
setmetatable(xdecor.nodebox, mt)
|