handle special cases for greyscale dyes and unpainted nodes

This commit is contained in:
Vanessa Ezekowitz 2017-01-26 07:10:48 -05:00
parent 1773af6868
commit 4f1303aac1

@ -191,8 +191,7 @@ function unifieddyes.on_destruct(pos)
end end
end end
function unifieddyes.on_rightclick(pos, node, player, stack, pointed_thing, newnode) function unifieddyes.on_rightclick(pos, node, player, stack, pointed_thing, newnode, colorfdir)
local colorfdir = (minetest.registered_nodes[minetest.get_node(pos).name].paramtype2 == "colorfacedir")
local name = player:get_player_name() local name = player:get_player_name()
if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then
minetest.record_protection_violation(pos,name) minetest.record_protection_violation(pos,name)
@ -222,13 +221,31 @@ function unifieddyes.on_rightclick(pos, node, player, stack, pointed_thing, newn
if newnode then if newnode then
node.name = newnode node.name = newnode
if colorfdir then -- we probably need to change the color of the node too if colorfdir then -- we probably need to change the hue of the node too
if oldhue ~=0 then -- it's colored, not grey 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]) node.name = string.gsub(node.name, "_"..HUES[oldhue], "_"..HUES[hue])
else else -- it's a greyscale dye
node.name = string.gsub(node.name, "_"..HUES[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]) node.name = string.gsub(node.name, "_grey", "_"..HUES[hue])
end end
end end
else
if hue ~= 0 then -- greyscale dye on greyscale node = no hue change
node.name = string.gsub(node.name, "_grey", "_"..HUES[hue])
end
end
end
minetest.swap_node(pos, node) minetest.swap_node(pos, node)
else else
if colorfdir then -- we probably need to change the color of the node too if colorfdir then -- we probably need to change the color of the node too