1
0
mirror of https://github.com/mt-mods/unifieddyes.git synced 2025-06-28 14:26:21 +02:00

Compare commits

..

15 Commits

Author SHA1 Message Date
ad12387432 use "split" for split-89 palette instead of true. 2018-09-08 12:09:25 -04:00
7b18314235 drop support for the old 89 color palette - obsolete
(the full version)
2018-09-08 11:49:20 -04:00
73a062f026 don't register pink recipe twice for wallmounted 2018-09-08 11:30:14 -04:00
0413f23df1 fix incorrect handling of "azure" re: wallmounted palette
(it doesn't exist there :P  replaced with light blue)
also fixed missing craft helper recipe for same
and fixed missing light_red in color<->palette table.
2018-09-08 11:21:00 -04:00
8fbd9cd23b condense legend a bit
move selected dye label over next to/under "Your selection"
2018-09-08 11:08:37 -04:00
997d703b94 eliminate most egregious string concats in color select form
build it into a table and return table.concat()
instead of using foo = foo..bar or foo = bar..baz..meh  everywhere
2018-09-08 10:53:25 -04:00
95f009a282 show in color selector when a dye is on-hand in survival, but unavailable
(right-clicked node can't use it)
2018-09-08 10:24:08 -04:00
fb2c14b4a8 rename "available" overlay to "onhand" 2018-09-08 10:15:51 -04:00
42093582df show "on hand" indicators in "avail only" screen 2018-09-08 10:13:31 -04:00
3cbb25d92a pass inv to colored squared function 2018-09-08 10:09:42 -04:00
0589d8f02e dim-out the user's color choice in the color selector
and reject it on clicking "Accept",
if they went to "Show All" to select a color,
but then went back to "Show Avail" before clicking Accept.

(i.e. only accept what's shown as available to click on)
2018-09-08 10:05:13 -04:00
fc199cced4 moved the formspec code for the colored squares to its own function 2018-09-08 09:47:31 -04:00
da9ab7215c make airbrush show only the colors the right-clicked node can use
(with button to toggle between that mode and show-all)
2018-09-08 09:09:13 -04:00
19febc877d fix typo 2018-08-28 22:50:05 -04:00
c3036aba00 handle special case of split palette with full colors in node name
also check for ud_param2_colorable before proceeding to airbrush
also handle new -> old color names in split palette switching
2018-08-28 22:44:02 -04:00
6 changed files with 260 additions and 201 deletions

4
API.md
View File

@ -28,7 +28,9 @@ minetest.register_node("mymod:colored_node", {
- "unifieddyes_palette_colorwallmounted.png"
- or one of the "split" hues palettes (see below).
`groups`: If your node can be colored by punching it with dye, its groups entry must contain the key ud_param2_colorable = 1, among whatever else you'd normally put there. If the node is software-controlled, as might be the case for some mesecons-digilines aware node, then this group key should be omitted.
`groups`: If your node can be colored by using the airbrush, its groups entry must contain the key ud_param2_colorable = 1, among whatever else you'd normally put there. If the node is software-controlled, as might be the case for some mesecons-digilines aware node, then this group key should be omitted.
If your node if of the kind where you need the split palette, but you need to put the *full color name* into the node name, as opposed to just the hue, then add the keys `ud_color_start` and `ud_color_end` and set them to the positions of the first and last characters of the color name (where 1 is the first character of the mod name at the start of the node name, i.e. "mymod:foo_bar_orange_baz" would have the start set to 15 and the end at 20).
`on_construct`: see below.

447
init.lua
View File

@ -155,6 +155,11 @@ local default_dyes = {
unifieddyes.player_current_dye = {}
unifieddyes.player_selected_dye = {}
unifieddyes.player_last_right_clicked = {}
unifieddyes.palette_has_color = {}
unifieddyes.player_showall = {}
-- unifieddyes.player_last_right_clicked[placer:get_player_name()] = {pos = pos, node = node, def = def}
-- if a node with a palette is placed in the world,
-- but the itemstack used to place it has no palette_index (color byte),
@ -179,7 +184,7 @@ minetest.register_on_placenode(
color = 240
elseif def.palette == "unifieddyes_palette_colorwallmounted.png" then
param2 = newnode.param2 % 8
elseif def.palette ~= "unifieddyes_palette.png" then -- it's a split palette
else -- it's a split palette
param2 = newnode.param2 % 32
end
@ -207,14 +212,6 @@ function unifieddyes.make_colored_itemstack(item, palette, color)
return stack:to_string(),paletteidx
end
-- if your node was once 89-color and uses an LBM to convert to the 256-color palette,
-- call this in that node def's on_construct:
function unifieddyes.on_construct(pos)
local meta = minetest.get_meta(pos)
meta:set_string("palette", "ext")
end
-- these helper functions register all of the recipes needed to create colored
-- nodes with any of the dyes supported by that node's palette.
@ -238,7 +235,7 @@ local function register_c(craft, hue, sat, val)
local output = craft.output
if craft.output_prefix then
if craft.palette ~= true then
if craft.palette ~= "split" then
output = craft.output_prefix..color..craft.output_suffix
else
if hue == "white" or hue == "black" or string.find(hue, "grey") then
@ -271,7 +268,7 @@ function unifieddyes.register_color_craft(craft)
if craft.palette == "wallmounted" then
register_c(craft, "green", "", "light_")
register_c(craft, "azure", "", "")
register_c(craft, "blue", "", "light_")
hues_table = unifieddyes.HUES_WALLMOUNTED
sats_table = {""}
vals_table = unifieddyes.VALS
@ -394,8 +391,7 @@ end
-- in the function below, color is just a color string, while
-- palette_type can be:
--
-- false/nil = standard 89 color palette
-- true = 89 color palette split into pieces for colorfacedir
-- "split" = 89 color palette split into pieces for colorfacedir
-- "wallmounted" = 32-color abridged palette
-- "extended" = 256 color palette
@ -546,7 +542,7 @@ function unifieddyes.getpaletteidx(color, palette_type)
if grayscale_wallmounted[color] then
return (grayscale_wallmounted[color] * 8), 0
end
elseif palette_type == true then
elseif palette_type == "split" then
if grayscale[color] then
return (grayscale[color] * 32), 0
end
@ -554,10 +550,6 @@ function unifieddyes.getpaletteidx(color, palette_type)
if grayscale_extended[color] then
return grayscale_extended[color]+240, 0
end
else
if grayscale[color] then
return grayscale[color], 0
end
end
local shade = "" -- assume full
@ -589,7 +581,7 @@ function unifieddyes.getpaletteidx(color, palette_type)
if color == "green" and shade == "light" then return 48,3
elseif color == "brown" then return 17,1
elseif color == "pink" then return 56,7
elseif color == "azure" then return 40,5
elseif color == "blue" and shade == "light" then return 40,5
elseif hues_wallmounted[color] and shades_wallmounted[shade] then
return (shades_wallmounted[shade] * 64 + hues_wallmounted[color] * 8), hues_wallmounted[color]
end
@ -601,7 +593,7 @@ function unifieddyes.getpaletteidx(color, palette_type)
color = "red"
shade = "light"
end
if palette_type == true then -- it's colorfacedir, so "split" 89-color palette
if palette_type == "split" then -- it's colorfacedir
-- If using this palette, translate new color names back to old.
@ -620,17 +612,6 @@ function unifieddyes.getpaletteidx(color, palette_type)
if hues_extended[color] and shades_extended[shade] then
return (hues_extended[color] + shades_extended[shade]*24), hues_extended[color]
end
else -- it's the regular 89-color palette, do the same translation if needed
if color == "spring" then
color = "aqua"
elseif color == "azure" then
color = "skyblue"
elseif color == "rose" then
color = "redviolet"
end
if hues[color] and shades[shade] then
return (hues[color] * 8 + shades[shade]), hues[color]
end
end
end
end
@ -665,7 +646,7 @@ function unifieddyes.on_airbrush(itemstack, player, pointed_thing)
return
end
if not def.palette then
if not def.palette or not (def.groups and def.groups.ud_param2_colorable > 0) then
minetest.chat_send_player(player_name, "*** That node can't be colored.")
return
end
@ -677,8 +658,8 @@ function unifieddyes.on_airbrush(itemstack, player, pointed_thing)
elseif def.palette == "unifieddyes_palette_colorwallmounted.png" then
palette = "wallmounted"
fdir = node.param2 % 8
elseif def.palette ~= "unifieddyes_palette.png" then
palette = true
else
palette = "split"
fdir = node.param2 % 32
end
@ -699,29 +680,41 @@ function unifieddyes.on_airbrush(itemstack, player, pointed_thing)
end
local oldidx = node.param2 - fdir
local name = def.airbrush_replacement_node or node.name
if palette == true then
local s = string.sub(def.palette, 21)
local oldcolor = string.sub(s, 1, string.find(s, "s.png")-1)
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"
local newcolor = "razzberry" -- intentionally misspelled ;-)
local a,b
local newcolor = "grey"
if def.ud_color_start and def.ud_color_end then
oldcolor = string.sub(node.name, def.ud_color_start, def.ud_color_end)
newcolor = string.sub(painting_with, 5)
else
if hue ~= 0 then
newcolor = unifieddyes.HUES[hue]
else
newcolor = "grey"
end
local a,b = string.gsub(nodename2, oldcolor, newcolor)
name = modname..":"..a
local s = string.sub(def.palette, 21)
oldcolor = string.sub(s, 1, string.find(s, "s.png")-1)
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
end
elseif idx == oldidx then
return
end
minetest.swap_node(pos, {name = name, param2 = fdir + idx})
if not creative or not creative.is_enabled_for(player_name) then
inv:remove_item("main", painting_with)
@ -764,28 +757,6 @@ function unifieddyes.color_to_name(param2, def)
return unifieddyes.VALS_EXTENDED[v]..unifieddyes.HUES_EXTENDED[h+1][1]..unifieddyes.SATS[s]
end
elseif def.palette == "unifieddyes_palette.png" then
local color = param2
local h = math.floor(color/8)
local s = 1
local val = ""
if color == 1 or color == h or color > 103 or color == 6 or color == 7 then return "white"
elseif color == 2 then return "light_grey"
elseif color == 3 then return "grey"
elseif color == 4 then return "dark_grey"
elseif color == 5 then return "black"
end
local c = color - h*8
if c == 2 then s = 2
elseif c == 3 then val = "light_"
elseif c == 4 then val = "medium_"
elseif c == 5 then val = "medium_" s = 2
elseif c == 6 then val = "dark_"
else val = "dark_" s = 2
end
return val..unifieddyes.HUES[h+1]..unifieddyes.SATS[s]
elseif def.palette == "unifieddyes_palette_colorwallmounted.png" then
local color = math.floor(param2 / 8)
if color == 0 then return "white"
@ -826,20 +797,79 @@ function unifieddyes.color_to_name(param2, def)
end
end
local hps = 0.6 -- horizontal position scale
local vps = 1.3 -- vertical position scale
local vs = 0.3 -- vertical shift/offset
local color_button_size = ";0.75,0.75;"
function unifieddyes.make_colored_square(hexcolor, colorname, showall, creative, painting_with, nodepalette, hp, v2, selindic, inv)
local dye = "dye:"..colorname
local overlay = ""
local colorize = minetest.formspec_escape("^[colorize:#"..hexcolor..":255")
if not creative and inv:contains_item("main", dye) then
overlay = "^unifieddyes_onhand_overlay.png"
end
local unavail_overlay = ""
if not showall and not unifieddyes.palette_has_color[nodepalette.."_"..colorname] then
if overlay == "" then
unavail_overlay = "^unifieddyes_unavailable_overlay.png"
else
unavail_overlay = "^unifieddyes_onhand_unavailable_overlay.png"
end
end
if dye == painting_with then
overlay = "^unifieddyes_select_overlay.png"
selindic = "unifieddyes_white_square.png"..colorize..overlay..unavail_overlay.."]"..
"tooltip["..colorname..";"..colorname.."]"
end
local form = "image_button["..
(hp*hps)..","..(v2*vps+vs)..
color_button_size..
"unifieddyes_white_square.png"..colorize..overlay..unavail_overlay..";"..
colorname..";]"..
"tooltip["..colorname..";"..colorname.."]"
return form, selindic
end
function unifieddyes.show_airbrush_form(player)
if not player then return end
local t = {}
local player_name = player:get_player_name()
local painting_with = unifieddyes.player_selected_dye[player_name] or unifieddyes.player_current_dye[player_name]
local creative = creative and creative.is_enabled_for(player_name)
local inv = player:get_inventory()
local nodepalette = "extended"
local showall = unifieddyes.player_showall[player_name]
local base_form = "size[15,8.5]label[7,-0.25;Select a color:]"
t[1] = "size[15,8.5]label[7,-0.25;Select a color:]"
local selindic = "unifieddyes_select_overlay.png^unifieddyes_question.png]"
local size="0.75,0.75;"
local hps=0.6
local vps=1.3
local vs=0.3
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
nodepalette = "wallmounted"
elseif last_right_click.def.palette == "unifieddyes_palette_extended.png" 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
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
for v = 0, 6 do
local val = unifieddyes.VALS_EXTENDED[v+1]
@ -865,29 +895,10 @@ function unifieddyes.show_airbrush_form(player)
local g2 = math.max(math.min(g + (4-v)*factor, 255), 0)
local b2 = math.max(math.min(b + (4-v)*factor, 255), 0)
local color = string.format("%02x", r2)..string.format("%02x", g2)..string.format("%02x", b2)
local dye = "dye:"..val..hue..sat
local overlay = ""
local colorize = minetest.formspec_escape("^[colorize:#"..color..":255")
if not creative and inv:contains_item("main", dye) then
overlay = "^unifieddyes_available_overlay.png"
end
if dye == painting_with then
overlay = "^unifieddyes_select_overlay.png"
selindic = "unifieddyes_white_square.png"..colorize..overlay.."]"..
"tooltip["..val..hue..sat..";"..val..hue..sat.."]"
end
base_form = base_form.."image_button["..
(hp*hps)..","..(v2*vps+vs)..";"..
size..
"unifieddyes_white_square.png"..colorize..overlay..";"..
val..hue..sat..";]"..
"tooltip["..val..hue..sat..";"..val..hue..sat.."]"
local hexcolor = string.format("%02x", r2)..string.format("%02x", g2)..string.format("%02x", b2)
local f
f, selindic = unifieddyes.make_colored_square(hexcolor, val..hue..sat, showall, creative, painting_with, nodepalette, hp, v2, selindic, inv)
t[#t+1] = f
end
if v > 3 then
@ -917,28 +928,10 @@ function unifieddyes.show_airbrush_form(player)
local g3 = math.floor(p+(g2-p)*0.5)
local b3 = math.floor(p+(b2-p)*0.5)
local color = string.format("%02x", r3)..string.format("%02x", g3)..string.format("%02x", b3)
local dye = "dye:"..val..hue..sat
local overlay = ""
local colorize = minetest.formspec_escape("^[colorize:#"..color..":255")
if not creative and inv:contains_item("main", dye) then
overlay = "^unifieddyes_available_overlay.png"
end
if dye == painting_with then
overlay = "^unifieddyes_select_overlay.png"
selindic = "unifieddyes_white_square.png"..colorize..overlay.."]"..
"tooltip["..val..hue..sat..";"..val..hue..sat.."]"
end
base_form = base_form.."image_button["..
(hp*hps)..","..(v2*vps+vs)..";"..
size..
"unifieddyes_white_square.png"..colorize..overlay..";"..
val..hue..sat..";]"..
"tooltip["..val..hue..sat..";"..val..hue..sat.."]"
local hexcolor = string.format("%02x", r3)..string.format("%02x", g3)..string.format("%02x", b3)
local f
f, selindic = unifieddyes.make_colored_square(hexcolor, val..hue..sat, showall, creative, painting_with, nodepalette, hp, v2, selindic, inv)
t[#t+1] = f
end
end
end
@ -948,61 +941,69 @@ function unifieddyes.show_airbrush_form(player)
local hp=(15-y)+0.5
local grey = string.format("%02x", y*17)..string.format("%02x", y*17)..string.format("%02x", y*17)
local grey2 = "grey_"..y
local hexgrey = string.format("%02x", y*17)..string.format("%02x", y*17)..string.format("%02x", y*17)
local grey = "grey_"..y
if y == 0 then grey2 = "black"
elseif y == 4 then grey2 = "dark_grey"
elseif y == 8 then grey2 = "grey"
elseif y == 11 then grey2 = "light_grey"
elseif y == 15 then grey2 = "white"
if y == 0 then grey = "black"
elseif y == 4 then grey = "dark_grey"
elseif y == 8 then grey = "grey"
elseif y == 11 then grey = "light_grey"
elseif y == 15 then grey = "white"
end
local dye = "dye:"..grey2
local overlay = ""
local colorize = minetest.formspec_escape("^[colorize:#"..grey..":255")
if not creative and inv:contains_item("main", dye) then
overlay = "^unifieddyes_available_overlay.png"
end
if dye == painting_with then
overlay = "^unifieddyes_select_overlay.png"
slindic = "unifieddyes_white_square.png"..colorize..overlay.."]"..
"tooltip["..grey2..";"..grey2.."]"
end
base_form = base_form.."image_button["..
(hp*hps)..","..(v2*vps+vs)..";"..
size..
"unifieddyes_white_square.png"..colorize..overlay..";"..
grey2..";]tooltip["..grey2..";"..grey2.."]"
local f
f, selindic = unifieddyes.make_colored_square(hexgrey, grey, showall, creative, painting_with, nodepalette, hp, v2, selindic, inv)
t[#t+1] = f
end
if not creative then
base_form = base_form..
"image[10.3,"..(vps*5+vs)..";"..size..
"unifieddyes_available_overlay.png]"..
"label[11.0,"..(vps*5.1+vs)..";Dyes on hand]"
end
base_form = base_form..
"image[12.5,"..(vps*5+vs)..";"..size..
selindic..
"label[13.2,"..(vps*5.1+vs)..";Your selection]"
t[#t+1] = "image[10.3,"
t[#t+1] = (vps*5+vs)
t[#t+1] = color_button_size
t[#t+1] = "unifieddyes_onhand_overlay.png]label[11.0,"
t[#t+1] = (vps*5.02+vs)
t[#t+1] = ";Dyes]"
t[#t+1] = "label[11.0,"
t[#t+1] = (vps*5.18+vs)
t[#t+1] = ";on hand]"
base_form = base_form..
"button_exit[11,8;2,1;cancel;Cancel]"..
"button_exit[13,8;2,1;accept;Accept]"
end
t[#t+1] = "image[11.9,"
t[#t+1] = (vps*5+vs)
t[#t+1] = color_button_size
t[#t+1] = selindic
if painting_with then
base_form = base_form..
"label[1,"..(7.5+vs)..";Selected dye: "..
painting_with.."]"
t[#t+1] = "label[12.6,"
t[#t+1] = (vps*5.02+vs)
t[#t+1] = ";Your selection:]"
t[#t+1] = "label[12.6,"
t[#t+1] = (vps*5.18+vs)
t[#t+1] = ";"
t[#t+1] = painting_with
t[#t+1] = "]"
else
t[#t+1] = "label[12.6,"
t[#t+1] = (vps*5.1+vs)
t[#t+1] = ";Your selection]"
end
minetest.show_formspec(player_name, "unifieddyes:dye_select_form", base_form)
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 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)]"
else
t[#t+1] = "button[0.5,8;2,1;show_all;Show All Colors]"
t[#t+1] = "label[2.5,8.25;(Currently only showing what the right-clicked node can use)]"
end
end
minetest.show_formspec(player_name, "unifieddyes:dye_select_form", table.concat(t))
end
minetest.register_tool("unifieddyes:airbrush", {
@ -1016,15 +1017,21 @@ minetest.register_tool("unifieddyes:airbrush", {
on_use = unifieddyes.on_airbrush,
on_place = function(itemstack, placer, pointed_thing)
local keys = placer:get_player_control()
local player_name = placer:get_player_name()
local pos = minetest.get_pointed_thing_position(pointed_thing)
local node
local def
if pos then node = minetest.get_node(pos) end
if node then def = minetest.registered_items[node.name] end
unifieddyes.player_last_right_clicked[player_name] = {pos = pos, node = node, def = def}
if not keys.sneak then
unifieddyes.show_airbrush_form(placer)
elseif keys.sneak then
local player_name = placer:get_player_name()
local pos = minetest.get_pointed_thing_position(pointed_thing)
if not pos then return end
local node = minetest.get_node(pos)
local def = minetest.registered_items[node.name]
if not def then return end
if not pos or not def then return end
local newcolor = unifieddyes.color_to_name(node.param2, def)
if not newcolor then
@ -1047,23 +1054,58 @@ minetest.register_craft( {
})
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname == "unifieddyes:dye_select_form" then
local player_name = player:get_player_name()
if fields.quit then
if not fields.accept then
unifieddyes.player_selected_dye[player_name] = nil
local nodepalette = "extended"
local showall = unifieddyes.player_showall[player_name]
local last_right_click = unifieddyes.player_last_right_clicked[player_name]
if last_right_click and last_right_click.def then
if last_right_click.def.palette then
if last_right_click.def.palette == "unifieddyes_palette_colorwallmounted.png" then
nodepalette = "wallmounted"
elseif last_right_click.def.palette ~= "unifieddyes_palette_extended.png" then
nodepalette = "split"
end
end
end
if fields.show_all then
unifieddyes.player_showall[player_name] = true
unifieddyes.show_airbrush_form(player)
return
else
elseif fields.show_avail then
unifieddyes.player_showall[player_name] = false
unifieddyes.show_airbrush_form(player)
return
elseif fields.quit then
if fields.accept then
local dye = unifieddyes.player_selected_dye[player_name]
if not dye then
minetest.chat_send_player(player_name, "*** Clicked \"Accept\", but no color was selected!")
return
elseif not showall
and not unifieddyes.palette_has_color[nodepalette.."_"..string.sub(dye, 5)] then
minetest.chat_send_player(player_name, "*** Clicked \"Accept\", but the selected color can't be used on the")
minetest.chat_send_player(player_name, "*** node that was right-clicked (and \"Show All\" wasn't in effect).")
if unifieddyes.player_current_dye[player_name] then
minetest.chat_send_player(player_name, "*** Ignoring it and sticking with "..string.sub(unifieddyes.player_current_dye[player_name], 5)..".")
else
minetest.chat_send_player(player_name, "*** Ignoring it.")
end
return
else
unifieddyes.player_current_dye[player_name] = dye
unifieddyes.player_selected_dye[player_name] = nil
minetest.chat_send_player(player_name, "*** Selected "..string.sub(dye, 5).." for the airbrush.")
return
end
else -- assume "Cancel" or Esc.
unifieddyes.player_selected_dye[player_name] = nil
return
end
else
local s1 = string.sub(minetest.serialize(fields), 11)
local s3 = string.sub(s1,1, string.find(s1, '"')-1)
@ -1071,7 +1113,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local inv = player:get_inventory()
local creative = creative and creative.is_enabled_for(player_name)
local dye = "dye:"..s3
if minetest.registered_items[dye] and (creative or inv:contains_item("main", dye)) then
if (showall or unifieddyes.palette_has_color[nodepalette.."_"..s3]) and
(minetest.registered_items[dye] and (creative or inv:contains_item("main", dye))) then
unifieddyes.player_selected_dye[player_name] = dye
unifieddyes.show_airbrush_form(player)
end
@ -1079,30 +1123,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
end)
-- build a table to convert from classic/89-color palette to extended palette
-- the first five entries are for the old greyscale - white, light, grey, dark, black
unifieddyes.convert_classic_palette = {
240,
244,
247,
251,
253
}
for hue = 0, 11 do
-- light
local paletteidx = unifieddyes.getpaletteidx("dye:light_"..unifieddyes.HUES[hue+1], false)
unifieddyes.convert_classic_palette[paletteidx] = hue*2 + 48
for sat = 0, 1 do
for val = 0, 2 do
-- all other shades
local paletteidx = unifieddyes.getpaletteidx("dye:"..unifieddyes.VALS[val+1]..unifieddyes.HUES[hue+1]..unifieddyes.SATS[sat+1], false)
unifieddyes.convert_classic_palette[paletteidx] = hue*2 + sat*24 + (val*48+96)
end
end
end
-- Generate all dyes that are not part of the default minetest_game dyes mod
for _, h in ipairs(unifieddyes.HUES_EXTENDED) do
@ -1217,6 +1237,43 @@ minetest.register_craftitem(":dye:light_grey", {
groups = { dye=1, not_in_creative_inventory=1 },
})
-- build a table of color <-> palette associations to reduce the need for
-- realtime lookups with getpaletteidx()
for _, palette in ipairs({"extended", "split", "wallmounted"}) do
local palette2 = palette
for i in ipairs(unifieddyes.SATS) do
local sat = (palette == "wallmounted") and "" or unifieddyes.SATS[i]
for _, hue in ipairs(unifieddyes.HUES_EXTENDED) do
for _, val in ipairs(unifieddyes.VALS_EXTENDED) do
local color = val..hue[1]..sat
if unifieddyes.getpaletteidx("dye:"..color, palette2) then
unifieddyes.palette_has_color[palette.."_"..color] = true
end
end
end
end
for y = 0, 15 do
local grey = "grey_"..y
if y == 0 then grey = "black"
elseif y == 4 then grey = "dark_grey"
elseif y == 8 then grey = "grey"
elseif y == 11 then grey = "light_grey"
elseif y == 15 then grey = "white"
end
if unifieddyes.getpaletteidx("dye:"..grey, palette2) then
unifieddyes.palette_has_color[palette.."_"..grey] = true
end
end
end
unifieddyes.palette_has_color["wallmounted_light_red"] = true
-- crafting!
unifieddyes.base_color_crafts = {
{ "red", "flowers:rose", nil, nil, nil, nil, 4 },
{ "vermilion", "dye:red", "dye:orange", nil, nil, nil, 3 },

View File

Before

Width:  |  Height:  |  Size: 140 B

After

Width:  |  Height:  |  Size: 140 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 207 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 B