get the bnode only when necessary and don't calculate the globalstep function every step

This commit is contained in:
HybridDog 2015-11-21 22:18:03 +01:00
parent b647842ad4
commit 3f99399f1d
2 changed files with 24 additions and 19 deletions

View File

@ -88,11 +88,10 @@ function snow.place(pos)
return return
end end
local bnode = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
if node.name == "default:snow" then if node.name == "default:snow" then
local level = minetest.get_node_level(pos) local level = minetest.get_node_level(pos)
if level < 63 then 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 and not snow.is_uneven(pos) then
minetest.sound_play("default_snow_footstep", {pos=pos}) minetest.sound_play("default_snow_footstep", {pos=pos})
minetest.add_node_level(pos, 7) minetest.add_node_level(pos, 7)
@ -109,7 +108,7 @@ function snow.place(pos)
end end
end end
elseif node.name ~= "default:ice" 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 data = minetest.registered_nodes[node.name]
local drawtype = data.drawtype local drawtype = data.drawtype
if drawtype == "normal" if drawtype == "normal"

View File

@ -31,6 +31,7 @@ near torches and lava.
* Add code to prevent snowfall from depositing snow on * Add code to prevent snowfall from depositing snow on
'walkable = false' defined nodes. 'walkable = false' defined nodes.
both are already fixed -- Hybrid Dog
--]] --]]
@ -42,8 +43,9 @@ near torches and lava.
local weather_legacy local weather_legacy
local worldpath = minetest.get_worldpath()
local read_weather_legacy = function () 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 if not file then return end
local readweather = file:read() local readweather = file:read()
file:close() file:close()
@ -52,26 +54,30 @@ end
--Weather for legacy versions of minetest. --Weather for legacy versions of minetest.
local save_weather_legacy = function () 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:write(weather_legacy)
file:close() file:close()
end end
weather_legacy = read_weather_legacy() or "" weather_legacy = read_weather_legacy() or ""
minetest.register_globalstep(function(dtime) local timer = 0
if weather_legacy == "snow" then minetest.register_globalstep(function(dtime)
if math.random(1, 10000) == 1 then timer = timer+dtime
weather_legacy = "none" if timer < 2 then
save_weather_legacy() return
end end
else timer = 0
if math.random(1, 50000) == 2 then if weather_legacy == "snow" then
weather_legacy = "snow" if math.random(1000) == 1 then
save_weather_legacy() weather_legacy = "none"
end save_weather_legacy()
end end
end) elseif math.random(5000) == 2 then
weather_legacy = "snow"
save_weather_legacy()
end
end)
-- copied from meru mod -- copied from meru mod
local SEEDDIFF3 = 9130 -- 9130 -- Values should match minetest mapgen desert perlin. local SEEDDIFF3 = 9130 -- 9130 -- Values should match minetest mapgen desert perlin.
@ -151,7 +157,7 @@ local function snow_fall(pos, player, animate)
return return
end end
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 local n = minetest.get_node({x=pos.x,y=y,z=pos.z}).name
if n ~= "air" and n ~= "ignore" then if n ~= "air" and n ~= "ignore" then
ground_y = y ground_y = y