Preserve colour on repair by crafting (#15)

This commit is contained in:
Luke aka SwissalpS 2024-04-13 19:18:52 +02:00 committed by GitHub
parent 2c708abd88
commit 8fc1f596d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -40,6 +40,14 @@ local function get_color_name(name)
return name return name
end end
local function get_color_name_from_color(color)
for name, color_hex in pairs(dye_colors) do
if color == color_hex then
return name
end
end
end
-- This recipe is just a placeholder -- This recipe is just a placeholder
do do
local item = ItemStack("hangglider:hangglider") local item = ItemStack("hangglider:hangglider")
@ -61,9 +69,15 @@ minetest.register_on_craft(function(crafted_item, _, old_craft_grid)
local name = stack:get_name() local name = stack:get_name()
if name == "hangglider:hangglider" then if name == "hangglider:hangglider" then
wear = stack:get_wear() wear = stack:get_wear()
color = stack:get_meta():get("hangglider_color")
color_name = get_color_name_from_color(color)
elseif minetest.get_item_group(name, "dye") ~= 0 then elseif minetest.get_item_group(name, "dye") ~= 0 then
color = get_dye_color(name) color = get_dye_color(name)
color_name = get_color_name(name) color_name = get_color_name(name)
elseif "wool:white" == stack:get_name()
or "default:paper" == stack:get_name()
then
wear = 0
end end
end end
if wear and color and color_name then if wear and color and color_name then