2 local weather_type = math.random(0,weather_max)
3 local weather_timer = 0
7 --this updates players skys since it cannot be done clientside
8 local update_player_sky = function()
9 for _,player in ipairs(minetest.get_connected_players()) do
10 if weather_type ~= 0 then
17 dawn_horizon = "#808080",
19 fog_sun_tint = "#808080",
22 night_horizon="#808080"
24 player:set_sun({visible=false,sunrise_visible=false})
25 player:set_moon({visible=false})
26 player:set_stars({visible=false})
35 dawn_horizon = "#bac1f0",
39 night_horizon="#4090ff"
42 player:set_sun({visible=true,sunrise_visible=true})
43 player:set_moon({visible=true})
44 player:set_stars({visible=true})
49 --this tells the client mod to update the weather type
50 local function_send_weather_type = function()
51 local channel = minetest.mod_channel_join("weather_type")
52 channel:send_all(tostring(weather_type))
58 minetest.register_on_mods_loaded(function()
59 for name in pairs(minetest.registered_nodes) do
60 if name ~= "air" and name ~= "ignore" then
61 table.insert(all_nodes,name)
66 --this sends the client all nodes that weather can be on top of
68 minetest.register_on_joinplayer(function(player)
69 minetest.after(5, function()
71 local text = minetest.serialize(all_nodes)
72 local channel = minetest.mod_channel_join("weather_nodes")
73 channel:send_all(text)
76 function_send_weather_type()
84 local do_snow = function(dtime)
85 snow_timer = snow_timer + dtime
86 if snow_timer > 3 then
88 for _,player in ipairs(minetest.get_connected_players()) do
90 local pos = player:get_pos()
92 local meta = player:get_meta()
93 local particle_table = {}
95 local area = vector.new(40,40,40)
97 local min = vector.subtract(pos, area)
98 local max = vector.add(pos, area)
101 local area_index = minetest.find_nodes_in_area_under_air(min, max, all_nodes)
104 local spawn_table = {}
105 for _,index in pairs(area_index) do
106 if not spawn_table[index.x] then spawn_table[index.x] = {} end
107 if not spawn_table[index.x][index.z] then
108 spawn_table[index.x][index.z] = index.y
109 elseif spawn_table[index.x][index.z] < index.y then
110 spawn_table[index.x][index.z] = index.y
115 --find the highest y value
117 for x,x_index in pairs(spawn_table) do
118 for z,y in pairs(x_index) do
119 if math.random() > 0.995 then
120 local lightlevel = minetest.get_node_light(vector.new(x,y+1,z), 0.5)
121 if lightlevel >= 14 then
122 --make it so buildable to nodes get replaced
123 local node = minetest.get_node(vector.new(x,y,z)).name
124 local def = minetest.registered_nodes[node]
125 local buildable = def.buildable_to
126 local walkable = def.walkable
127 local liquid = (def.liquidtype ~= "none")
130 if not buildable and minetest.get_node(vector.new(x,y+1,z)).name ~= "weather:snow" and walkable == true then
131 table.insert(bulk_list, vector.new(x,y+1,z))
132 elseif buildable == true and node ~= "weather:snow" then
133 table.insert(bulk_list, vector.new(x,y,z))
141 minetest.bulk_set_node(bulk_list, {name="weather:snow"})
149 --this sets random weather
150 local weather_timer_goal = (math.random(5,7)+math.random())*60
151 minetest.register_globalstep(function(dtime)
152 weather_timer = weather_timer + dtime
153 if weather_timer >= weather_timer_goal then
154 weather_timer_goal = (math.random(5,7)+math.random())*60
156 weather_type = math.random(0,weather_max)
157 function_send_weather_type()
161 if weather_type == 1 then
166 local snowball_throw = function(player)
167 local pos = player:get_pos()
168 pos.y = pos.y + 1.625
169 --let other players hear the noise too
170 minetest.sound_play("woosh",{to_player=player:get_player_name(), pitch = math.random(80,100)/100})
171 minetest.sound_play("woosh",{pos=pos, exclude_player = player:get_player_name(), pitch = math.random(80,100)/100})
172 local snowball = minetest.add_entity(pos,"weather:snowball")
174 local vel = player:get_player_velocity()
175 snowball:set_velocity(vector.add(vel,vector.multiply(player:get_look_dir(),20)))
176 snowball:get_luaentity().thrower = player:get_player_name()
182 minetest.register_node("weather:snow", {
183 description = "Snow",
184 tiles = {"snow_block.png"},
185 groups = {soft = 1, shovel = 1, hand = 1,pathable = 1,wool=1,dirt=1,falling_node=1},
186 sounds = main.woolSound(),
188 drawtype = "nodebox",
193 items = {"weather:snowball"},
196 items = {"weather:snowball"},
199 items = {"weather:snowball"},
202 items = {"weather:snowball"},
206 items = {"weather:snowball"},
214 {-8/16, -8/16, -8/16, 8/16, -6/16, 8/16},
219 minetest.register_craftitem("weather:snowball", {
220 description = "Snowball",
221 inventory_image = "snowball.png",
224 on_place = function(itemstack, placer, pointed_thing)
225 local worked = snowball_throw(placer)
227 itemstack:take_item()
231 on_secondary_use = function(itemstack, user, pointed_thing)
232 local worked = snowball_throw(user)
234 itemstack:take_item()
242 snowball.initial_properties = {
245 collide_with_objects = false,
246 collisionbox = {-0.1, -0.1, -0.1, 0.1, 0.1, 0.1},
248 visual_size = {x = 0.5, y = 0.5},
256 snowball.snowball = true
258 snowball.on_activate = function(self)
259 self.object:set_acceleration(vector.new(0,-9.81,0))
262 --make this as efficient as possible
263 --make it so you can hit one snowball with another
264 snowball.on_step = function(self, dtime)
265 local vel = self.object:get_velocity()
267 local pos = self.object:get_pos()
269 --hit object with the snowball
270 for _,object in ipairs(minetest.get_objects_inside_radius(pos, 1)) do
271 if (object:is_player() and object:get_hp() > 0 and object:get_player_name() ~= self.thrower) or (object:get_luaentity() and object:get_luaentity().mob == true) then
272 object:punch(self.object, 2,
274 full_punch_interval=1.5,
275 damage_groups = {fleshy=0},
282 if (self.oldvel and ((vel.x == 0 and self.oldvel.x ~= 0) or (vel.y == 0 and self.oldvel.y ~= 0) or (vel.z == 0 and self.oldvel.z ~= 0))) or hit == true then
284 minetest.sound_play("wool",{pos=pos, pitch = math.random(80,100)/100})
285 minetest.add_particlespawner({
287 -- Number of particles spawned over the time period `time`.
290 -- Lifespan of spawner in seconds.
291 -- If time is 0 spawner has infinite lifespan and spawns the `amount` on
292 -- a per-second basis.
296 minvel = {x=-2, y=3, z=-2},
297 maxvel = {x=2, y=5, z=2},
298 minacc = {x=0, y=-9.81, z=0},
299 maxacc = {x=0, y=-9.81, z=0},
304 -- The particles' properties are random values between the min and max
306 -- pos, velocity, acceleration, expirationtime, size
308 collisiondetection = true,
310 collision_removal = true,
312 object_collision = false,
314 texture = "snowflake_"..math.random(1,2)..".png",
324 minetest.register_entity("weather:snowball", snowball)