Differences From
Artifact [5af73c1767]:
29 29 local R = sorcery.lathe.recipes
30 30 sorcery.lathe.get = function(pos,idx,howmany)
31 31 local inv = minetest.get_meta(pos):get_inventory()
32 32 local tool = inv:get_stack('tool',1)
33 33 local tech = sorcery.lathe.tooltech(tool)
34 34 if not tech then return nil end
35 35 local wkpc = inv:get_stack('workpiece',1)
36 + howmany = howmany or wkpc:get_count()
36 37 local rec = R[wkpc:get_name()][tech][idx]
37 38 local outn = ItemStack(rec.output):get_count()
38 - local q = howmany / outn
39 + local ntimes = math.floor(howmany / (rec.mass or 1))
39 40 return {
40 41 tool = tool, wkpc = wkpc;
41 - cost = rec.cost * q;
42 - qty = q, outn = outn;
42 + cost = rec.cost * ntimes;
43 + ntimes = ntimes;
44 + tqty = math.floor(howmany / outn), outn = outn;
45 + gqty = ntimes * outn;
43 46 tech = tech;
44 47 rec = rec;
45 48 inv = inv;
46 49 }
47 50 end
48 51
49 52 sorcery.lathe.update = function(pos)
................................................................................
61 64
62 65 local tmat = sorcery.itemclass.get(tool:get_name(),'material')
63 66 local wmat = sorcery.itemclass.get(wkpc:get_name(),'material')
64 67 -- obey level restrictions. TODO honor Rend
65 68 if (wmat and wmat.data.level or 0) > (tmat and (tmat.data.maxlevel or tmat.data.level) or 0) then
66 69 return
67 70 end
68 -
71 +
69 72 local tech = sorcery.lathe.tooltech(tool)
70 73 local rec = R[wkpc:get_name()][tech]
71 74 tech = sorcery.lathe.techs[tech]
72 75
73 76 -- fill in the preview slots
74 77 local j = 1
75 - for i=1, inv:get_size('preview') do
76 - local stk
77 - if rec[i] and minetest.registered_items[ItemStack(rec[i].output):get_name()] then
78 - local max = wkpc:get_count()
78 + for i=1, inv:get_size 'preview' do
79 + local stk = ItemStack()
80 + 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
81 + local l = sorcery.lathe.get(pos, i, wkpc:get_count())
82 + local max = l.ntimes --math.floor(wkpc:get_count() / (rec[i].mass or 1))
79 83 if tech.dmg then
80 84 -- TODO count remaining tool uses
81 85 elseif tech.consume then
82 86 max = math.min(max, tool:get_count())
83 87 end
84 88 if max > 0 then
85 89 stk = ItemStack(rec[i].output)
86 90 stk:set_count(stk:get_count() * max)
87 - inv:set_stack('preview',i,stk)
88 91 end
89 92 end
93 + inv:set_stack('preview',i,stk)
90 94 j = j + 1
91 95 end
92 96
93 97 -- make sure remaining slots are clear
94 98 for i = j, inv:get_size('preview') do
95 99 inv:set_stack('preview',i,ItemStack())
96 100 end
................................................................................
182 186 local lfac = 1
183 187 if mat then
184 188 local dur = mat.data.durability or dur
185 189 lfac = (mmat and mmat.data.level or 1) /
186 190 (mat.data.maxlevel or mat.data.level or 1)
187 191 end
188 192 local ch = 65535 / dur
189 - l.tool:add_wear(4 * ch * l.cost * lfac)
193 + l.tool:add_wear(ch * l.cost * lfac)
190 194 end
191 - l.wkpc:take_item(l.qty)
195 + l.wkpc:take_item(l.tqty)
192 196 l.inv:set_stack('tool', 1, l.tool)
193 197 l.inv:set_stack('workpiece', 1, l.wkpc)
198 + if l.rec.leftover then
199 + sorcery.lib.node.insert(ItemStack(l.rec.leftover), 'workpiece', pos, user, l.inv)
200 + end
194 201 minetest.sound_play('sorcery_clank', { pos = pos, gain = 0.9 })
195 202 end
196 203 sorcery.lathe.update(pos)
197 204 end;
198 205
199 206 })
200 207