-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
250 lines (228 loc) · 6.92 KB
/
init.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
--MiniClime v0.2
--W.I.P. version
--fixed variables
local int = 0
local slow_timer = 0
local wind = 0
local weather_force = 10
--lightning mod
lightning.auto = false
lightning.interval_low = 8
lightning.interval_high = 14
local function rain(pos)
minetest.add_particlespawner({
amount = 204,
time = 0.5,
minpos = {x = pos.x-20, y = pos.y+15, z = pos.z-20},
maxpos = {x = pos.x+20, y = pos.y+25, z = pos.z+20},
minvel = {x = 0, y = -6, z = 0},
maxvel = {x = 0, y = -6, z = 0},
minacc = {x = wind, y = -38, z = wind},
maxacc = {x = wind, y = -38, z = wind},
minexptime = 2,
maxexptime = 3.5,
minsize = 5,
maxsize = 8,
texture = "miniclime_rain.png",
vertical = true,
collisiondetection = true,
collision_removal = true,
})
end
local function snow(pos)
minetest.add_particlespawner({
amount = 20,
time = 0.5,
minpos = {x = pos.x-15, y = pos.y+10, z = pos.z-15},
maxpos = {x = pos.x+15, y = pos.y+15, z = pos.z+15},
minvel = {x = wind, y = -1, z = wind},
maxvel = {x = wind, y = -1, z = wind},
minacc = {x = 0, y = -0.1, z = 0},
maxacc = {x = 0, y = -0.5, z = 0},
minexptime = 6,
maxexptime = 6,
minsize = 4,
maxsize = 5,
texture = "miniclime_snow.png",
vertical = true,
collisiondetection = true,
collision_removal = true,
})
end
local function sandstorm(pos)
minetest.add_particlespawner({
amount = 15,
time = 0.5,
minpos = {x = pos.x-15, y = pos.y-5, z = pos.z-15},
maxpos = {x = pos.x+15, y = pos.y-1, z = pos.z+15},
minvel = {x = 0, y = 0, z = 0},
maxvel = {x = 0, y = 1, z = 0},
minacc = {x = wind, y = 1, z = wind},
maxacc = {x = wind, y = 1, z = wind},
minexptime = 4,
maxexptime = 4.5,
minsize = 5,
maxsize = 8,
texture = "miniclime_dust.png",
vertical = false,
collisiondetection = false,
collision_removal = true,
})
end
local function fog(pos)
minetest.add_particlespawner({
amount = 15,
time = 0.5,
minpos = {x = pos.x-10, y = pos.y+15, z = pos.z-10},
maxpos = {x = pos.x+10, y = pos.y+15, z = pos.z+10},
minvel = {x = wind/3, y = -3, z = wind/3},
maxvel = {x = wind/3, y = -2, z = wind/3},
minacc = {x = -0.2, y = -0.2, z = -0.2},
maxacc = {x = 0.2, y = 0.2, z = 0.2},
minexptime = 6.5,
maxexptime = 10.5,
minsize = 47,
maxsize = 63,
texture = "miniclime_fog.png",
vertical = false,
collisiondetection = true,
collision_removal = false,
})
end
local function blizzard(pos)
minetest.add_particlespawner({
amount = 32,
time = 0.3,
minpos = {x = pos.x-25, y = pos.y+1, z = pos.z-25},
maxpos = {x = pos.x+25, y = pos.y+10, z = pos.z+25},
minvel = {x = wind, y = -1, z = wind},
maxvel = {x = wind, y = -1, z = wind},
minacc = {x = wind, y = -0.3, z = wind},
maxacc = {x = wind, y = -1, z = wind},
minexptime = 4,
maxexptime = 4,
minsize = 9,
maxsize = 19,
texture = "miniclime_snow.png",
vertical = true,
collisiondetection = true,
collision_removal = false,
})
end
local function thunder(pos)
minetest.add_particlespawner({
amount = 240,
time = 0.5,
minpos = {x = pos.x-20, y = pos.y+15, z = pos.z-20},
maxpos = {x = pos.x+20, y = pos.y+25, z = pos.z+20},
minvel = {x = 0, y = -10, z = 0},
maxvel = {x = 0, y = -10, z = 0},
minacc = {x = wind, y = -38, z = wind},
maxacc = {x = wind, y = -38, z = wind},
minexptime = 2.5,
maxexptime = 3.5,
minsize = 8,
maxsize = 10,
texture = "miniclime_rain.png",
vertical = true,
collisiondetection = true,
collision_removal = true,
})
lightning.auto = true
end
--active weather
minetest.register_globalstep(function(time_of_day)
--variable change
int = int+0.1
slow_timer = int
wind = wind+math.random(-0.1,0.1)
if wind > 1 then
wind = wind-0.2
end
if wind < -1 then
wind = wind+0.2
end
if slow_timer == 300 then
slow_timer = 0
weather_force = math.random(0,100)
if weather_force > 100 then
weather_force = 100
elseif weather_force < 0 then
weather_force = 0
end
end
--weather change
if int > 3 then
if weather_force > 63 then
int = 0
for _, player in ipairs(minetest.get_connected_players()) do
local pos = player:getpos()
local nodepos = {x = pos.x+math.random(-10,10), y=pos.y, z = pos.z+math.random(-10,10)}
if nodepos.y > 0 then
local time_of_day = minetest.get_timeofday()*24000
--day weather =============================================================================================================
if time_of_day < 18000 and time_of_day > 6000 then
lightning.auto = false
for i=0,60,1 do
local node = minetest.get_node({x=nodepos.x, y=nodepos.y-i, z=nodepos.z})
--rain on grass and rainforest-litter
if node.name == "default:dirt_with_rainforest_litter" or node.name == "default:dirt_with_grass" then
rain(pos)
minetest.sound_play("rain_drop", {pos = pos, gain = 0.2, max_hear_distance = 10})
end
--snow on snow (obliviously)
if node.name == "default:snow" or node.name == "default:dirt_with_snow" or node.name == "default:snowblock" then
snow(pos)
end
--sandstorm on desert sand
if node.name == "default:desert_sand" or node.name == "default:dirt_with_dry_grass" then
sandstorm(pos)
minetest.sound_play("wind", {pos = pos, gain = 0.1, max_hear_distance = 10})
end
end
--night weather =============================================================================================================
else
for i=0,60,1 do
local node = minetest.get_node({x=nodepos.x, y=nodepos.y-i, z=nodepos.z})
--fog on grass
if pos.y < 32 or pos.y < 312 then
if node.name == "default:air" or node.name == "default:water_source" then
fog(pos)
minetest.sound_play("light_rain_drop", {pos = pos, gain = 0.2, max_hear_distance = 10})
end
end
--blizzard
if node.name == "default:snow" or node.name == "default:dirt_with_snow" or node.name == "default:snowblock" then
blizzard(pos)
minetest.sound_play("wind", {pos = pos, gain = 0.1, max_hear_distance = 10})
end
--thunderstorm on grass and rainforest-litter
if node.name == "default:dirt_with_dry_grass" or node.name == "default:dirt_with_grass" then
thunder(pos)
minetest.sound_play("heavy_rain_drop", {pos = pos, gain = 0.2, max_hear_distance = 10})
minetest.sound_play("wind", {pos = pos, gain = 0.1, max_hear_distance = 10})
end
end
end
end
end
else -- stop lightning
lightning.auto = false
end
end
end)
minetest.register_chatcommand("roll_weather", {
params = "<value>",
privs = {settime=true},
description = "Allow parameting weather.",
func = function(name, param)
local value = tonumber(param)
if value == nil then
weather_force = math.random(0, 100)
minetest.debug("[miniclime] weather_force set to " .. weather_force)
else
weather_force = value
minetest.debug("[miniclime] weather_force set to " .. weather_force)
end
end,
})