+local minetest,vector,math = minetest,vector,math
local weather_channel = minetest.mod_channel_join("weather_type")
local weather_intake = minetest.mod_channel_join("weather_intake")
local weather_nodes_channel = minetest.mod_channel_join("weather_nodes")
weather_nodes_channel:send_all("")
local weather_max = 2
-
local mod_storage = minetest.get_mod_storage()
weather_type = mod_storage:get_int("weather_type")
local g_node = minetest.get_node
local node_name
local def
-local buildable
+--local buildable
+local drawtype
local walkable
local liquid
local r_nodes = minetest.registered_nodes
local under_air_count
local x, y, z
+local acceptable_drawtypes = {
+ ["normal"] = true,
+ ["glasslike"] = true,
+ ["glasslike_framed"] = true,
+ ["glasslike_framed_optional"] = true,
+ ["allfaces"] = true,
+ ["allfaces_optional"] = true,
+}
--this is debug
--local average = {}
if weather_type == 1 then
for _,player in ipairs(minetest.get_connected_players()) do
--this is debug
- --local t0 = os.clock()
+ --local t0 = minetest.get_us_time()/1000000
pos = round_it(player:get_pos())
min = subber(pos, snow_radius)
max = adder(pos, snow_radius)
area_index = under_air(min, max, all_nodes)
- --local node_search_time = math.ceil((os.clock() - t0) * 1000)
+ --local node_search_time = math.ceil((minetest.get_us_time()/1000000 - t0) * 1000)
spawn_table = {}
if lightlevel >= 14 then
-- daylight is above or near this node, so snow can fall on it
- --make it so buildable to nodes get replaced
node_name = g_node(n_vec(x,y,z)).name
def = r_nodes[node_name]
- buildable = def.buildable_to
+ --buildable = def.buildable_to
+
+ drawtype = acceptable_drawtypes[def.drawtype]
+
walkable = def.walkable
liquid = (def.liquidtype ~= "none")
- if not liquid then
- if buildable then
- if node_name ~= "weather:snow" then
- inserter(bulk_list, n_vec(x,y,z))
- else
- catchup_steps = catchup_steps + 1 -- we've already snowed on this spot
- end
- elseif walkable then
+ if not liquid and walkable and drawtype and node_name ~= "main:ice" then
+ --if buildable then
+ -- if node_name ~= "weather:snow" then
+ -- inserter(bulk_list, n_vec(x,y,z))
+ -- else
+ -- catchup_steps = catchup_steps + 1 -- we've already snowed on this spot
+ -- end
+ --elseif walkable then
if g_node(n_vec(x,y+1,z)).name ~= "weather:snow" then
inserter(bulk_list, n_vec(x,y+1,z))
else
catchup_steps = catchup_steps + 1 -- we've already snowed on this spot
end
- end
+ --end
elseif node_name == "main:water" then
inserter(ice_list, n_vec(x,y,z))
end
--this is debug
--[[
- local chugent = math.ceil((os.clock() - t0) * 1000)
+ local chugent = math.ceil((minetest.get_us_time()/1000000 - t0) * 1000)
print("---------------------------------")
print("find_nodes_in_area_under_air() time: " .. node_search_time .. " ms")
print("New Snow generation time: " .. chugent .. " ms [" .. (chugent - node_search_time) .. " ms]")
--this sets random weather
local initial_run = true
+local new_weather
local function randomize_weather()
if not initial_run then
- weather_type = math.random(0,weather_max)
+ new_weather = math.random(0,weather_max)
+ if new_weather ~= weather_type or not weather_type then
+ weather_type = new_weather
+ else
+ weather_type = 0
+ end
mod_storage:set_int("weather_type", weather_type)
else
initial_run = false
function_send_weather_type()
update_player_sky()
- minetest.after((math.random(5,7)+math.random())*60, function()
+ minetest.after((math.random(15,20)+math.random())*60, function()
randomize_weather()
end)
end
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
--snowballs explode in the nether
- if pos.y <= -10000 and pos.y >= -20000 then
+ if pos.y <= -10033 and pos.y >= -20000 then
self.object:remove()
tnt(pos,4)
else