mirror of
https://github.com/mt-mods/unifieddyes.git
synced 2024-11-22 23:43:45 +01:00
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]
This commit is contained in:
parent
4f1303aac1
commit
3f7fb1af74
43
init.lua
43
init.lua
@ -217,47 +217,60 @@ function unifieddyes.on_rightclick(pos, node, player, stack, pointed_thing, newn
|
|||||||
stack:take_item()
|
stack:take_item()
|
||||||
node.param2 = paletteidx
|
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
|
if newnode then
|
||||||
node.name = newnode
|
|
||||||
if colorfdir then -- we probably need to change the hue 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 oldhue ~= nil then -- it's been painted before
|
||||||
if hue ~= 0 then -- the player's wielding a colored dye
|
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
|
else -- it's a greyscale dye
|
||||||
node.name = string.gsub(node.name, "_"..HUES[oldhue], "_grey")
|
newnode = string.gsub(newnode, "_"..oldhue, "_grey")
|
||||||
end
|
end
|
||||||
else -- it's never had a color at all
|
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
|
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
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if hue ~= 0 then -- greyscale dye on greyscale node = no hue change
|
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
|
end
|
||||||
end
|
end
|
||||||
|
node.name = newnode
|
||||||
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
|
newnode = oldnode -- note that here, newnode/oldnode are a full node, not just the name.
|
||||||
node.name = string.gsub(node.name, HUES[oldhue], HUES[hue])
|
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)
|
end
|
||||||
|
newnode.param2 = paletteidx + (minetest.get_node(pos).param2 % 32)
|
||||||
|
minetest.set_node(pos, newnode)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if unifieddyes.is_buildable_to(player:get_player_name(), pos2) and
|
if unifieddyes.is_buildable_to(player:get_player_name(), pos2) and
|
||||||
minetest.registered_nodes[name] then
|
minetest.registered_nodes[name] then
|
||||||
local placeable_node = minetest.registered_nodes[stack:get_name()]
|
local placeable_node = minetest.registered_nodes[stack:get_name()]
|
||||||
minetest.set_node(pos2, placeable_node)
|
minetest.set_node(pos2, placeable_node)
|
||||||
|
print(minetest.get_node(pos).name)
|
||||||
stack:take_item()
|
stack:take_item()
|
||||||
return stack
|
return stack
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user