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
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"

View File

@ -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