]> git.lizzy.rs Git - crafter_client.git/blobdiff - weather_handling.lua
Update README.md
[crafter_client.git] / weather_handling.lua
index 40ceb50b5a7fa8ea23857f127cf40280eac7bcc8..65ca36cf2d5a268c91c17b184ac12ea7bd0c8359 100644 (file)
@@ -1,4 +1,7 @@
-local minetest,name,vector,math,pairs = minetest,minetest.localplayer:get_name(),vector,math,pairs
+local
+minetest,name,vector,math,pairs
+=
+minetest,minetest.localplayer:get_name(),vector,math,pairs
 
 local weather_intake = minetest.mod_channel_join("weather_intake")
 local weather = minetest.mod_channel_join("weather_nodes")
@@ -13,6 +16,14 @@ local id_table = {}
 
 local rain_sound_handle = nil
 
+local liquids = {
+       ["main:water"] = true,
+       ["main:waterflow"] = true,
+       ["main:lava"] = true,
+       ["main:lavaflow"] = true,
+       ["nether:lava"] = true,
+       ["nether:lavaflow"] = true,
+}
 
 
 local y
@@ -27,6 +38,8 @@ local spawn_table
 local lightlevel
 local null
 local curr_light
+local distance = vector.distance
+local current_node 
 local weather_effects = function(player,defined_type)
        pos = vector.round(player:get_pos())
        area = vector.new(10,10,10)
@@ -45,15 +58,17 @@ local weather_effects = function(player,defined_type)
        end
 
        if defined_type == "rain" then
-       curr_light = minetest.get_node_light({x=pos.x,y=pos.y+1,z=pos.z},0.5)
+       curr_light = minetest.get_node_light(minetest.camera:get_pos(),0.5)
        --rain sound effect
        if curr_light then
-               if curr_light >= 15 then
+               current_node = minetest.get_node_or_nil(minetest.camera:get_pos())
+
+               if curr_light >= 15 and current_node and not liquids[current_node.name] then
                        if not rain_sound_handle then
                                rain_sound_handle = minetest.sound_play("rain", {loop=true,gain=0})
                        end
                        minetest.sound_fade(rain_sound_handle, 0.5, 1)
-               elseif curr_light < 15 and rain_sound_handle then
+               elseif rain_sound_handle then
                        minetest.sound_fade(rain_sound_handle, -0.5, 0)
                        rain_sound_handle = nil
                end
@@ -62,8 +77,8 @@ local weather_effects = function(player,defined_type)
        particle_table = {
                amount = 3,
                time = 0.5,
-               minvel = {x=0, y=-20, z=0},
-               maxvel = {x=0, y=-20, z=0},
+               minvel = {x=0, y=-30, z=0},
+               maxvel = {x=0, y=-30, z=0},
                minacc = {x=0, y=0, z=0},
                maxacc = {x=0, y=0, z=0},
                minexptime = 0.5,
@@ -115,18 +130,20 @@ local weather_effects = function(player,defined_type)
 
        for x = min.x,max.x do
                for z = min.z,max.z do
-                       y = pos.y - 5
-                       if spawn_table[x] and spawn_table[x][z] then
-                               y = spawn_table[x][z]
-                       end
-                       if minetest.get_node_or_nil(vector.new(x,y+1,z)) ~= nil then
-                               lightlevel = minetest.get_node_light(vector.new(x,y+1,z), 0.5)
-                               if lightlevel >= 14 or defined_type == "ichor" then
+                       if distance({x=x,y=0,z=z},{x=pos.x,y=0,z=pos.z}) <= 10 then
+                               y = pos.y - 5
+                               if spawn_table[x] and spawn_table[x][z] then
+                                       y = spawn_table[x][z]
+                               end
+                               if minetest.get_node_or_nil(vector.new(x,y+1,z)) ~= nil then
+                                       lightlevel = minetest.get_node_light(vector.new(x,y+1,z), 0.5)
+                                       if lightlevel >= 14 or defined_type == "ichor" then
 
-                                       particle_table.minpos = vector.new(x-0.5,y,z-0.5)
-                                       particle_table.maxpos = vector.new(x+0.5,y+20,z+0.5)
+                                               particle_table.minpos = vector.new(x-0.5,y,z-0.5)
+                                               particle_table.maxpos = vector.new(x+0.5,y+20,z+0.5)
 
-                                       null = minetest.add_particlespawner(particle_table)
+                                               null = minetest.add_particlespawner(particle_table)
+                                       end
                                end
                        end
                end
@@ -135,33 +152,42 @@ end
 
 
 
+
 --client runs through spawning weather particles
 local player_pos
+local current_node
 local function update_weather()
        player_pos = minetest.localplayer:get_pos()
        if do_effects then
                if snow or rain then
-                       --do normal weather
-                       if player_pos.y > -10033 then
-                               if snow == true then
-                                       weather_effects(minetest.localplayer, "snow")
-                               elseif rain == true then
-                                       weather_effects(minetest.localplayer, "rain")
-                               end
-                       --rain blood upwards in the nether
-                       else
-                               if snow == true or rain == true then
-                                       weather_effects(minetest.localplayer, "ichor")
-                               end
-                       
-                               --stop the rain sound effect
-                               if rain_sound_handle then
-                                       minetest.sound_fade(rain_sound_handle, -0.5, 0)
-                                       rain_sound_handle = nil
+                       current_node = minetest.get_node_or_nil(minetest.camera:get_pos())
+                       if current_node and not liquids[current_node.name] then
+                               --do normal weather
+                               if player_pos.y > -10033 then
+                                       if snow == true then
+                                               weather_effects(minetest.localplayer, "snow")
+                                       elseif rain == true then
+                                               weather_effects(minetest.localplayer, "rain")
+                                       end
+                               --rain blood upwards in the nether
+                               else
+                                       if snow == true or rain == true then
+                                               weather_effects(minetest.localplayer, "ichor")
+                                       end
+                               
+                                       --stop the rain sound effect
+                                       if rain_sound_handle then
+                                               minetest.sound_fade(rain_sound_handle, -0.5, 0)
+                                               rain_sound_handle = nil
+                                       end
                                end
+                       elseif rain_sound_handle then
+                               minetest.sound_fade(rain_sound_handle, -0.5, 0)
+                               rain_sound_handle = nil
                        end
                end
        end
+
        if not rain and rain_sound_handle then
                minetest.sound_fade(rain_sound_handle, -0.5, 0)
                rain_sound_handle = nil
@@ -177,6 +203,10 @@ minetest.register_on_modchannel_message(function(channel_name, sender, message)
        --to spawn weather columns on
        if sender == "" and channel_name == "weather_nodes" then
                all_nodes = minetest.deserialize(message)
+               nodes = {}
+               for _,key in pairs(all_nodes) do
+                       nodes[key] = true
+               end
                do_effects = true
                weather:leave() --leave the channel
        end