carpets/api.lua

57 lines
1.4 KiB
Lua
Raw Normal View History

2016-09-04 17:09:25 +02:00
local carpet_proto = {
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.45, 0.5}
},
groups = {
snappy = 2,
flammable = 3,
oddly_breakable_by_hand = 3,
choppy = 2,
carpet = 1,
2016-11-05 07:17:08 +01:00
}
2016-09-04 17:09:25 +02:00
}
-- Register the carpet and recipe using material
-- material - already registered material item the textures and sounds applied from
-- def - optional additional - or overriding data passed to minetest.register_node()
carpets = {}
2016-09-04 17:09:25 +02:00
function carpets.register(material, def)
local node = table.copy(carpet_proto)
if def then
for k,v in pairs(def) do
node[k] = v
end
2016-09-04 17:09:25 +02:00
end
local material_def = minetest.registered_nodes[material]
node.description = node.description or material_def.description.." carpet"
node.sounds = table.copy(node.sounds or material_def.sounds or default.node_sound_defaults())
node.groups = table.copy(node.groups)
2016-09-04 17:09:25 +02:00
if node.tiles then
node.tiles = table.copy(node.tiles)
elseif material_def.tiles[6] then
node.tiles = {material_def.tiles[6]}
else
node.tiles = table.copy(material_def.tiles)
2016-09-04 17:09:25 +02:00
end
local name = "carpet:" .. (node.name or material:gsub(":", "_"))
2016-09-04 17:09:25 +02:00
node.name = nil
2016-11-05 07:17:08 +01:00
minetest.register_node(":" .. name, node)
2016-09-04 17:09:25 +02:00
minetest.register_craft({
2016-11-05 07:17:08 +01:00
output = name .. " 32",
recipe = {
{"group:wool", "group:wool", "group:wool"},
{"group:wool", material, "group:wool"}
2016-11-05 07:17:08 +01:00
}
2016-09-04 17:09:25 +02:00
})
end