@@ -108,11 +108,13 @@ L.image('sorcery_node_liquid.png'):multiply(L.color(liq.color)) ) else top=top:blit( L.image('sorcery_trough_bottom.png') ) end - local ttlc = function(liq,i) return - liq and string.format('%s Trough', L.str.capitalize(liq.name)), - liq and string.format('%s of %s', liq.measure(i * Q), liq.name) + local ttlc = function(liq,i) + if type(liq) == 'string' then liq = sorcery.register.liquid.db[liq] end + return + liq and string.format('%s Trough', L.str.capitalize(liq.name)), + liq and string.format('%s of %s', liq.measure(i * Q), liq.name) end local trough_title, trough_content = ttlc(liq,i) local function trough_caption(pos,i,l) local trough_title, trough_content = ttlc(l or liq,i) @@ -171,25 +173,44 @@ charge = liq and Q * i; empty = 'sorcery:trough'; max = constants.bottles_per_trough * Q; set_node_vol = liq and function(pos, vol) + log.act('putting', vol, liq, 'in trough at', pos) vol = math.min(M, math.max(0, math.floor(vol / Q))) minetest.swap_node(pos, {name = lid(vol)}) trough_caption(pos, vol) + return vol * Q end; set_node_liq = function(pos, liq, vol) - log.act('adding', vol, 'to trough at', liq) + log.act('putting', vol, liq, 'in trough at', pos) vol = vol or Q * i local idx = math.min(M, math.floor(vol/Q)) minetest.swap_node(pos, {name = trough_mkid(liq, idx)}) trough_caption(pos, idx, liq) + return idx * Q end } }; }) end end sorcery.liquid.mktrough() + +sorcery.liquid.setctr = function(pos, liq, vol, sameliq) + local n = sorcery.lib.node.force(pos) + if minetest.get_item_group(n.name, 'sorcery_container') ~= 2 then return false end + local def = minetest.registered_items[n.name]._sorcery + if not (def and def.container and def.container.set_node_liq) then + log.err('node',n.name,'marked as liquid container but is missing container.set_node_liq callback') + return false + end + if sameliq then + if def.container.has ~= nil and def.container.has ~= liq then + return false + end + end + return def.container.set_node_liq(pos, liq, vol) +end sorcery.liquid.measure_default = sorcery.liquid.units.dram sorcery.liquid.container = function(liq, ctr)