Use tables for registering colored nodes (fix of #2, p1)

This commit is contained in:
Mikita Wiśniewski 2022-04-30 21:18:18 +07:00
parent 79b53ce5a6
commit 4f43fcf650
2 changed files with 180 additions and 209 deletions

View File

@ -2,8 +2,38 @@
local S = minetest.get_translator(minetest.get_current_modname())
--=-- API --=--
function mcl_decor.register_armchair(color, desc, tiles, dye, colorgroup)
mcl_decor.colors = {
-- color, wool texture, armchair desc, curtains desc, dyed planks desc, dye, colorgroup hexcolor
{"white", "wool_white", S("White Armchair"), S("White Curtains"), S("White Planks"), "white", "unicolor_white", "#EDEDED"},
{"grey", "wool_dark_grey", S("Grey Armchair"), S("Grey Curtains"), S("Grey Planks"), "dark_grey", "unicolor_darkgrey", "#5F5F5F"},
{"silver", "wool_grey", S("Light Grey Armchair"), S("Light Grey Curtains"), S("Light Grey Planks"), "grey", "unicolor_grey", "#8C8C8C"},
{"black", "wool_black", S("Black Armchair"), S("Black Curtains"), S("Black Planks"), "black", "unicolor_black", "#030303"},
{"red", "wool_red", S("Red Armchair"), S("Red Curtains"), S("Red Planks"), "red", "unicolor_red", "#BD0000"},
{"yellow", "wool_yellow", S("Yellow Armchair"), S("Yellow Curtains"), S("Yellow Planks"), "yellow", "unicolor_yellow", "#EBD800"},
{"green", "wool_dark_green", S("Green Armchair"), S("Green Curtains"), S("Green Planks"), "dark_green", "unicolor_dark_green", "#086400"},
{"cyan", "wool_cyan", S("Cyan Armchair"), S("Cyan Curtains"), S("Cyan Planks"), "cyan", "unicolor_cyan", "#00C4B4"},
{"blue", "wool_blue", S("Blue Armchair"), S("Blue Curtains"), S("Blue Planks"), "blue", "unicolor_blue", "#0B1E80"},
{"magenta", "wool_magenta", S("Magenta Armchair"), S("Magenta Curtains"), S("Magenta Planks"), "magenta", "unicolor_red_violet", "#954395"},
{"orange", "wool_orange", S("Orange Armchair"), S("Orange Curtains"), S("Orange Planks"), "orange", "unicolor_orange", "#E68200"},
{"purple", "wool_violet", S("Purple Armchair"), S("Purple Curtains"), S("Purple Planks"), "violet", "unicolor_violet", "#461A6D"},
{"brown", "wool_brown", S("Brown Armchair"), S("Brown Curtains"), S("Brown Planks"), "brown", "unicolor_dark_orange", "#432209"},
{"pink", "wool_pink", S("Pink Armchair"), S("Pink Curtains"), S("Pink Planks"), "pink", "unicolor_light_red", "#ED9BB4"},
{"lime", "mcl_wool_lime", S("Lime Armchair"), S("Lime Curtains"), S("Lime Planks"), "green", "unicolor_green", "#B3DF86"},
{"light_blue", "mcl_wool_light_blue", S("Light Blue Armchair"), S("Light Blue Curtains"), S("Light Blue Planks"), "lightblue", "unicolor_light_blue,", "#72A4D4"},
}
for _, row in ipairs(mcl_decor.colors) do
-- define rows
local color = row[1]
local wooltile = row[2]
local desc = row[3]
local desc2 = row[4]
local desc3 = row[5]
local dye = row[6]
local colorgroup = row[7]
local hexcolor = row[8]
-- register armchairs
minetest.register_node("mcl_decor:"..color.."_armchair", {
description = desc,
drawtype = "nodebox",
@ -17,7 +47,7 @@ function mcl_decor.register_armchair(color, desc, tiles, dye, colorgroup)
{-0.5, -0.5, -0.4375, 0.5, -0.4375, 0.5},
}
},
tiles = {tiles},
tiles = {wooltile..".png"},
is_ground_content = false,
paramtype = "light",
paramtype2 = "facedir",
@ -58,44 +88,21 @@ function mcl_decor.register_armchair(color, desc, tiles, dye, colorgroup)
recipe = "mcl_decor:"..color.."_armchair",
burntime = 10,
})
end
function mcl_decor.register_dyed_planks(color, desc, hexcolor, dye, colorgroup)
minetest.register_node("mcl_decor:"..color.."_planks", {
description = desc,
tiles = {"mcl_decor_dyed_planks.png^[colorize:" .. hexcolor .. ":125"},
stack_max = 64,
is_ground_content = false,
groups = {handy=1, axey=1, flammable=3, wood=1, building_block=1, material_wood=1, fire_encouragement=5, fire_flammability=20, [colorgroup]=1},
sounds = mcl_sounds.node_sound_wood_defaults(),
_mcl_blast_resistance = 3,
_mcl_hardness = 2,
})
minetest.register_craft({
type = "shapeless",
output = "mcl_decor:"..color.."_planks",
recipe = {"group:wood", "mcl_dye:"..dye}
})
-- maybe descriptions of slabs/stairs after that workaround will be VERY CRAPPY (especially with translations via locales), but at least it works
mcl_stairs.register_stair_and_slab_simple(
color.."_planks", "mcl_decor:"..color.."_planks", desc..S(" Stair"), desc..S(" Slab"), S("Double")..desc..S(" Slab"), "woodlike"
)
end
function mcl_decor.register_curtains(color, desc, wool, wooltile, dye, colorgroup)
-- register curtains
minetest.register_node("mcl_decor:curtain_"..color, {
description = desc,
description = desc2,
tiles = {
wooltile.."^mcl_decor_curtain_alpha.png^[makealpha:255,126,126^mcl_decor_curtain_overlay.png", -- front
wooltile.."^mcl_decor_curtain_alpha.png^[makealpha:255,126,126^mcl_decor_curtain_overlay.png^[transformFY", -- back
wooltile.."^mcl_decor_curtain_overlay.png^[transformR270", -- side
wooltile.."^mcl_decor_curtain_overlay.png^[transformR90", -- side
wooltile.."^mcl_decor_curtain_overlay.png^[transformFY", -- top
wooltile.."^mcl_decor_curtain_alpha.png^[makealpha:255,126,126^mcl_decor_curtain_overlay.png", -- bottom
wooltile..".png".."^mcl_decor_curtain_alpha.png^[makealpha:255,126,126^mcl_decor_curtain_overlay.png",
wooltile..".png".."^mcl_decor_curtain_alpha.png^[makealpha:255,126,126^mcl_decor_curtain_overlay.png^[transformFY",
wooltile..".png".."^mcl_decor_curtain_overlay.png^[transformR270",
wooltile..".png".."^mcl_decor_curtain_overlay.png^[transformR90",
wooltile..".png".."^mcl_decor_curtain_overlay.png^[transformFY",
wooltile..".png".."^mcl_decor_curtain_alpha.png^[makealpha:255,126,126^mcl_decor_curtain_overlay.png",
},
stack_max = 64,
inventory_image = wooltile.."^mcl_decor_curtain_alpha.png^[makealpha:255,126,126^mcl_decor_curtain_overlay.png",
wield_image = wooltile.."^mcl_decor_curtain_alpha.png^[makealpha:255,126,126^mcl_decor_curtain_overlay.png",
inventory_image = wooltile..".png".."^mcl_decor_curtain_alpha.png^[makealpha:255,126,126^mcl_decor_curtain_overlay.png",
wield_image = wooltile..".png".."^mcl_decor_curtain_alpha.png^[makealpha:255,126,126^mcl_decor_curtain_overlay.png",
walkable = false,
sunlight_propagates = true,
drawtype = "nodebox",
@ -114,14 +121,14 @@ function mcl_decor.register_curtains(color, desc, wool, wooltile, dye, colorgrou
end
})
minetest.register_node("mcl_decor:curtain_"..color.."_closed", {
description = desc..S(" (closed)"),
description = desc2..S(" (closed)"),
tiles = {
wooltile.."^mcl_decor_curtain_overlay.png", -- front
wooltile.."^mcl_decor_curtain_overlay.png^[transformFY", -- back
wooltile.."^mcl_decor_curtain_overlay.png^[transformR270", -- side
wooltile.."^mcl_decor_curtain_overlay.png^[transformR90", -- side
wooltile.."^mcl_decor_curtain_overlay.png^[transformFY", -- top
wooltile.."^mcl_decor_curtain_overlay.png", -- bottom
wooltile..".png".."^mcl_decor_curtain_overlay.png",
wooltile..".png".."^mcl_decor_curtain_overlay.png^[transformFY",
wooltile..".png".."^mcl_decor_curtain_overlay.png^[transformR270",
wooltile..".png".."^mcl_decor_curtain_overlay.png^[transformR90",
wooltile..".png".."^mcl_decor_curtain_overlay.png^[transformFY",
wooltile..".png".."^mcl_decor_curtain_overlay.png",
},
walkable = false,
sunlight_propagates = true,
@ -145,8 +152,8 @@ function mcl_decor.register_curtains(color, desc, wool, wooltile, dye, colorgrou
output = "mcl_decor:curtain_"..color,
recipe = {
{"mcl_core:iron_ingot", "mcl_core:stick", "mcl_core:iron_ingot"},
{wool, wool, wool},
{wool, "", wool}
{"mcl_wool:"..color, "mcl_wool:"..color, "mcl_wool:"..color},
{"mcl_wool:"..color, "", "mcl_wool:"..color}
}
})
minetest.register_craft({
@ -154,61 +161,25 @@ function mcl_decor.register_curtains(color, desc, wool, wooltile, dye, colorgrou
output = "mcl_decor:curtain_"..color,
recipe = {"group:curtain", "mcl_dye:"..dye},
})
-- register dyed planks
minetest.register_node("mcl_decor:"..color.."_planks", {
description = desc3,
tiles = {"mcl_decor_dyed_planks.png^[colorize:"..hexcolor..":125"},
stack_max = 64,
is_ground_content = false,
groups = {handy=1, axey=1, flammable=3, wood=1, building_block=1, material_wood=1, fire_encouragement=5, fire_flammability=20, [colorgroup]=1},
sounds = mcl_sounds.node_sound_wood_defaults(),
_mcl_blast_resistance = 3,
_mcl_hardness = 2,
})
minetest.register_craft({
type = "shapeless",
output = "mcl_decor:"..color.."_planks",
recipe = {"group:wood", "mcl_dye:"..dye}
})
-- maybe descriptions of slabs/stairs after that workaround will be VERY CRAPPY (especially with translations via locales), but at least it works
mcl_stairs.register_stair_and_slab_simple(
color.."_planks", "mcl_decor:"..color.."_planks", desc3..S(" Stair"), desc3..S(" Slab"), S("Double")..desc3..S(" Slab"), "woodlike"
)
end
--=-- REGISTER --=--
--- Armchairs ---
mcl_decor.register_armchair("white", S("White Armchair"), "wool_white.png", "white", "unicolor_white")
mcl_decor.register_armchair("grey", S("Grey Armchair"), "wool_dark_grey.png", "dark_grey", "unicolor_darkgrey")
mcl_decor.register_armchair("silver", S("Light Grey Armchair"), "wool_grey.png", "grey", "unicolor_grey")
mcl_decor.register_armchair("black", S("Black Armchair"), "wool_black.png", "black", "unicolor_black")
mcl_decor.register_armchair("red", S("Red Armchair"), "wool_red.png", "red", "unicolor_red")
mcl_decor.register_armchair("yellow", S("Yellow Armchair"), "wool_yellow.png", "yellow", "unicolor_yellow")
mcl_decor.register_armchair("green", S("Green Armchair"), "wool_dark_green.png", "dark_green", "unicolor_dark_green")
mcl_decor.register_armchair("cyan", S("Cyan Armchair"), "wool_cyan.png", "cyan", "unicolor_cyan")
mcl_decor.register_armchair("blue", S("Blue Armchair"), "wool_blue.png", "blue", "unicolor_blue")
mcl_decor.register_armchair("magenta", S("Magenta Armchair"), "wool_magenta.png", "magenta", "unicolor_red_violet")
mcl_decor.register_armchair("orange", S("Orange Armchair"), "wool_orange.png", "orange", "unicolor_orange")
mcl_decor.register_armchair("purple", S("Purple Armchair"), "wool_violet.png", "violet", "unicolor_violet")
mcl_decor.register_armchair("brown", S("Brown Armchair"), "wool_brown.png", "brown", "unicolor_dark_orange")
mcl_decor.register_armchair("pink", S("Pink Armchair"), "wool_pink.png", "pink", "unicolor_light_red")
mcl_decor.register_armchair("lime", S("Lime Armchair"), "mcl_wool_lime.png", "green", "unicolor_green")
mcl_decor.register_armchair("light_blue", S("Light Blue Armchair"), "mcl_wool_light_blue.png", "lightblue", "unicolor_light_blue")
--- Curtains ---
mcl_decor.register_curtains("white", S("White Curtains"), "mcl_wool:white", "wool_white.png", "white", "unicolor_white")
mcl_decor.register_curtains("grey", S("Grey Curtains"), "mcl_wool:grey", "wool_dark_grey.png", "dark_grey", "unicolor_darkgrey")
mcl_decor.register_curtains("silver", S("Light Grey Curtains"), "mcl_wool:silver", "wool_grey.png", "grey", "unicolor_grey")
mcl_decor.register_curtains("black", S("Black Curtains"), "mcl_wool:black", "wool_black.png", "black", "unicolor_black")
mcl_decor.register_curtains("red", S("Red Curtains"), "mcl_wool:red", "wool_red.png", "red", "unicolor_red")
mcl_decor.register_curtains("yellow", S("Yellow Curtains"), "mcl_wool:yellow", "wool_yellow.png", "yellow", "unicolor_yellow")
mcl_decor.register_curtains("green", S("Green Curtains"), "mcl_wool:green", "wool_dark_green.png", "dark_green", "unicolor_dark_green")
mcl_decor.register_curtains("cyan", S("Cyan Curtains"), "mcl_wool:cyan", "wool_cyan.png", "cyan", "unicolor_cyan")
mcl_decor.register_curtains("blue", S("Blue Curtains"), "mcl_wool:blue", "wool_blue.png", "blue", "unicolor_blue")
mcl_decor.register_curtains("magenta", S("Magenta Curtains"), "mcl_wool:magenta", "wool_magenta.png", "magenta", "unicolor_red_violet")
mcl_decor.register_curtains("orange", S("Orange Curtains"), "mcl_wool:orange", "wool_orange.png", "orange", "unicolor_orange")
mcl_decor.register_curtains("purple", S("Purple Curtains"), "mcl_wool:purple", "wool_violet.png", "violet", "unicolor_violet")
mcl_decor.register_curtains("brown", S("Brown Curtains"), "mcl_wool:brown", "wool_brown.png", "brown", "unicolor_dark_orange")
mcl_decor.register_curtains("pink", S("Pink Curtains"), "mcl_wool:pink", "wool_pink.png", "pink", "unicolor_light_red")
mcl_decor.register_curtains("lime", S("Lime Curtains"), "mcl_wool:lime", "mcl_wool_lime.png", "green", "unicolor_green")
mcl_decor.register_curtains("light_blue", S("Light Blue Curtains"), "mcl_wool:light_blue", "mcl_wool_light_blue.png", "lightblue", "unicolor_light_blue")
--- Dyed Planks ---
mcl_decor.register_dyed_planks("white", S("White Planks"), "#EDEDED", "white", "unicolor_white")
mcl_decor.register_dyed_planks("grey", S("Grey Planks"), "#5F5F5F", "dark_grey", "unicolor_darkgrey")
mcl_decor.register_dyed_planks("silver", S("Light Grey Planks"), "#8C8C8C", "grey", "unicolor_grey")
mcl_decor.register_dyed_planks("black", S("Black Planks"), "#030303", "black", "unicolor_black")
mcl_decor.register_dyed_planks("red", S("Red Planks"), "#BD0000", "red", "unicolor_red")
mcl_decor.register_dyed_planks("yellow", S("Yellow Planks"), "#EBD800", "yellow", "unicolor_yellow")
mcl_decor.register_dyed_planks("green", S("Green Planks"), "#086400", "dark_green", "unicolor_dark_green")
mcl_decor.register_dyed_planks("cyan", S("Cyan Planks"), "#00C4B4", "cyan", "unicolor_cyan")
mcl_decor.register_dyed_planks("blue", S("Blue Planks"), "#0B1E80", "blue", "unicolor_blue")
mcl_decor.register_dyed_planks("magenta", S("Magenta Planks"), "#954395", "magenta", "unicolor_red_violet")
mcl_decor.register_dyed_planks("orange", S("Orange Planks"), "#E68200", "orange", "unicolor_orange")
mcl_decor.register_dyed_planks("purple", S("Purple Planks"), "#461A6D", "violet", "unicolor_violet")
mcl_decor.register_dyed_planks("brown", S("Brown Planks"), "#432209", "brown", "unicolor_dark_orange")
mcl_decor.register_dyed_planks("pink", S("Pink Planks"), "#ED9BB4", "pink", "unicolor_light_red")
mcl_decor.register_dyed_planks("lime", S("Lime Planks"), "#B3DF86", "green", "unicolor_green")
mcl_decor.register_dyed_planks("light_blue", S("Light Blue Planks"), "#72A4D4", "lightblue", "unicolor_light_blue")

View File

@ -3,7 +3,7 @@
local S = minetest.get_translator(minetest.get_current_modname())
--=-- API --=--
function mcl_decor.register_chair_and_table(name, desc, desc2, material, tiles, groups)
function mcl_decor.register_chair_and_table(name, desc, desc2, material, tiles, group)
if group == nil then
group = {handy=1, axey=1, attached_node=1, material_wood=1, deco_block=1, flammable=-1}
else