diff options
Diffstat (limited to 'unifieddyes/init.lua')
-rw-r--r-- | unifieddyes/init.lua | 83 |
1 files changed, 62 insertions, 21 deletions
diff --git a/unifieddyes/init.lua b/unifieddyes/init.lua index 49dca11..09b156f 100644 --- a/unifieddyes/init.lua +++ b/unifieddyes/init.lua @@ -58,6 +58,9 @@ unifieddyes.HUES = { "redviolet" } +unifieddyes.HUES_WITH_GREY = table.copy(unifieddyes.HUES) +table.insert(unifieddyes.HUES_WITH_GREY, "grey") + -- the names of the various colors here came from http://www.procato.com/rgb+index/ unifieddyes.HUES_EXTENDED = { @@ -203,6 +206,35 @@ end function unifieddyes.after_dig_node(foo) end +-- This helper function creates multiple copies of the passed node, +-- for the split palette - one per hue, plus grey - and assigns +-- proper palettes and other attributes + +function unifieddyes.generate_split_palette_nodes(name, def, drop) + for _, color in ipairs(unifieddyes.HUES_WITH_GREY) do + local def2 = table.copy(def) + local desc_color = string.gsub(string.upper(string.sub(color, 1, 1))..string.sub(color, 2), "_", " ") + if string.sub(def2.description, -1) == ")" then + def2.description = string.sub(def2.description, 1, -2)..", "..desc_color..")" + else + def2.description = def2.description.."("..desc_color..")" + end + def2.palette = "unifieddyes_palette_"..color.."s.png" + def2.paramtype2 = "colorfacedir" + def2.groups.ud_param2_colorable = 1 + + if drop then + def2.drop = { + items = { + {items = {drop.."_"..color}, inherit_color = true }, + } + } + end + + minetest.register_node(":"..name.."_"..color, def2) + end +end + -- This helper function creates a colored itemstack function unifieddyes.make_colored_itemstack(item, palette, color) @@ -233,18 +265,19 @@ local function register_c(craft, hue, sat, val) recipe = string.gsub(recipe, "NEUTRAL_NODE", craft.neutral_node) local newrecipe = minetest.deserialize(recipe) - local output = craft.output + local coutput = craft.output or "" + local output = coutput if craft.output_prefix then if craft.palette ~= "split" then - output = craft.output_prefix..color..craft.output_suffix + output = craft.output_prefix..color..craft.output_suffix..coutput else if hue == "white" or hue == "black" or string.find(hue, "grey") then - output = craft.output_prefix.."grey"..craft.output_suffix + output = craft.output_prefix.."grey"..craft.output_suffix..coutput elseif hue == "pink" then dye = "dye:light_red" - output = craft.output_prefix.."red"..craft.output_suffix + output = craft.output_prefix.."red"..craft.output_suffix..coutput else - output = craft.output_prefix..hue..craft.output_suffix + output = craft.output_prefix..hue..craft.output_suffix..coutput end end end @@ -646,21 +679,24 @@ function unifieddyes.on_airbrush(itemstack, player, pointed_thing) return end - if not def.palette or not (def.groups and def.groups.ud_param2_colorable > 0) then + if not (def.groups and def.groups.ud_param2_colorable and def.groups.ud_param2_colorable > 0) then minetest.chat_send_player(player_name, "*** That node can't be colored.") return end local palette = nil local fdir = 0 - if def.palette == "unifieddyes_palette_extended.png" then + if def.paramtype2 == "color" then palette = "extended" - elseif def.palette == "unifieddyes_palette_colorwallmounted.png" then + elseif def.paramtype2 == "colorwallmounted" then palette = "wallmounted" fdir = node.param2 % 8 - else + elseif def.paramtype2 == "colorfacedir" then palette = "split" fdir = node.param2 % 32 + else + minetest.chat_send_player(player_name, "*** That node can't be colored -- it has an invalid color mode.") + return end local idx, hue = unifieddyes.getpaletteidx(painting_with, palette) @@ -683,6 +719,7 @@ function unifieddyes.on_airbrush(itemstack, player, pointed_thing) local name = def.airbrush_replacement_node or node.name if palette == "split" then + local modname = string.sub(name, 1, string.find(name, ":")-1) local nodename2 = string.sub(name, string.find(name, ":")+1) local oldcolor = "snozzberry" @@ -698,16 +735,20 @@ function unifieddyes.on_airbrush(itemstack, player, pointed_thing) newcolor = "grey" end - local s = string.sub(def.palette, 21) - oldcolor = string.sub(s, 1, string.find(s, "s.png")-1) + if def.airbrush_replacement_node then + oldcolor = "grey" + else + local s = string.sub(def.palette, 21) + oldcolor = string.sub(s, 1, string.find(s, "s.png")-1) + end end if newcolor == "spring" then newcolor = "aqua" elseif newcolor == "azure" then newcolor = "skyblue" elseif newcolor == "rose" then newcolor = "redviolet" end - name = modname..":"..string.gsub(nodename2, oldcolor, newcolor) + if not minetest.registered_items[name] then minetest.chat_send_player(player_name, "*** "..string.sub(painting_with, 5).." can't be applied to that node.") return @@ -855,22 +896,22 @@ function unifieddyes.show_airbrush_form(player) local last_right_click = unifieddyes.player_last_right_clicked[player_name] if last_right_click then - if last_right_click.def and last_right_click.def.palette then - if last_right_click.def.palette == "unifieddyes_palette_colorwallmounted.png" then + if last_right_click.def and last_right_click.def.paramtype2 then + if last_right_click.def.paramtype2 == "colorwallmounted" then nodepalette = "wallmounted" - elseif last_right_click.def.palette == "unifieddyes_palette_extended.png" then + elseif last_right_click.def.paramtype2 == "color" then t[#t+1] = "label[0.5,8.25;(Right-clicked a node that supports all 256 colors, showing them all)]" showall = true - elseif last_right_click.def.palette ~= "unifieddyes_palette_extended.png" then + elseif last_right_click.def.paramtype2 == "colorfacedir" then nodepalette = "split" - elseif not string.find(last_right_click.def.palette, "unifieddyes_palette_") then - t[#t+1] = "label[0.5,8.25;(Right-clicked a node not supported by the Airbrush, showing all colors)]" end - else - t[#t+1] = "label[0.5,8.25;(Right-clicked a non-colorable node, showing all colors)]" end end + if not last_right_click.def.groups or not last_right_click.def.groups.ud_param2_colorable then + t[#t+1] = "label[0.5,8.25;(Right-clicked a node not supported by the Airbrush, showing all colors)]" + end + for v = 0, 6 do local val = unifieddyes.VALS_EXTENDED[v+1] @@ -993,7 +1034,7 @@ function unifieddyes.show_airbrush_form(player) t[#t+1] = "button_exit[11,8;2,1;cancel;Cancel]button_exit[13,8;2,1;accept;Accept]" - if last_right_click and last_right_click.def and last_right_click.def.palette and nodepalette ~= "extended" then + if last_right_click and last_right_click.def and nodepalette ~= "extended" then if showall then t[#t+1] = "button[0.5,8;2,1;show_avail;Show Available]" t[#t+1] = "label[2.5,8.25;(Currently showing all 256 colors)]" |