-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathweather.lua
675 lines (532 loc) · 14.8 KB
/
weather.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
--Sets the weather types for each month
local t = 0
minetest.register_globalstep(function(dtime)
local month = mymonths.month_counter
t = t + dtime
if t < 5 then
return
end
t = 0
if minetest.get_modpath("lightning") then
if mymonths.weather == "storm" then
lightning.strike()
end
end
if mymonths.weather ~= "clear" then
if math.random(1, 100) == 1 then
mymonths.weather = "clear"
minetest.chat_send_all("Clear skys!")
end
else
-- January
if tonumber(month) == 1 then
if math.random(1, 2000) == 1 then
mymonths.weather = "snow"
minetest.chat_send_all("It is Snowing")
elseif math.random(1, 5000) == 1 then
mymonths.weather = "snowstorm"
minetest.chat_send_all("It's a Snow Storm")
end
-- February
elseif tonumber(month) == 2 then
if math.random(1, 1000) == 1 then
mymonths.weather = "snow"
minetest.chat_send_all("It is Snowing")
elseif math.random(1, 5000) == 1 then
mymonths.weather = "snowstorm"
minetest.chat_send_all("It's a Snow storm")
elseif math.random(1, 5000) == 1 then
mymonths.weather = "hail"
minetest.chat_send_all("It is Hailing")
end
-- March
elseif tonumber(month) == 3 then
if math.random(1, 1000) == 1 then
mymonths.weather = "rain"
minetest.chat_send_all("It is Raining")
elseif math.random(1, 2500) == 2 then
mymonths.weather = "snow"
minetest.chat_send_all("It is Snowing")
elseif math.random(1, 5000) == 1 then
mymonths.weather = "hail"
minetest.chat_send_all("It is Hailing")
end
-- April
elseif tonumber(month) == 4 then
if math.random(1, 1000) == 1 then
mymonths.weather = "rain"
end
-- May
elseif tonumber(month) == 5 then
if math.random(1, 1500) == 1 then
mymonths.weather = "rain"
minetest.chat_send_all("It is Raining")
elseif math.random(1, 5000) == 1 then
mymonths.weather = "storm"
minetest.chat_send_all("It's a Storm")
end
-- June
elseif tonumber(month) == 6 then
if math.random(1, 5000) == 1 then
mymonths.weather = "rain"
minetest.chat_send_all("It is Raining")
elseif math.random(1, 5000) == 1 then
mymonths.weather = "storm"
minetest.chat_send_all("It's a Storm")
end
-- July
elseif tonumber(month) == 7 then
if math.random(1, 5000) == 1 then
mymonths.weather = "rain"
minetest.chat_send_all("It is Raining")
elseif math.random(1, 5000) == 1 then
mymonths.weather = "storm"
minetest.chat_send_all("It's a Storm")
end
-- August
elseif tonumber(month) == 8 then
if math.random(1, 5000) == 1 then
mymonths.weather = "rain"
minetest.chat_send_all("It is Raining")
elseif math.random(1, 5000) == 1 then
mymonths.weather = "storm"
minetest.chat_send_all("It's a Storm")
end
-- September
elseif tonumber(month) == 9 then
if math.random(1, 1500) == 1 then
mymonths.weather = "rain"
minetest.chat_send_all("It is Raining")
elseif math.random(1, 2500) == 1 then
mymonths.weather = "storm"
minetest.chat_send_all("It's a Storm")
end
-- October
elseif tonumber(month) == 10 then
if math.random(1, 1000) == 1 then
mymonths.weather = "rain"
minetest.chat_send_all("It is Raining")
elseif math.random(1, 2500) == 1 then
mymonths.weather = "storm"
minetest.chat_send_all("It's a Storm")
end
-- November
elseif tonumber(month) == 11 then
if math.random(1, 1000) == 1 then
mymonths.weather = "rain"
minetest.chat_send_all("It is Raining")
elseif math.random(1, 2000) == 2 then
mymonths.weather = "snow"
minetest.chat_send_all("It is Snowing")
end
-- December
elseif tonumber(month) == 12 then
if math.random(1, 2500) == 1 then
mymonths.weather = "rain"
minetest.chat_send_all("It is Raining")
elseif math.random(1, 1000) == 1 then
mymonths.weather = "snow"
minetest.chat_send_all("It is Snowing")
elseif math.random(1, 5000) == 1 then
mymonths.weather = "hail"
minetest.chat_send_all("It is Hailing")
end
end
end
end)
-- Weather vectors and some particles are from jeija's weather mod
addvectors = function (v1, v2)
return {x = v1.x + v2.x, y = v1.y + v2.y, z = v1.z + v2.z}
end
hp_t = 0
minetest.register_globalstep(function(dtime)
hp_t = hp_t + dtime
if hp_t <= 0.2 then
return
end
mymonths.weather2 = mymonths.weather
for _, player in ipairs(minetest.get_connected_players()) do
local ppos = player:getpos()
local hp = player:get_hp()
local name = player:get_player_name()
local nodein = minetest.get_node(ppos)
local nodeu = minetest.get_node({x = ppos.x, y = ppos.y - 1, z = ppos.z})
local biome_jungle = minetest.find_node_near(ppos, 5, "default:jungletree", "default:junglegrass")
local biome_desert = minetest.find_node_near(ppos, 5, "default:desert_sand", "default:desert_stone","default:sand","default:silver_sand")
local biome_snow = minetest.find_node_near(ppos, 5, "default:snow", "default:snowblock", "default:dirt_with_snow", "default:ice")
local biome_frost = minetest.find_node_near(ppos, 5, "default:permafrost_with_stone", "default:permafrost_with_moss", "default:gravel", "default:snow")
local biome_coniferous = minetest.find_node_near(ppos, 5, "default:dirt_with_coniferous_litter")
local biome_dry_land = minetest.find_node_near(ppos, 5, "default:dry_dirt", "default:dry_dirt_with_dry_grass")
local minp = addvectors(ppos, {x = -10, y = 7, z = -10})
local maxp = addvectors(ppos, {x = 10, y = 7, z = 10})
local minps = addvectors(ppos, {x =-15, y = 0, z = -10})
local maxps = addvectors(ppos, {x = 5, y = 3, z = 10})
local minp_deep = addvectors(ppos, {x = -10, y = 3.2, z = -10})
local maxp_deep = addvectors(ppos, {x = 10, y = 2.6, z = 10})
local vel_rain = {x = 0, y = -4, z = 0}
local acc_rain = {x = 0, y = -9.81, z = 0}
local vel_snow = {x = 0, y = -0.4, z = 0}
local acc_snow = {x = 0, y = -0.5, z = 0}
local vel_sand = {x = 1, y = -0.1, z = 0}
local acc_sand = {x = 2, y = 0, z = 0}
-- slows players walk in snow
if nodein.name == "mymonths:snow_cover_1" then
player:set_physics_override({0.95, 1, 1, true, false})
elseif nodein.name == "mymonths:snow_cover_2" then
player:set_physics_override({0.8, 1, 1, true, false})
elseif nodein.name == "mymonths:snow_cover_3" then
player:set_physics_override({0.65, 1, 1, true, false})
elseif nodein.name == "mymonths:snow_cover_4" then
player:set_physics_override({0.5, 1, 1, true, false})
elseif nodein.name == "mymonths:snow_cover_5" then
player:set_physics_override({0.35, 1, 1, true, false})
else
player:set_physics_override({1, 1, 1, true, false})
end
-- check light to make sure player is outside
if minetest.get_node_light({
x = ppos.x,
y = ppos.y + 1,
z = ppos.z}, 0.5) ~= 15 then
return
end
-- checks if there is any weather
if mymonths.weather2 == "none" then
return
end
-- changes weather based on biome
-- Jungle
if biome_jungle ~= nil then
if mymonths.weather == "snow" then
mymonths.weather2 = "rain"
elseif mymonths.weather == "snowstorm"
or mymonths.weather == "hail" then
mymonths.weather2 = "storm"
end
-- Desert
elseif biome_desert ~= nil then
if mymonths.weather == "snow"
or mymonths.weather == "rain" then
mymonths.weather2 = "clear"
elseif mymonths.weather == "snowstorm"
or mymonths.weather == "hail"
or mymonths.weather == "storm" then
mymonths.weather2 = "sandstorm"
end
-- Snow
elseif biome_snow ~= nil then
if mymonths.weather == "rain" then
mymonths.weather2 = "snow"
elseif mymonths.weather == "storm" then
mymonths.weather2 = "snowstorm"
end
-- Permafrost
elseif biome_frost ~= nil then
if mymonths.weather == "snow"
or mymonths.weather == "rain" then
mymonths.weather2 = "clear"
elseif mymonths.weather == "snowstorm"
or mymonths.weather == "hail"
or mymonths.weather == "storm" then
mymonths.weather2 = "snow"
end
-- Coniferous
elseif biome_coniferous ~= nil then
if mymonths.weather == "snow"
or mymonths.weather == "rain" then
mymonths.weather2 = "clear"
elseif mymonths.weather == "snowstorm"
or mymonths.weather == "hail"
or mymonths.weather == "storm" then
mymonths.weather2 = "rain"
end
-- Dry Land
elseif biome_dry_land ~= nil then
if mymonths.weather == "snow"
or mymonths.weather == "rain" then
mymonths.weather2 = "clear"
elseif mymonths.weather == "snowstorm"
or mymonths.weather == "hail"
or mymonths.weather == "storm" then
mymonths.weather2 = "sandstorm"
end
elseif
mymonths.weather2 == mymonths.weather then
end
if mymonths.weather2 == "storm" then
minetest.add_particlespawner({
amount = 40,
time = 0.5,
minpos = minp,
maxpos = maxp,
minvel = vel_rain,
maxvel = vel_rain,
minacc = acc_rain,
maxacc = acc_rain,
minexptime = 0.8,
maxexptime = 0.8,
minsize = 25,
maxsize = 40,
collisiondetection = false,
vertical = true,
texture = "weather_rain_dark.png",
playername = name
})
if minetest.get_node_light({
x = ppos.x,
y = ppos.y + 1,
z = ppos.z}, 0.5) == 15
and mymonths.damage == true then
if hp_t >= 15 then
player:set_hp(hp - 1)
hp_t = 0
end
end
if math.random(1, 200) == 1 then
minetest.sound_play("mymonths_thunder", {
pos = ppos,
max_hear_distance = 10,
gain = 10.0,
})
end
elseif mymonths.weather2 == "rain" then
minetest.add_particlespawner({
amount = 15,
time = 0.5,
minpos = minp,
maxpos = maxp,
minvel = vel_rain,
maxvel = vel_rain,
minacc = acc_rain,
maxacc = acc_rain,
minexptime = 0.6,
maxexptime = 0.8,
minsize = 25,
maxsize = 25,
collisiondetection = false,
vertical = true,
texture = "weather_rain.png",
playername = name
})
elseif mymonths.weather2 == "snow" then
minetest.add_particlespawner({
amount = 4,
time = 0.5,
minpos = minp,
maxpos = maxp,
minvel = vel_snow,
maxvel = vel_snow,
minacc = acc_snow,
maxacc = acc_snow,
minexptime = 4,
maxexptime = 8,
minsize = 15,
maxsize = 25,
collisiondetection = false,
vertical = true,
texture = "weather_snow.png",
playername = name
})
minetest.add_particlespawner({
amount = 4,
time = 0.5,
minpos = minp_deep,
maxpos = maxp_deep,
minvel = vel_snow,
maxvel = vel_snow,
minacc = acc_snow,
maxacc = acc_snow,
minexptime = 4,
maxexptime = 6,
minesize = 15,
maxsize = 25,
collisiondetection = false,
vertical = true,
texture = "weather_snow.png",
playername = name
})
elseif mymonths.weather2 == "snowstorm" then
minetest.add_particlespawner({
amount = 25,
time = 0.5,
minpos = minp,
maxpos = maxp,
minvel = vel_snow,
maxvel = vel_snow,
minacc = acc_snow,
maxacc = acc_snow,
minexptime = 4,
maxexptime = 6,
minesize = 15,
maxsize = 35,
collisiondetection = false,
vertical = true,
texture = "weather_snow.png",
playername = name
})
minetest.add_particlespawner({
amount = 25,
time = 0.5,
minpos = minp_deep,
maxpos = maxp_deep,
minvel = vel_snow,
maxvel = vel_snow,
minacc = acc_snow,
maxacc = acc_snow,
minexptime = 4,
maxexptime = 6,
minesize = 15,
maxsize = 25,
collisiondetection = false,
vertical = true,
texture = "weather_snow.png",
playername = name
})
if minetest.get_node_light({
x = ppos.x,
y = ppos.y + 1,
z =ppos.z}, 0.5) == 15
and mymonths.damage == true then
if hp_t >= 15 then
player:set_hp(hp - 1)
hp_t = 0
end
end
elseif mymonths.weather2 == "sandstorm" then
minetest.add_particlespawner({
amount = 35,
time = 0.5,
minpos = minps,
maxpos = maxps,
minvel = vel_sand,
maxvel = vel_sand,
minacc = acc_sand,
maxacc = acc_sand,
minexptime = 4,
maxexptime = 4,
minesize = 5,
maxsize = 10,
collisiondetection = false,
vertical = true,
texture = "weather_sand.png",
playername = name
})
if minetest.get_node_light({
x = ppos.x,
y = ppos.y + 1,
z = ppos.z}, 0.5) == 15
and mymonths.damage == true then
if hp_t >= 15 then
player:set_hp(hp - 1)
hp_t = 0
end
end
elseif mymonths.weather2 == "hail" then
minetest.add_particlespawner({
amount = 35,
time = 0.5,
minpos = minp,
maxpos = maxp,
minvel = vel_rain,
maxvel = vel_rain,
minacc = acc_rain,
maxacc = acc_rain,
minexptime = 1,
maxexptime = 1,
minesize = 5,
maxsize = 10,
collisiondetection = true,
vertical = true,
texture = "weather_hail.png",
playername = name
})
if minetest.get_node_light({
x = ppos.x,
y = ppos.y + 1,
z = ppos.z}, 0.5) == 15
and mymonths.damage == true then
if hp_t >= 15 then
player:set_hp(hp - 1)
hp_t = 0
end
end
biome_jungle = nil
biome_snow = nil
biome_desert = nil
biome_frost = nil
end
end
end
)
local t2 = 0
minetest.register_globalstep(function(dtime)
for _, player in ipairs(minetest.get_connected_players()) do
local ppos = player:getpos()
t2 = t2 + dtime
if t2 < 1 then
return
end
t2 = 0
if mymonths.weather2 == "rain"
or mymonths.weather2 == "storm" then
minetest.sound_play("mymonths_rain1", {
pos = ppos,
max_hear_distance = 10,
gain = 2.0,
})
end
end
end)
--Puddle node
local puddle_box = {
type = "fixed",
fixed = {
{-0.1875, -0.5, -0.375, 0.125, -0.4875, 0.3125},
{-0.25, -0.5, -0.3125, 0.3125, -0.4925, 0.25},
{-0.3125, -0.5, -0.1875, 0.375, -0.4975, 0.1875},
}
}
minetest.register_node("mymonths:puddle", {
description = "Puddle",
tiles = {"weather_puddle.png"},
drawtype = "nodebox",
paramtype = "light",
pointable = false,
buildable_to = true,
alpha = 50,
node_box = puddle_box,
selection_box = puddle_box,
groups = {not_in_creative_inventory = 1, crumbly = 3, attached_node = 0, falling_node = 1},
drop = "",
})
--Snow Nodes
local snow = {
{"mymonths:snow_cover_1","1", -0.4},
{"mymonths:snow_cover_2","2", -0.2},
{"mymonths:snow_cover_3","3", 0},
{"mymonths:snow_cover_4","4", 0.2},
{"mymonths:snow_cover_5","5", 0.5},
}
for i in ipairs(snow) do
local itm = snow[i][1]
local num = snow[i][2]
local box = snow[i][3]
minetest.register_node(itm, {
description = "Snow",
tiles = {"weather_snow_cover.png"},
drawtype = "nodebox",
paramtype = "light",
buildable_to = true,
walkable = false,
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, box, 0.5}
},
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, box, 0.5}
},
groups = {not_in_creative_inventory = 0, crumbly = 3, attached_node = 0, falling_node = 1, snowy = 1},
drop = "default:snow " .. num,
})
end