Ench. table : fix regression causing unknown item after enchanting twice

This commit is contained in:
jp 2015-12-29 01:22:42 +01:00
parent a309f95c36
commit 460b7dbd2f

View File

@ -57,14 +57,15 @@ function enchanting.fields(pos, _, fields, _)
local toolstack = inv:get_stack("tool", 1) local toolstack = inv:get_stack("tool", 1)
local toolstack_name = toolstack:get_name() local toolstack_name = toolstack:get_name()
local mesestack = inv:get_stack("mese", 1) local mesestack = inv:get_stack("mese", 1)
local modname, toolname = toolstack_name:match("([%w_]+):([%w_]+)") local mod, tool = toolstack_name:match("([%w_]+):([%w_]+)")
local toolwear = toolstack:get_wear() local toolwear = toolstack:get_wear()
local mese = mesestack:get_count() local mese = mesestack:get_count()
local ench = dump(fields):match("%w+") local ench = dump(fields):match("%w+")
if ench == "quit" then return end if ench == "quit" then return end
local enchanted_tool = mod..":enchanted_"..tool.."_"..ench
if mese > 0 and fields[ench] then if mese > 0 and fields[ench] and
local enchanted_tool = modname..":enchanted_"..toolname.."_"..ench minetest.registered_tools[enchanted_tool] then
toolstack:replace(enchanted_tool) toolstack:replace(enchanted_tool)
toolstack:add_wear(toolwear) toolstack:add_wear(toolwear)
mesestack:take_item() mesestack:take_item()
@ -91,10 +92,9 @@ end
function enchanting.put(_, listname, _, stack, _) function enchanting.put(_, listname, _, stack, _)
local toolstack = stack:get_name() local toolstack = stack:get_name()
local toolname = toolstack:match("[%w_]+:([%w_]+)") local toolname = toolstack:match("[%w_]+:([%w_]+)")
local count = stack:get_count()
if listname == "mese" and toolstack == "default:mese_crystal" then if listname == "mese" and toolstack == "default:mese_crystal" then
return count return stack:get_count()
elseif listname == "tool" and allowed(toolname) then elseif listname == "tool" and allowed(toolname) then
return 1 return 1
end end