sorcery  Diff

Differences From Artifact [2702148c37]:

To Artifact [7e4d0ae5aa]:

  • File coins.lua — part of check-in [3f6a913e4e] at 2020-09-29 12:40:28 on branch trunk — * remove former hacky registration system, replace with consistent and flexible API; rewrite metal/gem generation to take advantage of this new API; tweaks to init system to enable world-local tweaks to lore and sorcery behavior * initial documentation commit * initial steps towards calendar - add default date format, astrolabe; prepare infra for division/melding/transmutation spells, various tweaks and fixes (user: lexi, size: 5636) [annotate] [blame] [check-ins using]

12
13
14
15
16
17
18
19
















20
21
22
23
24
25










26
27
28

29
30

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
...
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
...
136
137
138
139
140
141
142
143
144
145

146
147
148
149
150
151
152
	local g = sorcery.data.gems[gem]
	local desc = (m.desc or metal) .. ' Coin'
	local coinimg = u.image('sorcery_coin.png'):multiply(u.color(m.tone))
	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
















	end

	minetest.register_craftitem(id, {
		description = u.str.capitalize(desc);
		inventory_image = coinimg:render();
		groups = { sorcery_coin = 1 };










	})
end
for metal in pairs(sorcery.data.metals) do

	register_coin(metal)
	for gem in pairs(sorcery.data.gems) do

		register_coin(metal,gem)
	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)
	local metalname, gemname
	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
				metalname = name
				coincount = slot_ingot:get_count()
				goto foundmetal
			end
		end
	end
	inv:set_stack('output',1,ItemStack(nil))
	do return end

	::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
			coincount = math.min(coincount, slot_gem:get_count())
			do break end
		::skip::end
	end
	
	coincount = coincount * coins_per_ingot

................................................................................
					listring[current_player;main]
		]])
	end;
	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
			end
		elseif list == 'gem' then
			for name,gem in pairs(sorcery.data.gems) do
				if gem.foreign then
					if id == gem.foreign then goto okay end
				else
					if id == 'sorcery:gem_' .. name then goto okay end
................................................................................
		do return 0 end
		::okay:: return max_components
	end;
	-- 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()

	end;
	on_metadata_inventory_put = function(pos,list,idx,stack,user)
		update_press_output(minetest.get_meta(pos))
	end;
	on_metadata_inventory_take = function(pos,list,idx,stack,user)
		local meta = minetest.get_meta(pos)
		if list == 'output' then







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>





|
>
>
>
>
>
>
>
>
>
>


|
>

|
>

|
|









|












<
|
<
<
|
|
<







 







|







 







|
|
|
>







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
...
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
...
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
	local g = sorcery.data.gems[gem]
	local desc = (m.desc or metal) .. ' Coin'
	local coinimg = u.image('sorcery_coin.png'):multiply(u.color(m.tone))
	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)
		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 = {
			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
sorcery.register.metals.foreach('sorcery:mkcoins',{'sorcery:generate'}, function(metal)
	register_coin(metal)
	-- 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)
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)
	local metalname, gemname
	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.parts.ingot then
				metalname = name
				coincount = slot_ingot:get_count()
				goto foundmetal
			end
		end
	end
	inv:set_stack('output',1,ItemStack(nil))
	do return end

	::foundmetal:: if not inv:is_empty('gem') then
		local id = slot_gem:get_name()
		for name,gem in pairs(sorcery.data.gems) do

			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
	
	coincount = coincount * coins_per_ingot

................................................................................
					listring[current_player;main]
		]])
	end;
	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.parts.ingot then goto okay end
			end
		elseif list == 'gem' then
			for name,gem in pairs(sorcery.data.gems) do
				if gem.foreign then
					if id == gem.foreign then goto okay end
				else
					if id == 'sorcery:gem_' .. name then goto okay end
................................................................................
		do return 0 end
		::okay:: return max_components
	end;
	-- 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 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;
	on_metadata_inventory_take = function(pos,list,idx,stack,user)
		local meta = minetest.get_meta(pos)
		if list == 'output' then