Skip to content

Commit

Permalink
Preserve colour on repair by crafting (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
SwissalpS authored Apr 13, 2024
1 parent 2c708ab commit 8fc1f59
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crafts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ local function get_color_name(name)
return name
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
do
local item = ItemStack("hangglider:hangglider")
Expand All @@ -61,9 +69,15 @@ minetest.register_on_craft(function(crafted_item, _, old_craft_grid)
local name = stack:get_name()
if name == "hangglider:hangglider" then
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
color = get_dye_color(name)
color_name = get_color_name(name)
elseif "wool:white" == stack:get_name()
or "default:paper" == stack:get_name()
then
wear = 0
end
end
if wear and color and color_name then
Expand Down

0 comments on commit 8fc1f59

Please sign in to comment.