]> git.lizzy.rs Git - crafter_client.git/commitdiff
Overhaul weather effects
authoroilboi <47129783+oilboi@users.noreply.github.com>
Mon, 8 Jun 2020 03:42:27 +0000 (23:42 -0400)
committeroilboi <47129783+oilboi@users.noreply.github.com>
Mon, 8 Jun 2020 03:42:27 +0000 (23:42 -0400)
version_send.lua
weather_handling.lua

index cffcfebefb3dff43d9644017adc1b93a41bcccf4..c80dabe6d4675e14ad3a32ffa4745ddd4442213c 100644 (file)
@@ -1,3 +1,3 @@
 minetest.after(0,function()
-    version_channel:send_all("0.5003")
+    version_channel:send_all("0.5004")
 end)
\ No newline at end of file
index d28cf451e9d6a341c150c826b69c403439aba8dc..883a400aa803987ad0592938d4176f6d2b947b44 100644 (file)
@@ -7,75 +7,37 @@ local id_table = {}
 
 local rain_sound_handle = nil
 
-local spawn_snow = function(player)
-       local pos = player:get_pos()
-       local radius = 10
-       local particle_table = {}
-       
-       local area = vector.new(10,10,10)
-       
-       local min = vector.subtract(pos, area)
-       local max = vector.add(pos, area)
-       
-       
-       local area_index = minetest.find_nodes_in_area_under_air(min, max, all_nodes)
-       
-       local spawn_table = {}
-       --find the highest y value
-       for _,index in pairs(area_index) do
-               if not spawn_table[index.x] then spawn_table[index.x] = {} end
-               if not spawn_table[index.x][index.z] then
-                       spawn_table[index.x][index.z] = index.y
-               elseif spawn_table[index.x][index.z] < index.y then
-                       spawn_table[index.x][index.z] = index.y
-               end
-       end
-       
-       for x,x_index in pairs(spawn_table) do
-               for z,y in pairs(x_index) do
-                       if minetest.get_node_or_nil(vector.new(x,y+1,z)) ~= nil then
-                               local pos = vector.new(x,y+1,z)
-                               local lightlevel = minetest.get_node_light(pos, 0.5)
-                               if lightlevel >= 14 then
-                                       minetest.add_particlespawner({
-                                               amount = 1,
-                                               time = 0.5,
-                                               minpos = vector.new(x-0.5,y,z-0.5),
-                                               maxpos = vector.new(x+0.5,y+20,z+0.5),
-                                               minvel = {x=-0.2, y=-0.2, z=-0.2},
-                                               maxvel = {x=0.2, y=-0.5, z=0.2},
-                                               minacc = {x=0, y=0, z=0},
-                                               maxacc = {x=0, y=0, z=0},
-                                               minexptime = 1,
-                                               maxexptime = 1,
-                                               minsize = 1,
-                                               maxsize = 1,
-                                               collisiondetection = true,
-                                               collision_removal = true,
-                                               object_collision = false,
-                                               texture = "snowflake_"..math.random(1,2)..".png",
-                                               playername = player:get_name(),
-                                       })
-                               end
-                       end
-               end
-       end
-end
 
-local spawn_ichor = function(player)
-       local pos = player:get_pos()
-       local radius = 10
-       local particle_table = {}
-       
-       local area = vector.new(10,10,10)
-       
-       local min = vector.subtract(pos, area)
-       local max = vector.add(pos, area)
-       
-       
-       local area_index = minetest.find_nodes_in_area_under_air(min, max, all_nodes)
-       
-       local spawn_table = {}
+--this is rice but it boosts the FPS slightly
+local y
+local find_em = minetest.find_nodes_in_area_under_air
+local pos
+local radius = 10
+local particle_table
+local area
+local min
+local max
+local round_it = vector.round
+local new_vec  = vector.new
+local add_it   = vector.add
+local sub_it   = vector.subtract
+local area_index
+local spawn_table
+local get_the_node = minetest.get_node_or_nil
+local get_the_light = minetest.get_node_light
+local lightlevel
+local add_ps = minetest.add_particlespawner
+local l_name = name
+-------
+local weather_effects = function(player,defined_type)
+       pos = round_it(player:get_pos())
+       particle_table = {}
+       area = new_vec(10,10,10)
+       min = sub_it(pos, area)
+       max = add_it(pos, area)
+       area_index = find_em(min, max, all_nodes)
+       spawn_table = nil -- this has to be terminated before reassignment
+       spawn_table = {}
        --find the highest y value
        for _,index in pairs(area_index) do
                if not spawn_table[index.x] then spawn_table[index.x] = {} end
