sorcery  tnodes.lua at [032f54d1d5]

File tnodes.lua artifact 46cef4271e part of check-in 032f54d1d5


for i=1,minetest.LIGHT_MAX do
	minetest.register_node('sorcery:air_glimmer_' .. tostring(i), {
		drawtype = 'airlike';
		light_source = 5 + math.ceil(i * (11/minetest.LIGHT_MAX));
		sunlight_propagates = true;
		buildable_to = true;
		pointable = false;
		walkable = false;
		floodable = true;
		drop = {max_items = 0, items = {}};
		on_blast = function() end; -- not affected by explosions
		groups = { air = 1; sorcery_air = 1; not_in_creative_inventory = 1; };
		on_construct = function(pos)
			local meta = minetest.get_meta(pos)
			meta:set_float('duration',10)
			meta:set_float('timeleft',10)
			meta:set_int('power',minetest.LIGHT_MAX)
			minetest.get_node_timer(pos):start(1)
		end;
		on_timer = function(pos,dtime)
			local meta = minetest.get_meta(pos)
			local elapsed = dtime + meta:get_float('duration') - meta:get_float('timeleft')
			local level = 1 - (elapsed / meta:get_float('duration'))
			local lum = math.ceil(level*meta:get_int('power'))
			local probe = sorcery.spell.probe(pos)
			if probe.disjunction then
				minetest.remove_node(pos)
				return false
			end
			if lum ~= i then
				if lum <= 0 then
					minetest.remove_node(pos)
					return false
				else
					minetest.swap_node(pos,{name='sorcery:air_glimmer_'..tostring(lum)})
				end
			end
			minetest.add_particlespawner {
				amount = 3 * meta:get_int('power');
				time = 1.1;
				minpos = vector.subtract(pos,2);
				maxpos = vector.add(pos,2);
				minvel = {x = -0.5; z = -0.5; y = -0.3};
				maxvel = {x =  0.5; z =  0.5; y =  0.3};
				minsize = 0.3, maxsize = 0.9;
				minexptime = 0.5, maxexptime = 1.2;
				texture = 'sorcery_spark.png';
				animation = {
					glow = i;
					length = 1.2;
					type = 'vertical_frames';
					aspect_w = 16;
					aspect_h = 16;
				}
			}
			meta:set_float('timeleft',meta:get_float('duration') - elapsed)
			return true
		end;
	})
end