sorcery  Check-in [77b901d950]

Overview
Comment:lathe is a mess but whatever i dont care it works now
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 77b901d9505d7405223a74300aa017b2c6f5d5c31c10ee936ef1e6776a4a7bdc
User & Date: lexi on 2021-07-08 11:25:23
Other Links: manifest | tags
Context
2021-07-08
13:41
commit missing texture check-in: aece454800 user: lexi tags: trunk
11:25
lathe is a mess but whatever i dont care it works now check-in: 77b901d950 user: lexi tags: trunk
01:08
add tool wear to lathe, add page turning sounds for cookbooks check-in: 0dbb4f52c3 user: lexi tags: trunk
Changes

Modified lathe.lua from [5af73c1767] to [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;

})

Modified metal.lua from [816e3182ea] to [43593523a3].

44
45
46
47
48
49
50

51
52
53
54
55
56

57
58
59
60
61
62
63
..
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100














101
102
103
104
105
106
107
108
109
110













111
112
113
114
115
116
117
-- for name, metal in pairs(sorcery.data.metals) do
sorcery.register.metals.foreach('sorcery:generate',{},function(name,metal)
	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

	metal.parts = {
		ingot = ingot;
		block = block;
		screw = screw;
		fragment = fragment;
		powder = powder;

	}
	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;
			value = c.cost * fragments_per_ingot;
		}
................................................................................
	sorcery.data.metallookup[fragment] = {
		id = name; data = metal;
		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;
		};
		_sorcery = {
			material = {
				id = name, data = metal;
				powder = powder;
				grindcost = 2, grindvalue = 1;
				value = 0.5;
			};
		};
	})














	local reglathe = function(ty, sz)
		sorcery.lathe.register {
			input = ty;
			output = {name = screw, count = sz * 2};
			tech = 'cut', cost = 1;
		}
	end
	reglathe(fragment, 1)
	reglathe(ingot, 4)
	reglathe(block, 4 * 9)













	minetest.register_craftitem(powder, {
		description = sorcery.lib.str.capitalize(name) .. ' Powder';
		inventory_image = 'sorcery_' .. name .. '_powder.png';
	})
	if metal.dye then
		minetest.register_craft {
			output = 'dye:' .. metal.dye .. ' 4';







>






>







 







<
<
|
<
<









>
>
>
>
>
>
>
>
>
>
>
>
>
>










>
>
>
>
>
>
>
>
>
>
>
>
>







44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
..
82
83
84
85
86
87
88


89


90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
-- for name, metal in pairs(sorcery.data.metals) do
sorcery.register.metals.foreach('sorcery:generate',{},function(name,metal)
	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;
			value = c.cost * fragments_per_ingot;
		}
................................................................................
	sorcery.data.metallookup[fragment] = {
		id = name; data = metal;
		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; };


		_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;
		}
	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
		minetest.register_craft {
			output = 'dye:' .. metal.dye .. ' 4';

Modified recipes.lua from [a1903de2a1] to [3fef19dac9].

368
369
370
371
372
373
374
375
376

377
378
379


380
381
382
383
384
385
386
...
789
790
791
792
793
794
795
796




797
798





	-- used in constructing devices that are subject to attunement wand
regtech('gravity_manipulator', 'Gravity Manipulator', {metal = 1})
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))



minetest.register_craft {
	output = 'sorcery:trough';
	recipe = {
		{ingot('aluminum'),'',ingot('aluminum')};
		{ingot('aluminum'),'',ingot('aluminum')};
		{ingot('aluminum'),ingot('aluminum'),ingot('aluminum')};
................................................................................
		potion_auto_recipe(id,v,{'farming:mixing_bowl'},'xdecor:bowl')
	end
end

sorcery.lathe.register {
	output = 'basic_materials:steel_bar 2';
	input = 'default:steel_ingot';
	tech = 'cut';




	cost = 3;
}












|
<
>
|
|
|
>
>







 







|
>
>
>
>
|

>
>
>
>
>
368
369
370
371
372
373
374
375

376
377
378
379
380
381
382
383
384
385
386
387
388
...
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
	-- used in constructing devices that are subject to attunement wand
regtech('gravity_manipulator', 'Gravity Manipulator', {metal = 1})
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},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')};
		{ingot('aluminum'),'',ingot('aluminum')};
		{ingot('aluminum'),ingot('aluminum'),ingot('aluminum')};
................................................................................
		potion_auto_recipe(id,v,{'farming:mixing_bowl'},'xdecor:bowl')
	end
end

sorcery.lathe.register {
	output = 'basic_materials:steel_bar 2';
	input = 'default:steel_ingot';
	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;
}