From 074d983d1c16638c9a8aeddf540133e753150caa Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Fri, 8 Nov 2019 13:21:39 +0100 Subject: [PATCH] light rain and thunderstorm --- .luacheckrc | 3 ++- init.lua | 2 ++ light_rain.lua | 55 ++++++++++++++++++++++++++++++++++++++++ thunderstorm.lua | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 light_rain.lua create mode 100644 thunderstorm.lua diff --git a/.luacheckrc b/.luacheckrc index 5a73642..c37f8be 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -14,5 +14,6 @@ read_globals = { "dump", "VoxelArea", -- deps - "epic", "screwdriver" + "epic", "screwdriver", + "lightning" } diff --git a/init.lua b/init.lua index 889b1bc..4aeae64 100644 --- a/init.lua +++ b/init.lua @@ -7,7 +7,9 @@ epic_weather = { dofile(MP.."/register.lua") dofile(MP.."/block.lua") +dofile(MP.."/light_rain.lua") dofile(MP.."/rain.lua") +dofile(MP.."/thunderstorm.lua") dofile(MP.."/snow.lua") epic.register_hook({ diff --git a/light_rain.lua b/light_rain.lua new file mode 100644 index 0000000..dd8bc23 --- /dev/null +++ b/light_rain.lua @@ -0,0 +1,55 @@ + +epic_weather.register_weather({ name = "Light rain" }) + + +local function do_rain(player) + local ppos = player:get_pos() + local player_name = player:get_player_name() + + if math.random(3) == 1 then + minetest.sound_play("epic_weather_rain", { + to_player = player_name, + gain = 1.0, + fade = 0.5, + pos = vector.add(ppos, {x=0, y=5, z=0}) + }) + end + + minetest.add_particlespawner({ + amount = 250, + time = 2, + minpos = vector.add(ppos, {x=-20, y=10, z=-20}), + maxpos = vector.add(ppos, {x=20, y=10, z=20}), + minvel = {x=2, y=-5, z=0}, + maxvel = {x=2, y=-12, z=0}, + minacc = {x=0, y=0, z=0}, + maxacc = {x=0, y=0, z=0}, + minexptime = 1, + maxexptime = 5, + minsize = 20, + maxsize = 30.7, + collisiondetection = true, + collision_removal = true, + object_collision = true, + vertical = true, + texture = "epic_weather_rain.png", + playername = player_name + }) +end + +local timer = 0 +minetest.register_globalstep(function(dtime) + timer = timer + dtime + if timer < 2 then return end + timer=0 + + for _, player in ipairs(minetest.get_connected_players()) do + local playername = player:get_player_name() + local weathername = epic_weather.current_weather[playername] + + if weathername == "Light rain" then + do_rain(player) + end + end + +end) diff --git a/thunderstorm.lua b/thunderstorm.lua new file mode 100644 index 0000000..666f3dc --- /dev/null +++ b/thunderstorm.lua @@ -0,0 +1,65 @@ + +epic_weather.register_weather({ name = "Thunderstorm" }) + + +local function do_rain(player) + local ppos = player:get_pos() + local player_name = player:get_player_name() + + if math.random(2) == 1 then + minetest.sound_play("epic_weather_rain", { + to_player = player_name, + gain = 1.0, + fade = 0.5, + pos = vector.add(ppos, {x=0, y=5, z=0}) + }) + end + + if math.random(10) == 1 then + local x_offset = math.floor(math.random(100)) - 50 + local y_offset = math.floor(math.random(30)) + local z_offset = math.floor(math.random(100)) - 50 + + local strike_pos = vector.add(ppos, { x=x_offset, y=y_offset, z=z_offset}) + + lightning.strike(strike_pos) + end + + minetest.add_particlespawner({ + amount = 750, + time = 2, + minpos = vector.add(ppos, {x=-20, y=10, z=-20}), + maxpos = vector.add(ppos, {x=20, y=10, z=20}), + minvel = {x=2, y=-5, z=0}, + maxvel = {x=2, y=-12, z=0}, + minacc = {x=0, y=0, z=0}, + maxacc = {x=0, y=0, z=0}, + minexptime = 1, + maxexptime = 5, + minsize = 20, + maxsize = 30.7, + collisiondetection = true, + collision_removal = true, + object_collision = true, + vertical = true, + texture = "epic_weather_rain.png", + playername = player_name + }) +end + +local timer = 0 +minetest.register_globalstep(function(dtime) + timer = timer + dtime + if timer < 2 then return end + timer=0 + + for _, player in ipairs(minetest.get_connected_players()) do + local playername = player:get_player_name() + local weathername = epic_weather.current_weather[playername] + + if weathername == "Thunderstorm" then + do_rain(player) + end + end + +end)