Index: lathe.lua ================================================================== --- lathe.lua +++ lathe.lua @@ -31,17 +31,20 @@ local inv = minetest.get_meta(pos):get_inventory() local tool = inv:get_stack('tool',1) local tech = sorcery.lathe.tooltech(tool) if not tech then return nil end local wkpc = inv:get_stack('workpiece',1) + howmany = howmany or wkpc:get_count() local rec = R[wkpc:get_name()][tech][idx] local outn = ItemStack(rec.output):get_count() - local q = howmany / outn + local ntimes = math.floor(howmany / (rec.mass or 1)) return { tool = tool, wkpc = wkpc; - cost = rec.cost * q; - qty = q, outn = outn; + cost = rec.cost * ntimes; + ntimes = ntimes; + tqty = math.floor(howmany / outn), outn = outn; + gqty = ntimes * outn; tech = tech; rec = rec; inv = inv; } end @@ -63,32 +66,33 @@ local wmat = sorcery.itemclass.get(wkpc:get_name(),'material') -- obey level restrictions. TODO honor Rend if (wmat and wmat.data.level or 0) > (tmat and (tmat.data.maxlevel or tmat.data.level) or 0) then return end - + local tech = sorcery.lathe.tooltech(tool) local rec = R[wkpc:get_name()][tech] tech = sorcery.lathe.techs[tech] -- fill in the preview slots local j = 1 - for i=1, inv:get_size('preview') do - local stk - if rec[i] and minetest.registered_items[ItemStack(rec[i].output):get_name()] then - local max = wkpc:get_count() + for i=1, inv:get_size 'preview' do + local stk = ItemStack() + if rec[i] and minetest.registered_items[ItemStack(rec[i].output):get_name()] and (rec[i].mass == nil or rec[i].mass <= wkpc:get_count()) then + local l = sorcery.lathe.get(pos, i, wkpc:get_count()) + local max = l.ntimes --math.floor(wkpc:get_count() / (rec[i].mass or 1)) if tech.dmg then -- TODO count remaining tool uses elseif tech.consume then max = math.min(max, tool:get_count()) end if max > 0 then stk = ItemStack(rec[i].output) stk:set_count(stk:get_count() * max) - inv:set_stack('preview',i,stk) end end + inv:set_stack('preview',i,stk) j = j + 1 end -- make sure remaining slots are clear for i = j, inv:get_size('preview') do @@ -184,15 +188,18 @@ local dur = mat.data.durability or dur lfac = (mmat and mmat.data.level or 1) / (mat.data.maxlevel or mat.data.level or 1) end local ch = 65535 / dur - l.tool:add_wear(4 * ch * l.cost * lfac) + l.tool:add_wear(ch * l.cost * lfac) end - l.wkpc:take_item(l.qty) + l.wkpc:take_item(l.tqty) l.inv:set_stack('tool', 1, l.tool) l.inv:set_stack('workpiece', 1, l.wkpc) + if l.rec.leftover then + sorcery.lib.node.insert(ItemStack(l.rec.leftover), 'workpiece', pos, user, l.inv) + end minetest.sound_play('sorcery_clank', { pos = pos, gain = 0.9 }) end sorcery.lathe.update(pos) end; Index: metal.lua ================================================================== --- metal.lua +++ metal.lua @@ -46,16 +46,18 @@ local ingot = metal.ingot or 'sorcery:' .. name .. '_ingot' local block = metal.block or 'sorcery:' .. name .. 'block' local screw = 'sorcery:screw_' .. name local fragment = 'sorcery:fragment_' .. name local powder = 'sorcery:powder_' .. name + local disc = 'sorcery:disc_' .. name metal.parts = { ingot = ingot; block = block; screw = screw; fragment = fragment; powder = powder; + disc = disc; } if not metal.no_tools then for t,c in pairs(tools) do sorcery.matreg.lookup[(metal.items and metal.items[t]) or ('sorcery:' .. t .. '_' .. name)] = { metal = true; id = name; data = metal; @@ -82,24 +84,34 @@ value = 1; } minetest.register_craftitem(screw, { description = sorcery.lib.str.capitalize(name) .. ' Screw'; inventory_image = sorcery.lib.image('sorcery_screw.png'):multiply(sorcery.lib.color(metal.tone)):render(); - groups = { - metal = 1; - sorcery_screw = 1; - sorcery_tech_component = 1; - }; + groups = { metal = 1; sorcery_screw = 1; sorcery_tech_component = 1; }; _sorcery = { material = { id = name, data = metal; powder = powder; grindcost = 2, grindvalue = 1; value = 0.5; }; }; }) + minetest.register_craftitem(disc, { + description = sorcery.lib.str.capitalize(name) .. ' Disc'; + inventory_image = sorcery.lib.image('sorcery_disc.png'):multiply(sorcery.lib.color(metal.tone)):render(); + groups = { metal = 1; sorcery_disc = 1; sorcery_tech_component = 1; }; + _sorcery = { + material = { + id = name, data = metal; + powder = powder; + grindvalue = (3*4) / 2; + value = 4 * (2/3); + }; + }; + }) + local reglathe = function(ty, sz) sorcery.lathe.register { input = ty; output = {name = screw, count = sz * 2}; tech = 'cut', cost = 1; @@ -106,10 +118,23 @@ } end reglathe(fragment, 1) reglathe(ingot, 4) reglathe(block, 4 * 9) + + sorcery.lathe.register { + input = ingot, mass = 2; + output = {name = disc, count = 3}; + tech = 'cut', cost = 5; + } + sorcery.lathe.register { + input = block; + output = {name = disc, count = 8*3}; + leftover = ingot; + tech = 'cut', cost = 5*7; + } + minetest.register_craftitem(powder, { description = sorcery.lib.str.capitalize(name) .. ' Powder'; inventory_image = 'sorcery_' .. name .. '_powder.png'; }) if metal.dye then Index: recipes.lua ================================================================== --- recipes.lua +++ recipes.lua @@ -370,15 +370,17 @@ regtech('valve','Valve', {metal = 1}, { {'','default:bronze_ingot',''}; {'basic_materials:plastic_sheet','basic_materials:steel_bar','basic_materials:plastic_sheet'}; {'','default:bronze_ingot',''}; },3,nil, mprop('bronze',2*4,1,2*4)) -regtech('pipe','Pipe', {metal = 1}, { - {ingot('aluminum'),'',ingot('aluminum')}; - {ingot('aluminum'),'',ingot('aluminum')}; - {ingot('aluminum'),'',ingot('aluminum')}; -}, 6, nil, mprop('aluminum', 4)) +regtech('pipe','Pipe', {metal = 1},nil, nil, nil, mprop('aluminum', 4)) + +sorcery.lathe.register { + input = ingot('aluminum'); + output = 'sorcery:pipe'; + tech = 'cut', cost = 8; +} minetest.register_craft { output = 'sorcery:trough'; recipe = { {ingot('aluminum'),'',ingot('aluminum')}; @@ -791,8 +793,17 @@ end sorcery.lathe.register { output = 'basic_materials:steel_bar 2'; input = 'default:steel_ingot'; - tech = 'cut'; - cost = 3; + tech = 'cut', cost = 3; +} +sorcery.lathe.register { + output = 'basic_materials:steel_bar 18'; + input = 'default:steelblock'; + tech = 'cut', cost = 3*9; +} +sorcery.lathe.register { + output = 'basic_materials:steel_bar'; + input = 'default:steel_fragment', mass = 2; + tech = 'cut', cost = 2; }