@@ -78,8 +78,22 @@ meta:mark_as_private('sorcery:attune') end; pair = function(reciprocal,src,dest) local d, code = sorcery.attunement.get(src) + local gdef = function(n) + local m = minetest.registered_nodes[minetest.get_node(n).name] + if m and m._sorcery and m._sorcery.attune then + return m._sorcery.attune + end + return nil + end + + local dsrc, dtgt = gdef(src), gdef(tgt) + if not (dsrc and dtgt) then return nil end + + if not (dsrc.source and dtgt.target) then return nil end + if dtgt.accepts ~= dsrc.class then return nil end + if reciprocal or not d then code = math.random(0,65536) sorcery.attunement.set(src, { code = code;