2015-01-23 17:40:57 +01:00
|
|
|
-- please keep any non-generic nodeboxe with its node definition
|
|
|
|
-- this file should not accumulate any left over nodeboxes
|
|
|
|
-- but is meant to host any abstractions or calculations based on nodeboxes
|
|
|
|
|
|
|
|
-- a box is defined as {x1, y1, z1, x2, y2, z2}
|
|
|
|
homedecor.box = {
|
2015-08-19 15:32:19 +02:00
|
|
|
-- slab starting from -x (after rotation: left)
|
|
|
|
slab_x = function(depth) return { -0.5, -0.5, -0.5, -0.5+depth, 0.5, 0.5 } end,
|
2015-08-19 15:06:53 +02:00
|
|
|
-- bottom slab (starting from -y) with height optionally shifted upwards
|
2015-01-23 17:40:57 +01:00
|
|
|
slab_y = function(height, shift) return { -0.5, -0.5+(shift or 0), -0.5, 0.5, -0.5+height+(shift or 0), 0.5 } end,
|
2015-08-19 15:32:19 +02:00
|
|
|
-- slab starting from -z (+z with negative depth)
|
2021-03-26 07:15:10 +01:00
|
|
|
slab_z = function(depth, shift)
|
2022-05-03 21:21:14 +02:00
|
|
|
-- for consistency with the other functions here, we have to assume that a z slab starts from -z and extends by depth,
|
2015-08-19 15:06:53 +02:00
|
|
|
-- but since conventionally a lot of nodes place slabs against +z for player convenience, we define
|
|
|
|
-- a "negative" depth as a depth extending from the other side, i.e. +z
|
2021-03-26 07:15:10 +01:00
|
|
|
local s = shift or 0
|
2015-08-19 15:06:53 +02:00
|
|
|
if depth > 0 then
|
|
|
|
-- slab starting from -z
|
2021-03-26 07:15:10 +01:00
|
|
|
return { -0.5, -0.5, -0.5+s, 0.5, 0.5, -0.5+depth+s }
|
2015-08-19 15:06:53 +02:00
|
|
|
else
|
|
|
|
-- slab starting from +z (z1=0.5-(-depth))
|
2021-03-26 07:15:10 +01:00
|
|
|
return { -0.5, -0.5, 0.5+depth+s, 0.5, 0.5, 0.5+s }
|
2015-08-19 15:06:53 +02:00
|
|
|
end
|
|
|
|
end,
|
2015-01-23 17:40:57 +01:00
|
|
|
bar_y = function(radius) return {-radius, -0.5, -radius, radius, 0.5, radius} end,
|
2020-08-04 16:12:47 +02:00
|
|
|
cuboid = function(radius_x, radius_y, radius_z)
|
|
|
|
return {-radius_x, -radius_y, -radius_z, radius_x, radius_y, radius_z} end,
|
2015-01-23 17:40:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
homedecor.nodebox = {
|
|
|
|
-- { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
|
|
|
|
-- can be used in-place as:
|
|
|
|
-- { type="regular" },
|
|
|
|
regular = { type="regular" },
|
|
|
|
null = { type = "fixed", fixed = { 0, 0, 0, 0, 0, 0 } },
|
2015-08-19 15:32:19 +02:00
|
|
|
corner_xz = function(depth_x, depth_z) return {
|
|
|
|
type="fixed",
|
|
|
|
fixed={
|
|
|
|
homedecor.box.slab_x(depth_x),
|
|
|
|
homedecor.box.slab_z(depth_z),
|
|
|
|
-- { -0.5, -0.5, -0.5, 0.5-depth, 0.5, -0.5+depth } -- slab_x without the overlap, but actually looks a bit worse
|
|
|
|
}
|
|
|
|
} end,
|
2015-01-23 17:40:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
local mt = {}
|
|
|
|
mt.__index = function(table, key)
|
|
|
|
local ref = homedecor.box[key]
|
2015-01-23 21:51:29 +01:00
|
|
|
local ref_type = type(ref)
|
|
|
|
if ref_type == "function" then
|
2015-01-23 17:40:57 +01:00
|
|
|
return function(...)
|
2015-01-23 18:52:34 +01:00
|
|
|
return { type = "fixed", fixed = ref(...) }
|
2015-01-23 17:40:57 +01:00
|
|
|
end
|
2015-01-23 21:51:29 +01:00
|
|
|
elseif ref_type == "table" then
|
2015-01-23 17:40:57 +01:00
|
|
|
return { type = "fixed", fixed = ref }
|
2015-01-23 21:51:29 +01:00
|
|
|
elseif ref_type == "nil" then
|
|
|
|
error(key .. "could not be found among nodebox presets and functions")
|
2015-01-23 17:40:57 +01:00
|
|
|
end
|
2015-01-23 21:51:29 +01:00
|
|
|
error("unexpected datatype " .. tostring(type(ref)) .. " while looking for " .. key)
|
2015-01-23 17:40:57 +01:00
|
|
|
end
|
|
|
|
setmetatable(homedecor.nodebox, mt)
|