Differences From
Artifact [080406f8d2]:
46 46 local props = object:get_properties()
47 47 local node = minetest.get_node(pos)
48 48 props.wield_item = itemstring
49 49 object:set_properties(props)
50 50 object:set_yaw(math.pi*2 - node.param2*(math.pi / 2))
51 51 end
52 52 end
53 +
54 +-- remove unknown gifts
55 +minetest.register_on_mods_loaded(function()
56 + for name, god in pairs(sorcery.data.gods) do
57 + local bad = {}
58 + for g in pairs(god.gifts) do
59 + -- can't mutate table while we're iterating it
60 + if not minetest.registered_nodes[g] then bad[#bad+1] = g end
61 + end
62 + for _, g in ipairs(bad) do god.gifts[g] = nil end
63 + end
64 +end)
53 65
54 66 for name, god in pairs(sorcery.data.gods) do
55 67 local hitbox = {
56 68 0-(god.idol.width / 2.0), 0-(god.idol.height / 2.0), -0.15,
57 69 god.idol.width / 2.0, god.idol.height / 2.0, 0.15
58 70 } -- {xmin, ymin, zmin,
59 71 -- xmax, ymax, zmax} in nodes from node center.
60 72 paramtype = "light";
61 - minetest.register_node('sorcery:idol_' .. name, {
73 + sorcery.lib.node.reg_autopreserve('sorcery:idol_' .. name, {
62 74 description = god.idol.desc;
63 75 drawtype = "mesh";
64 76 mesh = 'sorcery-idol-' .. name .. '.obj';
65 77 paramtype = 'light';
66 78 paramtype2 = 'facedir';
67 79 sunlight_propagates = true;
68 80 stack_max = 1;
69 81 tiles = god.idol.tex;
70 82 selection_box = { type = "fixed"; fixed = {hitbox}; };
71 83 collision_box = { type = "fixed"; fixed = {hitbox}; };
72 84 groups = { cracky = 2, sorcery_idol = 1, heavy = 1, sorcery_worship = 1};
73 85
74 - after_place_node = function(pos, placer, stack, pointat)
75 - local meta = minetest.get_meta(pos)
76 - local stackmeta = stack:get_meta()
77 - meta:set_int('favor', stackmeta:get_int('favor'))
78 - meta:set_string('last_sacrifice', stackmeta:get_string('last_sacrifice'))
79 -
86 + on_construct = function(pos)
80 87 minetest.get_node_timer(pos):start(1)
81 88 end;
82 89
83 - drop = {
84 - -- for some idiot reason this is necessary for
85 - -- preserve_metadata to work right
86 - max_items = 1;
87 - items = {
88 - { items = {'sorcery:idol_' .. name} }
89 - };
90 - };
91 -
92 - preserve_metadata = function(pos, node, meta, newstack)
93 - newstack[1]:get_meta():from_table(meta)
94 - end;
95 -
96 90 on_timer = function(pos, elapsed)
97 91 local altar = minetest.find_node_near(pos, 3, "sorcery:altar")
98 92 -- TODO even without an altar, an idol with high favor could still be the source of miracles
93 + -- refills nearby partly empty troughs at cost to favor?
99 94 if not altar then return true end
100 95
101 96 local altarmeta = minetest.get_meta(altar)
102 97 local inv = altarmeta:get_inventory()
103 98 local idolmeta = minetest.get_meta(pos)
104 99 local divine_favor = idolmeta:get_int('favor')
105 100 local bestow = function(item,color)
................................................................................
234 229 }
235 230 end
236 231 -- preserve wear
237 232 local gift
238 233 if type(tx) == 'string' then
239 234 gift = ItemStack(tx)
240 235 else gift = tx end
236 + if not gift:is_known() then goto skip end
241 237 local wear = stack:get_wear()
242 238 if wear > 0 then
243 239 gift:set_wear(wear)
244 240 end
245 241 -- preserve meta
246 242 local gm = gift:get_meta()
247 243 gm:from_table(
................................................................................
264 260 if divine_favor >= cost then
265 261 bestow(gift)
266 262 divine_favor = divine_favor - cost
267 263 log.act(god.name, 'has consecrated', s, 'into', tx, 'for the cost of', cost, 'points of divine favor')
268 264 goto refresh
269 265 end
270 266 end
271 - end
267 + ::skip::end
272 268 end
273 269
274 270 ::refresh::
275 271 idolmeta:set_int('favor', divine_favor)
276 272 update_altar(altar,nil)
277 273 return true
278 274 end;