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

Compare commits

...

11 Commits

Author SHA1 Message Date
10ab87bf65 prevent crash in setting sky color
if get color from name return nil
2019-05-25 04:14:12 -04:00
f59c8affc1 Merge branch 'master' into 'master'
Fixed yield for crafted dyes.

See merge request VanessaE/unifieddyes!2
2019-02-07 15:19:47 +00:00
667bce80b9 Fixed yield for crafted dyes.
Fix a bug that caused multiple inconsistent recipes to appear
(identical dye resources gave different dye output quantity).

Signed-off-by: Michal Cieslakiewicz <michal.cieslakiewicz@wp.pl>
2019-02-07 10:08:04 +01:00
5039a8ce07 Merge branch 'patch-1' into 'master'
Fix numbers relating to greys

See merge request VanessaE/unifieddyes!1
2018-12-16 00:09:21 +00:00
13a8cbb38f Some of the numbers relating to greys are used inconsistently, making three of the palette colours unreachable. This bug patch fixes the numbers and restores full usability of the palette. 2018-12-15 10:53:35 +00:00
58dd71e561 Add function to get the hex color from a dye name
(oh, and https://www.youtube.com/watch?v=OEVFbrEv83w too)
2018-12-01 17:59:00 -06:00
1fd850d37c change airbrush recipe
to 1 brass ingot, 2 steel ingots, and 1 plastic sheet
2018-11-23 10:38:05 -05:00
334de564fd fix crash
when trying to airbrush unknown nodes or nodes without palettes.
2018-10-19 16:00:05 -04:00
545968517b more strict checking of need to reset param2 on place
fixes wood (coloredwood mod), stone (blox mod), bricks (unified
bricks mod), etc.  being rotated wrong
2018-10-12 07:55:09 -04:00
368205d3b8 Add VALS_SPLIT for craft
Add faint + light.
2018-10-05 05:23:02 +02:00
feed6d5aae add human-readable color names to tooltips and "your selection
in airbrush form, plus minor re-arrangements and size adjustment to fit.
2018-09-23 18:11:07 -04:00

161
init.lua
View File

@ -99,6 +99,14 @@ unifieddyes.VALS = {
"dark_"
}
unifieddyes.VALS_SPLIT = {
"faint_",
"light_",
"",
"medium_",
"dark_"
}
unifieddyes.VALS_EXTENDED = {
"faint_",
"pastel_",
@ -120,7 +128,7 @@ unifieddyes.GREYS = {
unifieddyes.GREYS_EXTENDED = table.copy(unifieddyes.GREYS)
for i = 1, 14 do
if i ~= 0 and i ~= 3 and i ~= 7 and i ~= 11 and i ~= 15 then
if i ~= 0 and i ~= 4 and i ~= 8 and i ~= 11 and i ~= 15 then
table.insert(unifieddyes.GREYS_EXTENDED, "grey_"..i)
end
end
@ -164,20 +172,25 @@ minetest.register_on_placenode(
end
if not string.find(itemstack:to_string(), "palette_index") then
local param2 = 0
local param2
local color = 0
if def.palette == "unifieddyes_palette_extended.png" then
if def.palette == "unifieddyes_palette_extended.png"
and def.paramtype2 == "color" then
param2 = 240
color = 240
elseif def.palette == "unifieddyes_palette_colorwallmounted.png" then
elseif def.palette == "unifieddyes_palette_colorwallmounted.png"
and def.paramtype2 == "colorwallmounted" then
param2 = newnode.param2 % 8
else -- it's a split palette
elseif string.find(def.palette, "unifieddyes_palette_")
and def.paramtype2 == "colorfacedir" then -- it's a split palette
param2 = newnode.param2 % 32
end
minetest.swap_node(pos, {name = newnode.name, param2 = param2})
minetest.get_meta(pos):set_int("palette_index", color)
if param2 then
minetest.swap_node(pos, {name = newnode.name, param2 = param2})
minetest.get_meta(pos):set_int("palette_index", color)
end
end
end
)
@ -282,7 +295,7 @@ end
function unifieddyes.register_color_craft(craft)
local hues_table = unifieddyes.HUES_EXTENDED
local sats_table = unifieddyes.SATS
local vals_table = unifieddyes.VALS
local vals_table = unifieddyes.VALS_SPLIT
local greys_table = unifieddyes.GREYS
if craft.palette == "wallmounted" then
@ -436,7 +449,7 @@ function unifieddyes.getpaletteidx(color, palette_type)
["grey_14"] = 1,
["grey_13"] = 2,
["grey_12"] = 3,
["light_grey"] = 3,
["light_grey"] = 4,
["grey_11"] = 4,
["grey_10"] = 5,
["grey_9"] = 6,
@ -617,6 +630,19 @@ function unifieddyes.getpaletteidx(color, palette_type)
end
end
function unifieddyes.get_color_from_dye_name(name)
if name == "dye:black" then
return "000000"
elseif name == "dye:white" then
return "ffffff"
end
local item = minetest.registered_items[name]
if not item then return end
local inv_image = item.inventory_image
if not inv_image then return end
return string.match(inv_image,"colorize:#(......):200")
end
-- punch-to-recolor using the airbrush
function unifieddyes.on_airbrush(itemstack, player, pointed_thing)
@ -627,8 +653,30 @@ function unifieddyes.on_airbrush(itemstack, player, pointed_thing)
painting_with = unifieddyes.player_current_dye[player_name]
end
if not painting_with then
minetest.chat_send_player(player_name, "*** You need to set a color first.")
minetest.chat_send_player(player_name, "*** Right-click any random node to open the color selector,")
minetest.chat_send_player(player_name, "*** or shift+right-click a colorized node to use its color.")
minetest.chat_send_player(player_name, "*** Be sure to click \"Accept\", or the color you select will be ignored.")
return
end
local pos = minetest.get_pointed_thing_position(pointed_thing)
if not pos then return end
if not pos then
local look_angle = player:get_look_vertical()
if look_angle > -1.55 then
minetest.chat_send_player(player_name, "*** No node selected")
else
local hexcolor = unifieddyes.get_color_from_dye_name(painting_with)
if hexcolor then
local r = tonumber(string.sub(hexcolor,1,2),16)
local g = tonumber(string.sub(hexcolor,3,4),16)
local b = tonumber(string.sub(hexcolor,5,6),16)
player:set_sky({r=r,g=g,b=b,a=255},"plain")
end
end
return
end
local node = minetest.get_node(pos)
local def = minetest.registered_items[node.name]
@ -639,14 +687,6 @@ function unifieddyes.on_airbrush(itemstack, player, pointed_thing)
return
end
if not painting_with then
minetest.chat_send_player(player_name, "*** You need to set a color first.")
minetest.chat_send_player(player_name, "*** Right-click any random node to open the color selector,")
minetest.chat_send_player(player_name, "*** or shift+right-click a colorized node to use its color.")
minetest.chat_send_player(player_name, "*** Be sure to click \"Accept\", or the color you select will be ignored.")
return
end
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
@ -654,7 +694,10 @@ function unifieddyes.on_airbrush(itemstack, player, pointed_thing)
local palette = nil
local fdir = 0
if def.palette == "unifieddyes_palette_extended.png" then
if not def or not def.palette then
minetest.chat_send_player(player_name, "*** That node can't be colored -- it's either undefined or has no palette.")
return
elseif def.palette == "unifieddyes_palette_extended.png" then
palette = "extended"
elseif def.palette == "unifieddyes_palette_colorwallmounted.png" then
palette = "wallmounted"
@ -806,10 +849,17 @@ end
local hps = 0.6 -- horizontal position scale
local vps = 1.3 -- vertical position scale
local vs = 0.3 -- vertical shift/offset
local vs = 0.1 -- vertical shift/offset
local color_button_size = ";0.75,0.75;"
local color_square_size = ";0.69,0.69;"
function unifieddyes.make_readable_color(color)
local s = string.gsub(color, "_", " ")
s = string.gsub(s, "s50", "(low saturation)")
return s
end
function unifieddyes.make_colored_square(hexcolor, colorname, showall, creative, painting_with, nodepalette, hp, v2, selindic, inv, explist)
local dye = "dye:"..colorname
@ -831,26 +881,29 @@ function unifieddyes.make_colored_square(hexcolor, colorname, showall, creative,
end
end
local tooltip = "tooltip["..colorname..";"..
unifieddyes.make_readable_color(colorname)..
"\n(dye:"..colorname..")]"
if dye == painting_with then
overlay = "^unifieddyes_select_overlay.png"
selindic = "unifieddyes_white_square.png"..colorize..overlay..unavail_overlay.."]"..
"tooltip["..colorname..";"..colorname.."]"
selindic = "unifieddyes_white_square.png"..colorize..overlay..unavail_overlay.."]"..tooltip
end
local form
local form
if unavail_overlay == "" then
form = "image_button["..
(hp*hps)..","..(v2*vps+vs)..
color_button_size..
"unifieddyes_white_square.png"..colorize..overlay..unavail_overlay..";"..
colorname..";]"..
"tooltip["..colorname..";"..colorname.."]"
tooltip
else
form = "image["..
(hp*hps)..","..(v2*vps+vs)..
color_square_size..
"unifieddyes_white_square.png"..colorize..overlay..unavail_overlay.."]"..
"tooltip["..colorname.." (unavailable);"..colorname.."]"
tooltip
end
return form, selindic
@ -868,7 +921,7 @@ function unifieddyes.show_airbrush_form(player)
local nodepalette = "extended"
local showall = unifieddyes.player_showall[player_name]
t[1] = "size[15,8.5]label[7,-0.25;Select a color:]"
t[1] = "size[14.5,8.5]label[7,-0.3;Select a color:]"
local selindic = "unifieddyes_select_overlay.png^unifieddyes_question.png]"
local last_right_click = unifieddyes.player_last_right_clicked[player_name]
@ -904,7 +957,7 @@ function unifieddyes.show_airbrush_form(player)
for hi, h in ipairs(unifieddyes.HUES_EXTENDED) do
local hue = h[1]
local hp=hi-0.5
local hp=hi-1
local r = h[2]
local g = h[3]
@ -932,7 +985,7 @@ function unifieddyes.show_airbrush_form(player)
for hi, h in ipairs(unifieddyes.HUES_EXTENDED) do
local hue = h[1]
local hp=hi-0.5
local hp=hi-1
local r = h[2]
local g = h[3]
@ -964,7 +1017,7 @@ function unifieddyes.show_airbrush_form(player)
local v2=5
for y = 0, 15 do
local hp=(15-y)+0.5
local hp=15-y
local hexgrey = string.format("%02x", y*17)..string.format("%02x", y*17)..string.format("%02x", y*17)
local grey = "grey_"..y
@ -983,48 +1036,52 @@ function unifieddyes.show_airbrush_form(player)
end
if not creative then
t[#t+1] = "image[10.3,"
t[#t+1] = (vps*5+vs)
t[#t+1] = "image[10,"
t[#t+1] = (vps*5.55+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] = "unifieddyes_onhand_overlay.png]label[10.7,"
t[#t+1] = (vps*5.51+vs)
t[#t+1] = ";Dyes]"
t[#t+1] = "label[11.0,"
t[#t+1] = (vps*5.18+vs)
t[#t+1] = "label[10.7,"
t[#t+1] = (vps*5.67+vs)
t[#t+1] = ";on hand]"
end
t[#t+1] = "image[11.9,"
t[#t+1] = "image[10,"
t[#t+1] = (vps*5+vs)
t[#t+1] = color_button_size
t[#t+1] = selindic
if painting_with then
t[#t+1] = "label[12.6,"
t[#t+1] = (vps*5.02+vs)
t[#t+1] = "label[10.7,"
t[#t+1] = (vps*4.90+vs)
t[#t+1] = ";Your selection:]"
t[#t+1] = "label[12.6,"
t[#t+1] = (vps*5.18+vs)
t[#t+1] = "label[10.7,"
t[#t+1] = (vps*5.07+vs)
t[#t+1] = ";"
t[#t+1] = unifieddyes.make_readable_color(string.sub(painting_with, 5))
t[#t+1] = "]label[10.7,"
t[#t+1] = (vps*5.24+vs)
t[#t+1] = ";("
t[#t+1] = painting_with
t[#t+1] = "]"
t[#t+1] = ")]"
else
t[#t+1] = "label[12.6,"
t[#t+1] = (vps*5.1+vs)
t[#t+1] = "label[10.7,"
t[#t+1] = (vps*5.07+vs)
t[#t+1] = ";Your selection]"
end
t[#t+1] = "button_exit[11,8;2,1;cancel;Cancel]button_exit[13,8;2,1;accept;Accept]"
t[#t+1] = "button_exit[10.5,8;2,1;cancel;Cancel]button_exit[12.5,8;2,1;accept;Accept]"
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)]"
t[#t+1] = "button[0,8;2,1;show_avail;Show Available]"
t[#t+1] = "label[2,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)]"
t[#t+1] = "button[0,8;2,1;show_all;Show All Colors]"
t[#t+1] = "label[2,8.25;(Currently only showing what the right-clicked node can use)]"
end
end
@ -1072,9 +1129,9 @@ minetest.register_tool("unifieddyes:airbrush", {
minetest.register_craft( {
output = "unifieddyes:airbrush",
recipe = {
{ "default:gold_ingot", "", "bucket:bucket_empty" },
{ "", "default:steel_ingot", "" },
{ "", "", "default:steel_ingot" }
{ "basic_materials:brass_ingot", "", "basic_materials:plastic_sheet" },
{ "", "default:steel_ingot", "" },
{ "", "", "default:steel_ingot" }
},
})
@ -1376,7 +1433,7 @@ for _,i in ipairs(unifieddyes.base_color_crafts) do
minetest.register_craft( {
type = "shapeless",
output = "dye:"..j[1]..color..j[2].." "..yield,
output = "dye:"..j[1]..color..j[2].." "..j[6],
recipe = {
"dye:"..color,
firstdye,