@@ -58,19 +58,26 @@ local img_sparkle = img('sorcery_amulet_sparkle.png') local useamulet = function(stack,user,target) local sp = sorcery.amulet.getspell(stack) if not sp or not sp.cast then return nil end - local stats = sorcery.amulet.stats(stack) + + local usedamulet if stack:get_count() == 1 then + usedamulet = stack + else + usedamulet = ItemStack(stack) + usedamulet:set_count(1) + end local probe = sorcery.spell.probe(user:get_pos()) -- amulets don't work in antimagic fields, though some may want to -- implement this logic themselves (for instance to check a range) if (probe.disjunction and not sp.ignore_disjunction) then return nil end + local stats = sorcery.amulet.stats(usedamulet) local ctx = { caster = user; target = target; stats = stats; - wield = stack; + wield = usedamulet; amulet = stack:get_definition()._sorcery.amulet; meta = stack:get_meta(); -- avoid spell boilerplate color = sorcery.lib.color(sp.tone); today = minetest.get_day_count(); @@ -96,15 +103,25 @@ end if ctx.sparkle then sorcery.vfx.cast_sparkle(user, ctx.color, stats.power,0.5) end + local infinirune = minetest.check_player_privs(user, 'sorcery:infinirune') if res == nil then - if not minetest.check_player_privs(user, 'sorcery:infinirune') then - sorcery.amulet.setrune(stack) - end + if not infinirune then sorcery.amulet.setrune(usedamulet) end end - return ctx.wield + if stack:get_count() == 1 then + return ctx.wield + else + if not infinirune then + stack:take_item(1) + local leftover = user:get_inventory():add_item('main',usedamulet) + if leftover and leftover:get_count() > 0 then + minetest.add_item(user:get_pos(), leftover) + end + end + return stack + end end; minetest.register_craftitem(amuletname, { description = sorcery.lib.str.capitalize(name) .. ' amulet'; inventory_image = img_sparkle:blit(img_stone):render();