This repository has been archived by the owner on Oct 6, 2019. It is now read-only.
forked from HybridDog/weather-pack
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathheavy_rain.lua
211 lines (175 loc) · 4.51 KB
/
heavy_rain.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
------------------------------
-- Happy Weather: Heavy Rain
-- License: MIT
-- Credits: xeranas
------------------------------
local heavy_rain = {}
heavy_rain.last_check = 0
heavy_rain.check_interval = 200
-- Weather identification code
heavy_rain.code = "heavy_rain"
-- Keeps sound handler references
local sound_handlers = {}
-- Manual triggers flags
local manual_trigger_start = false
local manual_trigger_end = false
-- Skycolor layer id
local SKYCOLOR_LAYER = "happy_weather_heavy_rain_sky"
heavy_rain.is_starting = function(dtime, position)
if heavy_rain.last_check + heavy_rain.check_interval < os.time() then
heavy_rain.last_check = os.time()
local heavy_rain_chance = 0.06
if hw_utils.is_biome_tropic(position) then
heavy_rain_chance = 0.4
end
if math.random() < heavy_rain_chance then
happy_weather.request_to_end("light_rain")
happy_weather.request_to_end("rain")
return true
end
end
if manual_trigger_start then
manual_trigger_start = false
return true
end
return false
end
heavy_rain.is_ending = function(dtime)
if heavy_rain.last_check + heavy_rain.check_interval < os.time() then
heavy_rain.last_check = os.time()
if math.random() < 0.7 then
if math.random() < 0.4 then
happy_weather.request_to_start("rain")
end
return true
end
end
if manual_trigger_end then
manual_trigger_end = false
return true
end
return false
end
local set_sky_box = function(player_name)
local sl = {}
sl.name = SKYCOLOR_LAYER
sl.sky_data = {
gradient_colors = {
{r=0, g=0, b=0},
{r=85, g=86, b=98},
{r=142, g=140, b=149},
{r=85, g=86, b=98},
{r=0, g=0, b=0}
},
}
sl.clouds_data = {
gradient_colors = {
{r=0, g=0, b=0},
{r=65, g=66, b=78},
{r=112, g=110, b=119},
{r=65, g=66, b=78},
{r=0, g=0, b=0}
},
speed = {z = 10, y = -40},
density = 0.6
}
skylayer.add_layer(player_name, sl)
end
local set_rain_sound = function(player)
return minetest.sound_play("heavy_rain_drop", {
object = player,
max_hear_distance = 2,
loop = true,
})
end
local remove_rain_sound = function(player)
local sound = sound_handlers[player:get_player_name()]
if sound ~= nil then
minetest.sound_stop(sound)
sound_handlers[player:get_player_name()] = nil
end
end
heavy_rain.add_player = function(player)
sound_handlers[player:get_player_name()] = set_rain_sound(player)
set_sky_box(player:get_player_name())
end
heavy_rain.remove_player = function(player)
remove_rain_sound(player)
skylayer.remove_layer(player:get_player_name(), SKYCOLOR_LAYER)
end
local rain_drop_texture = "happy_weather_heavy_rain_drops.png"
local add_close_range_rain_particle = function(player)
local offset = {
front = 1,
back = 0,
top = 6
}
local random_pos = hw_utils.get_random_pos(player, offset)
local rain_texture_size_offset_y = -1
if hw_utils.is_outdoor(random_pos, rain_texture_size_offset_y) then
minetest.add_particle({
pos = {x=random_pos.x, y=random_pos.y, z=random_pos.z},
velocity = {x=0, y=-10, z=0},
acceleration = {x=0, y=-10, z=0},
expirationtime = 5,
size = 30,
collisiondetection = true,
collision_removal = true,
vertical = true,
texture = rain_drop_texture,
playername = player:get_player_name()
})
end
end
local add_wide_range_rain_particle = function(player)
local offset = {
front = 10,
back = 5,
top = 8
}
local random_pos = hw_utils.get_random_pos(player, offset)
if hw_utils.is_outdoor(random_pos) then
minetest.add_particle({
pos = {x=random_pos.x, y=random_pos.y, z=random_pos.z},
velocity = {x=0, y=-10, z=0},
acceleration = {x=0, y=-15, z=0},
expirationtime = 5,
size = 30,
collisiondetection = true,
collision_removal = true,
vertical = true,
texture = rain_drop_texture,
playername = player:get_player_name()
})
end
end
local display_rain_particles = function(player)
if hw_utils.is_underwater(player) then
return
end
add_close_range_rain_particle(player)
local particles_number_per_update = 5
for i=particles_number_per_update, 1,-1 do
add_wide_range_rain_particle(player)
end
end
heavy_rain.render = function(dtime, player)
display_rain_particles(player)
end
heavy_rain.start = function()
manual_trigger_start = true
end
heavy_rain.stop = function()
manual_trigger_end = true
end
heavy_rain.in_area = function(position)
if hw_utils.is_biome_frozen(position) or
hw_utils.is_biome_dry(position) then
return false
end
if position.y > -10 and position.y < 120 then
return true
end
return false
end
happy_weather.register_weather(heavy_rain)