From 958b235d26f387ede5a1be1bc7c279fb5162d738 Mon Sep 17 00:00:00 2001 From: Christian Wischenbart Date: Wed, 5 Aug 2015 02:03:51 +0200 Subject: [PATCH] Fix ench. table swapping tool causing unknown bugs --- enchanting.lua | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) 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