From 3f7fb1af74ffc9908a8ac8607de1f3323d8494df Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Thu, 26 Jan 2017 11:06:06 -0500 Subject: Just do the node's color search manually (to handle cases where the node has more than just the standard-format nodename:[shade_]hue[_s50] naming, e.g. stairsplus nodes like: nodename:stair_[shade_]hue[_s50][_some_extra_details] --- init.lua | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/init.lua b/init.lua index d2ff67a..9b14739 100644 --- a/init.lua +++ b/init.lua @@ -217,47 +217,60 @@ function unifieddyes.on_rightclick(pos, node, player, stack, pointed_thing, newn stack:take_item() node.param2 = paletteidx - local oldpaletteidx, oldhue = unifieddyes.getpaletteidx(prevdye, colorfdir) + local oldpaletteidx, oldhuenum = unifieddyes.getpaletteidx(prevdye, colorfdir) + + local oldnode = minetest.get_node(pos) + + local oldhue = nil + for _, i in ipairs(HUES) do + if string.find(oldnode.name, "_"..i) and not + ( string.find(oldnode.name, "_redviolet") and i == "red" ) then + oldhue = i + break + end + end if newnode then - node.name = newnode if colorfdir then -- we probably need to change the hue of the node too if oldhue ~=0 then -- it's colored, not grey - print("at line 226") - print("prevdye = "..dump(prevdye)) - print("oldhue = "..dump(oldhue).." "..dump(HUES[oldhue])) - print("hue = "..dump(hue).." "..dump(HUES[hue])) - print("node.name = "..dump(node.name)) if oldhue ~= nil then -- it's been painted before if hue ~= 0 then -- the player's wielding a colored dye - node.name = string.gsub(node.name, "_"..HUES[oldhue], "_"..HUES[hue]) + newnode = string.gsub(newnode, "_"..oldhue, "_"..HUES[hue]) else -- it's a greyscale dye - node.name = string.gsub(node.name, "_"..HUES[oldhue], "_grey") + newnode = string.gsub(newnode, "_"..oldhue, "_grey") end else -- it's never had a color at all if hue ~= 0 then -- and if the wield is greyscale, don't change the node name - node.name = string.gsub(node.name, "_grey", "_"..HUES[hue]) + newnode = string.gsub(newnode, "_grey", "_"..HUES[hue]) end end else if hue ~= 0 then -- greyscale dye on greyscale node = no hue change - node.name = string.gsub(node.name, "_grey", "_"..HUES[hue]) + newnode = string.gsub(newnode, "_grey", "_"..HUES[hue]) end end end - + node.name = newnode minetest.swap_node(pos, node) else - if colorfdir then -- we probably need to change the color of the node too - node.name = string.gsub(node.name, HUES[oldhue], HUES[hue]) + newnode = oldnode -- note that here, newnode/oldnode are a full node, not just the name. + if colorfdir then + print("prevdye = "..dump(prevdye)) + print("hue = "..dump(hue).." "..dump(HUES[hue])) + print("newnode.name = "..newnode.name) + if oldhue then + newnode.name = string.gsub(newnode.name, "_"..oldhue, "_"..HUES[hue]) + end end - minetest.swap_node(pos, node) + newnode.param2 = paletteidx + (minetest.get_node(pos).param2 % 32) + minetest.set_node(pos, newnode) end else if unifieddyes.is_buildable_to(player:get_player_name(), pos2) and minetest.registered_nodes[name] then local placeable_node = minetest.registered_nodes[stack:get_name()] minetest.set_node(pos2, placeable_node) + print(minetest.get_node(pos).name) stack:take_item() return stack end -- cgit v1.2.3