X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=mods%2Fweather%2Finit.lua;h=c6e63c63f01653b20096dbb0d7c466181085518b;hb=48aa89197636250b3e494e9124c7c5c6e2d63dea;hp=f4a07623939e597f9f98efed630f0c75c4789e40;hpb=91be0626345f42e347bb688fe78be378ca0bee3d;p=Crafter.git diff --git a/mods/weather/init.lua b/mods/weather/init.lua index f4a0762..c6e63c6 100644 --- a/mods/weather/init.lua +++ b/mods/weather/init.lua @@ -1,3 +1,4 @@ +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") @@ -8,7 +9,6 @@ weather_intake:send_all("") weather_nodes_channel:send_all("") local weather_max = 2 - local mod_storage = minetest.get_mod_storage() weather_type = mod_storage:get_int("weather_type") @@ -124,7 +124,8 @@ local get_light = minetest.get_node_light 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 @@ -148,6 +149,14 @@ local relative_z 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 = {} @@ -199,14 +208,14 @@ local function do_snow() 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 = {} @@ -269,27 +278,29 @@ local function do_snow() 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 @@ -310,7 +321,7 @@ local function do_snow() --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]") @@ -347,9 +358,15 @@ end) --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 @@ -358,7 +375,7 @@ local function randomize_weather() 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 @@ -544,7 +561,7 @@ snowball.on_step = function(self, dtime) 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