From 3f99399f1d127681abd30201bba221bbef3a0770 Mon Sep 17 00:00:00 2001 From: HybridDog Date: Sat, 21 Nov 2015 22:18:03 +0100 Subject: [PATCH] get the bnode only when necessary and don't calculate the globalstep function every step --- init.lua | 5 ++--- src/falling_snow.lua | 38 ++++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/init.lua b/init.lua index a7fb6bd..3758274 100644 --- a/init.lua +++ b/init.lua @@ -88,11 +88,10 @@ function snow.place(pos) return end - local bnode = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}) if node.name == "default:snow" then local level = minetest.get_node_level(pos) if level < 63 then - if minetest.get_item_group(bnode.name, "leafdecay") == 0 + if minetest.get_item_group(minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name, "leafdecay") == 0 and not snow.is_uneven(pos) then minetest.sound_play("default_snow_footstep", {pos=pos}) minetest.add_node_level(pos, 7) @@ -109,7 +108,7 @@ function snow.place(pos) end end elseif node.name ~= "default:ice" - and bnode.name ~= "air" then + and minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name ~= "air" then local data = minetest.registered_nodes[node.name] local drawtype = data.drawtype if drawtype == "normal" diff --git a/src/falling_snow.lua b/src/falling_snow.lua index d61a63f..106652f 100644 --- a/src/falling_snow.lua +++ b/src/falling_snow.lua @@ -31,6 +31,7 @@ near torches and lava. * Add code to prevent snowfall from depositing snow on 'walkable = false' defined nodes. +both are already fixed -- Hybrid Dog --]] @@ -42,8 +43,9 @@ near torches and lava. local weather_legacy +local worldpath = minetest.get_worldpath() local read_weather_legacy = function () - local file = io.open(minetest.get_worldpath().."/weather_v6", "r") + local file = io.open(worldpath.."/weather_v6", "r") if not file then return end local readweather = file:read() file:close() @@ -52,26 +54,30 @@ end --Weather for legacy versions of minetest. local save_weather_legacy = function () - local file = io.open(minetest.get_worldpath().."/weather_v6", "w+") + local file = io.open(worldpath.."/weather_v6", "w+") file:write(weather_legacy) file:close() end - weather_legacy = read_weather_legacy() or "" +weather_legacy = read_weather_legacy() or "" - minetest.register_globalstep(function(dtime) - if weather_legacy == "snow" then - if math.random(1, 10000) == 1 then - weather_legacy = "none" - save_weather_legacy() - end - else - if math.random(1, 50000) == 2 then - weather_legacy = "snow" - save_weather_legacy() - end +local timer = 0 +minetest.register_globalstep(function(dtime) + timer = timer+dtime + if timer < 2 then + return + end + timer = 0 + if weather_legacy == "snow" then + if math.random(1000) == 1 then + weather_legacy = "none" + save_weather_legacy() end - end) + elseif math.random(5000) == 2 then + weather_legacy = "snow" + save_weather_legacy() + end +end) -- copied from meru mod local SEEDDIFF3 = 9130 -- 9130 -- Values should match minetest mapgen desert perlin. @@ -151,7 +157,7 @@ local function snow_fall(pos, player, animate) return end end - for y=pos.y+10,pos.y-15,-1 do + for y=pos.y+9,pos.y-15,-1 do local n = minetest.get_node({x=pos.x,y=y,z=pos.z}).name if n ~= "air" and n ~= "ignore" then ground_y = y