@@ -85,91 +47,85 @@ local spawn_ichor = function(player)
                        spawn_table[index.x][index.z] = index.y
                end
        end
-       
-       for x,x_index in pairs(spawn_table) do
-               for z,y in pairs(x_index) do
-                       if minetest.get_node_or_nil(vector.new(x,y+1,z)) ~= nil then
-                               local pos = vector.new(x,y+1,z)
-                               minetest.add_particlespawner({
-                                       amount = 1,
-                                       time = 0.5,
-                                       minpos = vector.new(x-0.5,y,z-0.5),
-                                       maxpos = vector.new(x+0.5,y+20,z+0.5),
-                                       minvel = {x=-0.2, y=0.2, z=-0.2},
-                                       maxvel = {x=0.2, y=0.5, z=0.2},
-                                       minacc = {x=0, y=0, z=0},
-                                       maxacc = {x=0, y=0, z=0},
-                                       minexptime = 1,
-                                       maxexptime = 1,
-                                       minsize = 1,
-                                       maxsize = 1,
-                                       collisiondetection = true,
-                                       collision_removal = true,
-                                       object_collision = false,
-                                       texture = "ichor_"..math.random(1,2)..".png",
-                                       playername = player:get_name(),
-                               })
+       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
-               end
-       end
-end
-
-local spawn_rain = function(player)
-       local pos = player:get_pos()
-       local radius = 10
-       local particle_table = {}
-       
-       local area = vector.new(10,10,10)
-       
-       local min = vector.subtract(pos, area)
-       local max = vector.add(pos, area)
-       
-       
-       local area_index = minetest.find_nodes_in_area_under_air(min, max, all_nodes)
-       
-       local spawn_table = {}
-       --find the highest y value
-       for _,index in pairs(area_index) do
-               if not spawn_table[index.x] then spawn_table[index.x] = {} end
-               if not spawn_table[index.x][index.z] then
-                       spawn_table[index.x][index.z] = index.y
-               elseif spawn_table[index.x][index.z] < index.y then
-                       spawn_table[index.x][index.z] = index.y
-               end
-       end
-       
-       for x,x_index in pairs(spawn_table) do
-               for z,y in pairs(x_index) do
-                       if minetest.get_node_or_nil(vector.new(x,y+1,z)) ~= nil then
-                               local pos = vector.new(x,y+1,z)
-                               local lightlevel = minetest.get_node_light(pos, 0.5)
-                               if lightlevel >= 14 then
-                                       minetest.add_particlespawner({
-                                               amount = 3,
-                                               time = 0.5,
-                                               minpos = vector.new(x-0.5,y,z-0.5),
-                                               maxpos = vector.new(x+0.5,y+20,z+0.5),
-                                               minvel = {x=0, y=-20, z=0},
-                                               maxvel = {x=0, y=-20, z=0},
-                                               minacc = {x=0, y=0, z=0},
-                                               maxacc = {x=0, y=0, z=0},
-                                               minexptime = 1,
-                                               maxexptime = 2,
-                                               minsize = 4,
-                                               maxsize = 4,
-                                               collisiondetection = true,
-                                               collision_removal = true,
-                                               object_collision = false,
-                                               vertical = true,
-                                               texture = "raindrop.png^[opacity:80",
-                                               playername = player:get_name(),
-                                       })
+                       if get_the_node(new_vec(x,y+1,z)) ~= nil then
+                               lightlevel = get_the_light(new_vec(x,y+1,z), 0.5)
+                               if lightlevel >= 14 or defined_type == "ichor" then
+                                       if defined_type == "rain" then
+                                               add_ps({
+                                                       amount = 3,
+                                                       time = 0.5,
+                                                       minpos = new_vec(x-0.5,y,z-0.5),
+                                                       maxpos = new_vec(x+0.5,y+20,z+0.5),
+                                                       minvel = {x=0, y=-20, z=0},
+                                                       maxvel = {x=0, y=-20, z=0},
+                                                       minacc = {x=0, y=0, z=0},
+                                                       maxacc = {x=0, y=0, z=0},
+                                                       minexptime = 0.5,
+                                                       maxexptime = 0.5,
+                                                       minsize = 4,
+                                                       maxsize = 4,
+                                                       collisiondetection = true,
+                                                       collision_removal = true,
+                                                       object_collision = false,
+                                                       vertical = true,
+                                                       texture = "raindrop.png^[opacity:80",
+                                                       playername = l_name,
+                                               })
+                                       elseif defined_type == "snow" then
+                                               add_ps({
+                                                       amount = 1,
+                                                       time = 0.5,
+                                                       minpos = vector.new(x-0.5,y,z-0.5),
+                                                       maxpos = vector.new(x+0.5,y+20,z+0.5),
+                                                       minvel = {x=-0.2, y=-0.2, z=-0.2},
+                                                       maxvel = {x=0.2, y=-0.5, z=0.2},
+                                                       minacc = {x=0, y=0, z=0},
+                                                       maxacc = {x=0, y=0, z=0},
+                                                       minexptime = 1,
+                                                       maxexptime = 1,
+                                                       minsize = 1,
+                                                       maxsize = 1,
+                                                       collisiondetection = true,
+                                                       collision_removal = true,
+                                                       object_collision = false,
+                                                       texture = "snowflake_"..math.random(1,2)..".png",
+                                                       playername = l_name,
+                                               })
+                                       elseif defined_type == "ichor" then
+                                               add_ps({
+                                                       amount = 1,
+                                                       time = 0.5,
+                                                       minpos = vector.new(x-0.5,y,z-0.5),
+                                                       maxpos = vector.new(x+0.5,y+20,z+0.5),
+                                                       minvel = {x=-0.2, y=0.2, z=-0.2},
+                                                       maxvel = {x=0.2, y=0.5, z=0.2},
+                                                       minacc = {x=0, y=0, z=0},
+                                                       maxacc = {x=0, y=0, z=0},
+                                                       minexptime = 1,
+                                                       maxexptime = 1,
+                                                       minsize = 1,
+                                                       maxsize = 1,
+                                                       collisiondetection = true,
+                                                       collision_removal = true,
+                                                       object_collision = false,
+                                                       texture = "ichor_"..math.random(1,2)..".png",
+                                                       playername = player:get_name(),
+                                               })
+                                       end
                                end
                        end
                end
        end
 end
 
+
+
 --client runs through spawning weather particles
 local player_pos
 local function update_weather()
@@ -179,14 +135,14 @@ local function update_weather()
                        --do normal weather
                        if player_pos.y > -10033 then
                                if snow == true then
-                                       spawn_snow(minetest.localplayer)
+                                       weather_effects(minetest.localplayer, "snow")
                                elseif rain == true then
-                                       spawn_rain(minetest.localplayer)
+                                       weather_effects(minetest.localplayer, "rain")
                                end
                        --rain blood upwards in the nether
                        else
                                if snow == true or rain == true then
-                                       spawn_ichor(minetest.localplayer)
+                                       weather_effects(minetest.localplayer, "ichor")
                                end
                        
                                --stop the rain sound effect