summaryrefslogtreecommitdiff
path: root/unifieddyes
diff options
context:
space:
mode:
Diffstat (limited to 'unifieddyes')
-rw-r--r--unifieddyes/API.md7
-rw-r--r--unifieddyes/init.lua83
2 files changed, 68 insertions, 22 deletions
diff --git a/unifieddyes/API.md b/unifieddyes/API.md
index bd06164..6f1b9d0 100644
--- a/unifieddyes/API.md
+++ b/unifieddyes/API.md
@@ -117,12 +117,17 @@ This will loop through all of Unified Dyes' color lists, generating one recipe f
`recipe` is the same as in the normal call, except that Unified Dyes will replace all instances of the string "NEUTRAL_NODE" with the item specified in the preceding `neutral_node` field. Every instance of "MAIN_DYE" will be replaced with a portion of dye, as Unified Dyes' recipe helper works through its color lists (i.e. this field will become whatever dye is needed for each recipe).
-`output_prefix` and `output_suffix`, if specified (must use both if at all), will cause the recipe registration to ignore the usual `output` field, and instead set to the output item to `output_prefix` + (hue) + `output_suffix`. Used for mods that use the split 89-color palette. `hue` will thus be one of the 12 hues, or "grey", as defined by the split palettes.
+`output_prefix` and `output_suffix`, if specified (must use both if at all), will cause the recipe registration to set to the output item to `output_prefix` + (hue) + `output_suffix` + `output`. Used for mods that use the split 89-color palette. `hue` will thus be one of the 12 hues, or "grey", as defined by the split palettes. In this situation, you can set `output` to your recipe yield (with a leading space) if needed. For example, if the prefix is "foo:bar", the suffix is "baz", and the output is set to " 3", then the craft helper will generate output item strings of the form "foo:bar_COLOR_baz 3", for each color in the table.
**`unifieddyes.make_colored_itemstack(itemstack, palette, color)`**
Makes a colored itemstack out of the given `itemstack` and `color` (as a dye, e.g. "dye:dark_red_s50"), setting the correct index per the `palette` field, which works as described above for `unifieddyes.getpaletteidx()`. Said itemstack is returned as a string suitable for use as the output field of a craft recipe, equal in size to the itemstack passed into the function (e.g. if you give it "mymod:colored_node 7", it'll return a stack of 7 colored items).
+**`unifieddyes.generate_split_palette_nodes(name, def, drop)`**
+
+Does just what it sounds like - it registers all the nodes that are needed for a given base node (`def`) to be able to use the split palette, each named according to `name`, with the palette hue appended. If a custom drop is needed, it can be passed along (only a string is allowed here, specifying a single item).
+
+
#### Tables
In addition to the above API calls, Unified Dyes provides several useful tables
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)]"