Differences From
Artifact [2702148c37]:
- 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 12 local g = sorcery.data.gems[gem]
13 13 local desc = (m.desc or metal) .. ' Coin'
14 14 local coinimg = u.image('sorcery_coin.png'):multiply(u.color(m.tone))
15 15 local id = 'sorcery:coin_' .. metal
16 16 if gem then
17 17 desc = (g.desc or gem) .. '-' .. desc
18 18 coinimg = u.image('sorcery_coin_gem.png'):multiply(u.color(g.tone)):blit(coinimg)
19 - id = id .. '_' .. gem
19 + local gemid = id .. '_' .. gem
20 + minetest.register_craft {
21 + type = 'shapeless';
22 + recipe = { 'xdecor:hammer', gemid };
23 + output = g.parts.shard;
24 + replacements = {
25 + {'xdecor:hammer', 'xdecor:hammer'};
26 + {gemid, id};
27 + };
28 + }
29 + id = gemid
30 + else
31 + minetest.register_craft {
32 + type = 'cooking';
33 + recipe = id .. ' 2';
34 + output = m.parts.fragment;
35 + }
20 36 end
21 37
22 38 minetest.register_craftitem(id, {
23 39 description = u.str.capitalize(desc);
24 40 inventory_image = coinimg:render();
25 - groups = { sorcery_coin = 1 };
41 + groups = {
42 + coin = 1; sorcery_coin = 1; metal = 1;
43 + not_in_creative_inventory = 1;
44 + -- nice try mr lenin
45 + };
46 + _sorcery = {
47 + material = (gem == nil) and {
48 + metal = true; id = metal, data = m;
49 + grindcost = 2, grindvalue = 1;
50 + } or nil;
51 + };
26 52 })
27 53 end
28 -for metal in pairs(sorcery.data.metals) do
54 +-- for metal in pairs(sorcery.data.metals) do
55 +sorcery.register.metals.foreach('sorcery:mkcoins',{'sorcery:generate'}, function(metal)
29 56 register_coin(metal)
30 - for gem in pairs(sorcery.data.gems) do
57 + -- for gem in pairs(sorcery.data.gems) do
58 + sorcery.register.gems.foreach('sorcery:mkcoins_' .. metal, {'sorcery:generate'}, function(gem)
31 59 register_coin(metal,gem)
32 - end
33 -end
60 + end)
61 +end)
34 62 local update_press_output = function(meta)
35 63 local inv = meta:get_inventory()
36 64 local slot_ingot = inv:get_stack('ingot',1)
37 65 local slot_gem = inv:get_stack('gem',1)
38 66 local metalname, gemname
39 67 local coincount
40 68 if not inv:is_empty('ingot') then
41 69 local id = slot_ingot:get_name()
42 70 for name,metal in pairs(sorcery.data.metals) do
43 - if id == metal.ingot then
71 + if id == metal.parts.ingot then
44 72 metalname = name
45 73 coincount = slot_ingot:get_count()
46 74 goto foundmetal
47 75 end
48 76 end
49 77 end
50 78 inv:set_stack('output',1,ItemStack(nil))
51 79 do return end
52 80
53 81 ::foundmetal:: if not inv:is_empty('gem') then
54 82 local id = slot_gem:get_name()
55 83 for name,gem in pairs(sorcery.data.gems) do
56 - if gem.foreign then
57 - if id == gem.foreign then gemname = name
58 - else goto skip end
59 - else
60 - if id == 'sorcery:gem_' .. name then gemname = name
61 - else goto skip end
62 - end
84 + if id == gem.parts.item
85 + then gemname = name
86 + else goto skip end
63 87 coincount = math.min(coincount, slot_gem:get_count())
64 88 do break end
65 89 ::skip::end
66 90 end
67 91
68 92 coincount = coincount * coins_per_ingot
69 93
................................................................................
118 142 listring[current_player;main]
119 143 ]])
120 144 end;
121 145 allow_metadata_inventory_put = function(pos,list,idx,stack,user)
122 146 local id = stack:get_name()
123 147 if list == 'ingot' then
124 148 for name,metal in pairs(sorcery.data.metals) do
125 - if id == metal.ingot then goto okay end
149 + if id == metal.parts.ingot then goto okay end
126 150 end
127 151 elseif list == 'gem' then
128 152 for name,gem in pairs(sorcery.data.gems) do
129 153 if gem.foreign then
130 154 if id == gem.foreign then goto okay end
131 155 else
132 156 if id == 'sorcery:gem_' .. name then goto okay end
................................................................................
136 160 do return 0 end
137 161 ::okay:: return max_components
138 162 end;
139 163 -- mercifully there is never any case where moving between the
140 164 -- inventories of the node is allowable
141 165 allow_metadata_inventory_move = function() return 0 end;
142 166 allow_metadata_inventory_take = function(pos,list,idx,stack,user)
143 - local meta = minetest.get_meta(pos)
144 - local inv = meta:get_inventory()
145 - return inv:get_stack(list,idx):get_count()
167 + local count = stack:get_count()
168 + if list == 'output' then
169 + return (count % coins_per_ingot) == 0 and count or 0
170 + else return count end
146 171 end;
147 172 on_metadata_inventory_put = function(pos,list,idx,stack,user)
148 173 update_press_output(minetest.get_meta(pos))
149 174 end;
150 175 on_metadata_inventory_take = function(pos,list,idx,stack,user)
151 176 local meta = minetest.get_meta(pos)
152 177 if list == 'output' then