sorcery  Diff

Differences From Artifact [5af73c1767]:

To Artifact [1310436767]:


29
30
31
32
33
34
35

36
37
38

39
40
41

42

43
44
45
46
47
48
49
..
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

79
80
81
82
83
84
85
86
87
88
89

90
91
92
93
94
95
96
...
182
183
184
185
186
187
188
189
190
191
192
193



194
195
196
197
198
199
200
local R = sorcery.lathe.recipes
sorcery.lathe.get = function(pos,idx,howmany)
	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)

	local rec = R[wkpc:get_name()][tech][idx]
	local outn = ItemStack(rec.output):get_count()
	local q = howmany / outn

	return {
		tool = tool, wkpc = wkpc;
		cost = rec.cost * q;

		qty = q, outn = outn;

		tech = tech;
		rec = rec;
		inv = inv;
	}
end

sorcery.lathe.update = function(pos)
................................................................................

	local tmat = sorcery.itemclass.get(tool:get_name(),'material')
	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()

			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

		j = j + 1
	end

	-- make sure remaining slots are clear
	for i = j, inv:get_size('preview') do
		inv:set_stack('preview',i,ItemStack())
	end
................................................................................
				local lfac = 1
				if mat then
					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)
			end
			l.wkpc:take_item(l.qty)
			l.inv:set_stack('tool', 1, l.tool)
			l.inv:set_stack('workpiece', 1, l.wkpc)



			minetest.sound_play('sorcery_clank', { pos = pos, gain = 0.9 })
		end
		sorcery.lathe.update(pos)
	end;

})








>


<
>


|
>
|
>







 







|






|
|
|
|
>








<


>







 







|

|


>
>
>







29
30
31
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46
47
48
49
50
51
52
..
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

91
92
93
94
95
96
97
98
99
100
...
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
local R = sorcery.lathe.recipes
sorcery.lathe.get = function(pos,idx,howmany)
	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 ntimes = math.floor(howmany / (rec.mass or 1))
	return {
		tool = tool, wkpc = wkpc;
		cost = rec.cost * ntimes;
		ntimes = ntimes;
		tqty = math.floor(howmany / outn), outn = outn;
		gqty = ntimes * outn;
		tech = tech;
		rec = rec;
		inv = inv;
	}
end

sorcery.lathe.update = function(pos)
................................................................................

	local tmat = sorcery.itemclass.get(tool:get_name(),'material')
	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 = 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)

			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
		inv:set_stack('preview',i,ItemStack())
	end
................................................................................
				local lfac = 1
				if mat then
					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(ch * l.cost * lfac)
			end
			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;

})