diff --git a/stairsplus/common.lua b/stairsplus/common.lua new file mode 100644 index 0000000..91803c8 --- /dev/null +++ b/stairsplus/common.lua @@ -0,0 +1,60 @@ +--[[ +More Blocks: registrations + +Copyright (c) 2011-2018 Hugo Locurcio and contributors. +Licensed under the zlib license. See LICENSE.md for more information. +--]] + +local S = moreblocks.intllib + + +stairsplus.register_single = function(category, alternate, info, modname, subname, recipeitem, fields) + local descriptions = { + ["micro"] = "Microblock", + ["slab"] = "Slab", + ["slope"] = "Slope", + ["panel"] = "Panel", + ["stair"] = "Stairs", + } + local def = {} + if category ~= "slab" then + def = table.copy(info) + end + + for k, v in pairs(fields) do + def[k] = v + end + def.drawtype = "nodebox" + if category == "slope" then + def.drawtype = "mesh" + end + def.paramtype = "light" + def.paramtype2 = def.paramtype2 or "facedir" + def.on_place = minetest.rotate_node + if category ~= "slab" then + def.description = S("%s " .. descriptions[category]):format(fields.description) + else + local desc_base = S("%s " .. descriptions[category]):format(fields.description) + if type(info) ~= "table" then + def.node_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, (info/16)-0.5, 0.5}, + } + def.description = ("%s (%d/16)"):format(desc_base, info) + else + def.node_box = { + type = "fixed", + fixed = info, + } + def.description = desc_base .. alternate:gsub("_", " "):gsub("(%a)(%S*)", function(a, b) return a:upper() .. b end) + end + end + def.groups = stairsplus:prepare_groups(fields.groups) + if category == "stair" and alternate == "" then + def.groups.stair = 1 + end + if fields.drop and not (type(fields.drop) == "table") then + def.drop = modname.. ":" .. category .. "_" .. fields.drop .. alternate + end + minetest.register_node(":" ..modname.. ":" .. category .. "_" .. subname .. alternate, def) +end \ No newline at end of file diff --git a/stairsplus/init.lua b/stairsplus/init.lua index cfb6fcd..c9ca438 100644 --- a/stairsplus/init.lua +++ b/stairsplus/init.lua @@ -71,6 +71,7 @@ end -- dofile(modpath.. "/aliases.lua") -- Not needed as of Q2 2013, uncomment to fix old maps. -- dofile(modpath.. "/conversion.lua") -- Not needed as of Q2 2013, uncomment to fix old maps. dofile(modpath .. "/defs.lua") +dofile(modpath .. "/common.lua") dofile(modpath .. "/stairs.lua") dofile(modpath .. "/slabs.lua") dofile(modpath .. "/slopes.lua") diff --git a/stairsplus/microblocks.lua b/stairsplus/microblocks.lua index 8a3b63d..4e7c51e 100644 --- a/stairsplus/microblocks.lua +++ b/stairsplus/microblocks.lua @@ -36,21 +36,8 @@ end function stairsplus:register_micro(modname, subname, recipeitem, fields) local defs = table.copy(stairsplus.defs["micro"]) - local desc = S("%s Microblock"):format(fields.description) for alternate, def in pairs(defs) do - for k, v in pairs(fields) do - def[k] = v - end - def.drawtype = "nodebox" - def.paramtype = "light" - def.paramtype2 = def.paramtype2 or "facedir" - def.on_place = minetest.rotate_node - def.groups = stairsplus:prepare_groups(fields.groups) - def.description = desc - if fields.drop and not (type(fields.drop) == "table") then - def.drop = modname.. ":micro_" ..fields.drop..alternate - end - minetest.register_node(":" ..modname.. ":micro_" ..subname..alternate, def) + stairsplus.register_single("micro", alternate, def, modname, subname, recipeitem, fields) end minetest.register_alias(modname.. ":micro_" ..subname.. "_bottom", modname.. ":micro_" ..subname) diff --git a/stairsplus/panels.lua b/stairsplus/panels.lua index e065cdd..a33cc5f 100644 --- a/stairsplus/panels.lua +++ b/stairsplus/panels.lua @@ -36,21 +36,8 @@ end function stairsplus:register_panel(modname, subname, recipeitem, fields) local defs = table.copy(stairsplus.defs["panel"]) - local desc = S("%s Panel"):format(fields.description) for alternate, def in pairs(defs) do - for k, v in pairs(fields) do - def[k] = v - end - def.drawtype = "nodebox" - def.paramtype = "light" - def.paramtype2 = def.paramtype2 or "facedir" - def.on_place = minetest.rotate_node - def.description = desc - def.groups = stairsplus:prepare_groups(fields.groups) - if fields.drop and not (type(fields.drop) == "table") then - def.drop = modname.. ":panel_" ..fields.drop..alternate - end - minetest.register_node(":" ..modname.. ":panel_" ..subname..alternate, def) + stairsplus.register_single("panel", alternate, def, modname, subname, recipeitem, fields) end minetest.register_alias(modname.. ":panel_" ..subname.. "_bottom", modname.. ":panel_" ..subname) diff --git a/stairsplus/slabs.lua b/stairsplus/slabs.lua index 2d60d6d..a8d920b 100644 --- a/stairsplus/slabs.lua +++ b/stairsplus/slabs.lua @@ -38,38 +38,7 @@ function stairsplus:register_slab(modname, subname, recipeitem, fields) local defs = table.copy(stairsplus.defs["slab"]) local desc_base = S("%s Slab"):format(fields.description) for alternate, shape in pairs(defs) do - local def = {} - for k, v in pairs(fields) do - def[k] = v - end - if type(shape) ~= "table" then - def.node_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, (shape/16)-0.5, 0.5}, - } - def.description = ("%s (%d/16)"):format(desc_base, shape) - else - def.node_box = { - type = "fixed", - fixed = shape, - } - local desc_x = alternate:gsub("_", " ") - desc_x = desc_x:gsub("(%a)(%S*)", function(a, b) return a:upper() .. b end) - def.description = desc_base .. desc_x - end - - def.drawtype = "nodebox" - def.paramtype = "light" - def.paramtype2 = def.paramtype2 or "facedir" - def.on_place = minetest.rotate_node - def.groups = stairsplus:prepare_groups(fields.groups) - if alternate == "" then - def.groups.slab = 1 - end - if fields.drop and not (type(fields.drop) == "table") then - def.drop = modname.. ":slab_" .. fields.drop .. alternate - end - minetest.register_node(":" .. modname .. ":slab_" .. subname .. alternate, def) + stairsplus.register_single("slab", alternate, shape, modname, subname, recipeitem, fields) end circular_saw.known_nodes[recipeitem] = {modname, subname} diff --git a/stairsplus/slopes.lua b/stairsplus/slopes.lua index 892e856..adf755e 100644 --- a/stairsplus/slopes.lua +++ b/stairsplus/slopes.lua @@ -36,21 +36,8 @@ end function stairsplus:register_slope(modname, subname, recipeitem, fields) local defs = table.copy(stairsplus.defs["slope"]) - local desc = S("%s Slope"):format(fields.description) for alternate, def in pairs(defs) do - for k, v in pairs(fields) do - def[k] = v - end - def.drawtype = "mesh" - def.paramtype = "light" - def.paramtype2 = def.paramtype2 or "facedir" - def.on_place = minetest.rotate_node - def.description = desc - def.groups = stairsplus:prepare_groups(fields.groups) - if fields.drop and not (type(fields.drop) == "table") then - def.drop = modname.. ":slope_" ..fields.drop..alternate - end - minetest.register_node(":" ..modname.. ":slope_" ..subname..alternate, def) + stairsplus.register_single("slope", alternate, def, modname, subname, recipeitem, fields) end circular_saw.known_nodes[recipeitem] = {modname, subname} diff --git a/stairsplus/stairs.lua b/stairsplus/stairs.lua index eb76663..5160f0b 100644 --- a/stairsplus/stairs.lua +++ b/stairsplus/stairs.lua @@ -36,24 +36,8 @@ end function stairsplus:register_stair(modname, subname, recipeitem, fields) local defs = table.copy(stairsplus.defs["stair"]) - local desc = S("%s Stairs"):format(fields.description) for alternate, def in pairs(defs) do - for k, v in pairs(fields) do - def[k] = v - end - def.drawtype = "nodebox" - def.paramtype = "light" - def.paramtype2 = def.paramtype2 or "facedir" - def.on_place = minetest.rotate_node - def.description = desc - def.groups = stairsplus:prepare_groups(fields.groups) - if alternate == "" then - def.groups.stair = 1 - end - if fields.drop and not (type(fields.drop) == "table") then - def.drop = modname .. ":stair_" .. fields.drop .. alternate - end - minetest.register_node(":" .. modname .. ":stair_" .. subname .. alternate, def) + stairsplus.register_single("stair", alternate, def, modname, subname, recipeitem, fields) end circular_saw.known_nodes[recipeitem] = {modname, subname}