diff --git a/enchanting.lua b/enchanting.lua index ac6e55d..532efb9 100644 --- a/enchanting.lua +++ b/enchanting.lua @@ -16,6 +16,16 @@ local function enchconstruct(pos) inv:set_size("mese", 1) end +local function is_allowed_tool(toolname) + local tdef = minetest.registered_tools[toolname] + if tdef and string.find(toolname, "default:") and not + string.find(toolname, "sword") and not + string.find(toolname, "stone") and not + string.find(toolname, "wood") then + return 1 + else return 0 end +end + local function enchfields(pos, formname, fields, sender) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() @@ -26,7 +36,7 @@ local function enchfields(pos, formname, fields, sender) local enchs = {"durable", "fast"} for _, e in pairs(enchs) do - if string.find(toolname, "default:") and mese > 0 and fields[e] then + if is_allowed_tool(toolname) ~= 0 and mese > 0 and fields[e] then toolstack:replace("xdecor:enchanted_"..string.sub(toolname, 9).."_"..e) mesestack:take_item() inv:set_stack("mese", 1, mesestack) @@ -54,13 +64,7 @@ local function enchput(pos, listname, index, stack, player) else return 0 end end if listname == "tool" then - local tdef = minetest.registered_tools[toolname] - if tdef and string.find(toolname, "default:") and not - string.find(toolname, "sword") and not - string.find(toolname, "stone") and not - string.find(toolname, "wood") then - return 1 - else return 0 end + return is_allowed_tool(toolname) end return count end