-- Rain
minetest.register_globalstep(function(dtime)
	if weather ~= "rain" then return end
	for _, player in ipairs(minetest.get_connected_players()) do

--		-- Setting sky to dreary
--		local sky = {}
--		local ps = {}
--
--               sky.bgcolor, sky.type, sky.textures = player:get_sky()
--
--              local name = player:get_player_name()
--		if ps[name] == nil then
--			ps[name] = {p = player, sky = sky}
--			player:set_sky(0xffffff, "plain", {})
--		end

		local ppos = player:get_pos()

		-- Make sure player is not in a cave/house...
		if minetest.env:get_node_light(ppos, 0.5) ~= 15 then return end

		-- The actual rain
		local minp = addvectors(ppos, {x=-20, y=7, z=-20})
		local maxp = addvectors(ppos, {x= 20, y=7, z= 20})

		local vel = {x=0, y=   -4, z=0}
		local acc = {x=0, y=-9.81, z=0}

		minetest.add_particlespawner({amount=40, time=0.5,
			minpos=minp, maxpos=maxp,
			minvel=vel, maxvel=vel,
			minacc=acc, maxacc=acc,
			minexptime=0.8, maxexptime=0.8,
			minsize=40, maxsize=40,
			collisiondetection=false, vertical=true, texture="weather_rain.png", player=player:get_player_name()})
	end
end)
