]> git.lizzy.rs Git - crafter_client.git/blob - init.lua
Update README.md
[crafter_client.git] / init.lua
1 print("weather client go")
2 local weather = minetest.mod_channel_join("weather_nodes")
3 local weather_type = minetest.mod_channel_join("weather_type")
4 local server = minetest.mod_channel_join("server")
5
6 local all_nodes = {}
7 local do_effects = false
8 local snow = false
9 local weather_update_timer = 0
10 local id_table = {}
11
12 local spawn_weather = function(player)
13         local pos = player:get_pos()
14         local radius = 10
15         local particle_table = {}
16         
17         local area = vector.new(10,10,10)
18         
19         local min = vector.subtract(pos, area)
20         local max = vector.add(pos, area)
21         
22         
23         local area_index = minetest.find_nodes_in_area_under_air(min, max, all_nodes)
24         
25         local spawn_table = {}
26         --find the highest y value
27         for _,index in pairs(area_index) do
28                 if not spawn_table[index.x] then spawn_table[index.x] = {} end
29                 if not spawn_table[index.x][index.z] then
30                         spawn_table[index.x][index.z] = index.y
31                 elseif spawn_table[index.x][index.z] < index.y then
32                         spawn_table[index.x][index.z] = index.y
33                 end
34         end
35         
36         for x,x_index in pairs(spawn_table) do
37                 for z,y in pairs(x_index) do
38                         if minetest.get_node_or_nil(vector.new(x,y+1,z)) ~= nil then
39                                 --print("got to this spointa")
40                                 local pos = vector.new(x,y+1,z)
41                                 local lightlevel = 14
42                                 --local lightlevel = minetest.get_node_light(pos, 0.5)
43                                 --print("but not here")
44                                 if lightlevel >= 14 then
45                                         minetest.add_particlespawner({
46                                                 amount = 1,
47                                                 time = 0.5,
48                                                 minpos = vector.new(x-0.5,y,z-0.5),
49                                                 maxpos = vector.new(x+0.5,y+20,z+0.5),
50                                                 minvel = {x=-0.2, y=-0.2, z=-0.2},
51                                                 maxvel = {x=0.2, y=-0.5, z=0.2},
52                                                 minacc = {x=0, y=0, z=0},
53                                                 maxacc = {x=0, y=0, z=0},
54                                                 minexptime = 1,
55                                                 maxexptime = 1,
56                                                 minsize = 1,
57                                                 maxsize = 1,
58                                                 collisiondetection = true,
59                                                 collision_removal = true,
60                                                 object_collision = false,
61                                                 texture = "snowflake_"..math.random(1,2)..".png",
62                                                 playername = player:get_name(),
63                                         })
64                                 end
65                         end
66                 end
67         end
68 end
69
70 minetest.register_globalstep(function(dtime)
71         if do_effects then
72                 if snow then
73                         weather_update_timer = weather_update_timer + dtime
74                         if weather_update_timer >= 0.5 then
75                                 weather_update_timer = 0
76                                 local player = minetest.localplayer
77                                 spawn_weather(minetest.localplayer)
78                         end
79                 end
80         end
81 end)
82
83
84
85 minetest.register_on_modchannel_message(function(channel_name, sender, message)
86         if channel_name == "weather_nodes" then
87                 all_nodes = minetest.deserialize(message)
88                 do_effects = true
89         end
90         if channel_name == "weather_type" then
91                 if message == "1" then
92                         print("snowing")
93                         snow = true
94                 else
95                         print("not snowing")
96                         snow = false
97                 end
98         end
99 end)