Move node registrations to a separate file

This commit is contained in:
Thomas--S 2018-03-03 20:15:09 +01:00 committed by Hugo Locurcio
parent 4d2a7ab6fe
commit c711946453
7 changed files with 66 additions and 91 deletions

60
stairsplus/common.lua Normal file
View File

@ -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

View File

@ -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")

View File

@ -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)

View File

@ -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)

View File

@ -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}

View File

@ -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}

View File

@ -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}