diff --git a/init.lua b/init.lua index b6f1e28..fc2a528 100644 --- a/init.lua +++ b/init.lua @@ -147,21 +147,22 @@ end -- the actual nodes! +minetest.register_node("coloredwood:wood_block", { + description = "Colored wooden planks", + tiles = { "coloredwood_base.png" }, + paramtype = "light", + paramtype2 = "color", + palette = "unifieddyes_palette_extended.png", + place_param2 = 240, + walkable = true, + sunlight_propagates = false, + groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2, not_in_creative_inventory=1, ud_param2_colorable = 1}, + sounds = default.node_sound_wood_defaults(), + after_dig_node = unifieddyes.after_dig_node, + drop = "default:wood" +}) + for _, color in ipairs(coloredwood.hues_plus_greys) do - minetest.register_node("coloredwood:wood_"..color, { - description = "Colored wooden planks", - tiles = { "coloredwood_base.png" }, - paramtype = "light", - paramtype2 = "colorfacedir", - palette = "unifieddyes_palette_"..color.."s.png", - walkable = true, - sunlight_propagates = false, - ud_replacement_node = "coloredwood:wood_"..color, - groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2, not_in_creative_inventory=1, ud_param2_colorable = 1}, - sounds = default.node_sound_wood_defaults(), - after_dig_node = unifieddyes.after_dig_node, - drop = "default:wood" - }) -- moreblocks/stairsplus support @@ -226,8 +227,10 @@ end end minetest.override_item("default:wood", { - paramtype2 = "colorfacedir", - ud_replacement_node = "coloredwood:wood_grey", + paramtype2 = "color", + palette = "unifieddyes_palette_extended.png", + place_param2 = 240, + ud_replacement_node = "coloredwood:wood_block", groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2, wood = 1, ud_param2_colorable = 1}, }) @@ -237,7 +240,8 @@ minetest.register_node("coloredwood:fence", { tiles = { "coloredwood_fence_base.png" }, paramtype = "light", paramtype2 = "color", - palette = "unifieddyes_palette.png", + palette = "unifieddyes_palette_extended.png", + place_param2 = 240, walkable = true, groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2, ud_param2_colorable = 1}, sounds = default.node_sound_wood_defaults(), @@ -250,6 +254,8 @@ minetest.register_node("coloredwood:fence", { }) minetest.override_item("default:fence_wood", { + palette = "unifieddyes_palette_extended.png", + place_param2 = 240, ud_replacement_node = "coloredwood:fence", groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2, ud_param2_colorable = 1} }) @@ -258,8 +264,10 @@ minetest.override_item("default:fence_wood", { -- convert the old static nodes coloredwood.old_static_nodes = {} +coloredwood.old_13_color_nodes = {} for _, hue in ipairs(coloredwood.hues) do + table.insert(coloredwood.old_13_color_nodes, "coloredwood:wood_"..hue) for _, sat in ipairs({"", "_s50"}) do for _, val in ipairs ({"dark_", "medium_", "light_", ""}) do table.insert(coloredwood.old_static_nodes, "coloredwood:wood_"..val..hue..sat) @@ -273,6 +281,9 @@ for _, shade in ipairs(coloredwood.greys) do table.insert(coloredwood.old_static_nodes, "coloredwood:fence_"..shade) end +table.insert(coloredwood.old_13_color_nodes, "coloredwood:wood_grey") + + -- add all of the stairsplus nodes, if moreblocks is installed. if coloredwood.enable_stairsplus then for _, shape in ipairs(circular_saw.names) do @@ -298,6 +309,28 @@ if coloredwood.enable_stairsplus then end end +local old_shades = { + "", + "", + "", + "light_", + "medium_", + "medium_", + "dark_", + "dark_" +} + +local old_greys = { + "white", + "white", + "light_grey", + "grey", + "dark_grey", + "black", + "white", + "white" +} + minetest.register_lbm({ name = "coloredwood:convert", label = "Convert wood blocks, fences, stairsplus stuff, etc to use param2 color", @@ -306,15 +339,13 @@ minetest.register_lbm({ action = function(pos, node) local meta = minetest.get_meta(pos) - if meta and (meta:get_string("dye") ~= "") then return end -- node has already been converted before. - local name = node.name local hue, sat, val = unifieddyes.get_hsv(name) - local color = val..hue..sat - local s1, s2 = is_stairsplus(name) + if meta and (meta:get_string("dye") ~= "") then return end -- node has already been converted before. + if s1 then if not s2 then print("impossible conversion request! name = "..node.name.." --> ".."coloredwood:"..s1.."_wood_"..hue.."*nil*") return end @@ -328,18 +359,59 @@ minetest.register_lbm({ meta:set_string("dye", "unifieddyes:"..color) elseif string.find(name, ":fence") then - local paletteidx, hue = unifieddyes.getpaletteidx("unifieddyes:"..color, false) + local paletteidx, hue = unifieddyes.getpaletteidx("unifieddyes:"..color, "extended") minetest.set_node(pos, { name = "coloredwood:fence", param2 = paletteidx }) meta:set_string("dye", "unifieddyes:"..color) + meta:set_string("palette", "ext") else - local paletteidx, hue = unifieddyes.getpaletteidx("unifieddyes:"..color, true) - if hue ~= 0 and hue ~= nil then - minetest.set_node(pos, { name = "coloredwood:wood_"..coloredwood.hues[hue], param2 = paletteidx }) - meta:set_string("dye", "unifieddyes:"..color) - else - minetest.set_node(pos, { name = "coloredwood:wood_grey", param2 = paletteidx }) - meta:set_string("dye", "unifieddyes:"..color) + if hue == "aqua" then + hue = "spring" + elseif hue == "skyblue" then + hue = "azure" + elseif hue == "redviolet" then + hue = "rose" end + + color = val..hue..sat + + local paletteidx, hue = unifieddyes.getpaletteidx("unifieddyes:"..color, "extended") + minetest.set_node(pos, { name = "coloredwood:wood_block", param2 = paletteidx }) + meta:set_string("dye", "unifieddyes:"..color) + meta:set_string("palette", "ext") + end + end +}) + +table.insert(coloredwood.old_13_color_nodes, "coloredwood:fence") + +minetest.register_lbm({ + name = "coloredwood:recolor_basics", + label = "Convert fences and base 13-color wood to use UD extended palette", + run_at_every_load = true, + nodenames = coloredwood.old_13_color_nodes, + action = function(pos, node) + local meta = minetest.get_meta(pos) + if meta:get_string("palette") ~= "ext" then + if node.name == "coloredwood:fence" then + minetest.swap_node(pos, { name = node.name, param2 = unifieddyes.convert_classic_palette[node.param2] }) + else + local hue = string.sub(node.name, 18) + local shadenum = math.floor(node.param2/32) + 1 + local shade = old_shades[shadenum] + local sat = "" + + if hue == "grey" then + hue = old_greys[shadenum] + shade = "" + sat = "" + elseif shadenum == 3 or shadenum == 6 or shadenum == 8 then + sat = "_s50" + end + + local newcolor = unifieddyes.convert_classic_palette[unifieddyes.getpaletteidx("unifieddyes:"..shade..hue..sat)] + minetest.swap_node(pos, { name = "coloredwood:wood_block", param2 = newcolor }) + end + meta:set_string("palette", "ext") end end })