@@ -15,23 +15,51 @@ local id = 'sorcery:coin_' .. metal if gem then desc = (g.desc or gem) .. '-' .. desc coinimg = u.image('sorcery_coin_gem.png'):multiply(u.color(g.tone)):blit(coinimg) - id = id .. '_' .. gem + local gemid = id .. '_' .. gem + minetest.register_craft { + type = 'shapeless'; + recipe = { 'xdecor:hammer', gemid }; + output = g.parts.shard; + replacements = { + {'xdecor:hammer', 'xdecor:hammer'}; + {gemid, id}; + }; + } + id = gemid + else + minetest.register_craft { + type = 'cooking'; + recipe = id .. ' 2'; + output = m.parts.fragment; + } end minetest.register_craftitem(id, { description = u.str.capitalize(desc); inventory_image = coinimg:render(); - groups = { sorcery_coin = 1 }; + groups = { + coin = 1; sorcery_coin = 1; metal = 1; + not_in_creative_inventory = 1; + -- nice try mr lenin + }; + _sorcery = { + material = (gem == nil) and { + metal = true; id = metal, data = m; + grindcost = 2, grindvalue = 1; + } or nil; + }; }) end -for metal in pairs(sorcery.data.metals) do +-- for metal in pairs(sorcery.data.metals) do +sorcery.register.metals.foreach('sorcery:mkcoins',{'sorcery:generate'}, function(metal) register_coin(metal) - for gem in pairs(sorcery.data.gems) do + -- for gem in pairs(sorcery.data.gems) do + sorcery.register.gems.foreach('sorcery:mkcoins_' .. metal, {'sorcery:generate'}, function(gem) register_coin(metal,gem) - end -end + end) +end) local update_press_output = function(meta) local inv = meta:get_inventory() local slot_ingot = inv:get_stack('ingot',1) local slot_gem = inv:get_stack('gem',1) @@ -39,9 +67,9 @@ local coincount if not inv:is_empty('ingot') then local id = slot_ingot:get_name() for name,metal in pairs(sorcery.data.metals) do - if id == metal.ingot then + if id == metal.parts.ingot then metalname = name coincount = slot_ingot:get_count() goto foundmetal end @@ -52,15 +80,11 @@ ::foundmetal:: if not inv:is_empty('gem') then local id = slot_gem:get_name() for name,gem in pairs(sorcery.data.gems) do - if gem.foreign then - if id == gem.foreign then gemname = name - else goto skip end - else - if id == 'sorcery:gem_' .. name then gemname = name - else goto skip end - end + if id == gem.parts.item + then gemname = name + else goto skip end coincount = math.min(coincount, slot_gem:get_count()) do break end ::skip::end end @@ -121,9 +145,9 @@ allow_metadata_inventory_put = function(pos,list,idx,stack,user) local id = stack:get_name() if list == 'ingot' then for name,metal in pairs(sorcery.data.metals) do - if id == metal.ingot then goto okay end + if id == metal.parts.ingot then goto okay end end elseif list == 'gem' then for name,gem in pairs(sorcery.data.gems) do if gem.foreign then @@ -139,11 +163,12 @@ -- mercifully there is never any case where moving between the -- inventories of the node is allowable allow_metadata_inventory_move = function() return 0 end; allow_metadata_inventory_take = function(pos,list,idx,stack,user) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - return inv:get_stack(list,idx):get_count() + local count = stack:get_count() + if list == 'output' then + return (count % coins_per_ingot) == 0 and count or 0 + else return count end end; on_metadata_inventory_put = function(pos,list,idx,stack,user) update_press_output(minetest.get_meta(pos)) end;