@@ -49,8 +49,20 @@ object:set_properties(props) object:set_yaw(math.pi*2 - node.param2*(math.pi / 2)) end end + +-- remove unknown gifts +minetest.register_on_mods_loaded(function() + for name, god in pairs(sorcery.data.gods) do + local bad = {} + for g in pairs(god.gifts) do + -- can't mutate table while we're iterating it + if not minetest.registered_nodes[g] then bad[#bad+1] = g end + end + for _, g in ipairs(bad) do god.gifts[g] = nil end + end +end) for name, god in pairs(sorcery.data.gods) do local hitbox = { 0-(god.idol.width / 2.0), 0-(god.idol.height / 2.0), -0.15, @@ -57,9 +69,9 @@ god.idol.width / 2.0, god.idol.height / 2.0, 0.15 } -- {xmin, ymin, zmin, -- xmax, ymax, zmax} in nodes from node center. paramtype = "light"; - minetest.register_node('sorcery:idol_' .. name, { + sorcery.lib.node.reg_autopreserve('sorcery:idol_' .. name, { description = god.idol.desc; drawtype = "mesh"; mesh = 'sorcery-idol-' .. name .. '.obj'; paramtype = 'light'; @@ -70,33 +82,16 @@ selection_box = { type = "fixed"; fixed = {hitbox}; }; collision_box = { type = "fixed"; fixed = {hitbox}; }; groups = { cracky = 2, sorcery_idol = 1, heavy = 1, sorcery_worship = 1}; - after_place_node = function(pos, placer, stack, pointat) - local meta = minetest.get_meta(pos) - local stackmeta = stack:get_meta() - meta:set_int('favor', stackmeta:get_int('favor')) - meta:set_string('last_sacrifice', stackmeta:get_string('last_sacrifice')) - + on_construct = function(pos) minetest.get_node_timer(pos):start(1) end; - drop = { - -- for some idiot reason this is necessary for - -- preserve_metadata to work right - max_items = 1; - items = { - { items = {'sorcery:idol_' .. name} } - }; - }; - - preserve_metadata = function(pos, node, meta, newstack) - newstack[1]:get_meta():from_table(meta) - end; - on_timer = function(pos, elapsed) local altar = minetest.find_node_near(pos, 3, "sorcery:altar") -- TODO even without an altar, an idol with high favor could still be the source of miracles + -- refills nearby partly empty troughs at cost to favor? if not altar then return true end local altarmeta = minetest.get_meta(altar) local inv = altarmeta:get_inventory() @@ -237,8 +232,9 @@ local gift if type(tx) == 'string' then gift = ItemStack(tx) else gift = tx end + if not gift:is_known() then goto skip end local wear = stack:get_wear() if wear > 0 then gift:set_wear(wear) end @@ -267,9 +263,9 @@ log.act(god.name, 'has consecrated', s, 'into', tx, 'for the cost of', cost, 'points of divine favor') goto refresh end end - end + ::skip::end end ::refresh:: idolmeta:set_int('favor', divine_favor)