From 78a0fe9f8ca4a2ef60cef6d3fb5880de6f8420fe Mon Sep 17 00:00:00 2001 From: Splizard Date: Sat, 26 Apr 2014 10:33:44 +1200 Subject: [PATCH] Fallback to legacy snowfall detection. get_heat and get_humidity have been removed from minetest. --- falling_snow.lua | 43 +++++++++++++++++++++++++++++++++++++++++-- util.lua | 2 +- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/falling_snow.lua b/falling_snow.lua index 3ef28aa..54349ae 100644 --- a/falling_snow.lua +++ b/falling_snow.lua @@ -1,10 +1,49 @@ if snow.enable_snowfall then + + local weather_legacy + + local read_weather_legacy = function () + local file = io.open(minetest.get_worldpath().."/weather_v6", "r") + if not file then return end + local readweather = file:read() + file:close() + return readweather + end + + --Weather for legacy versions of minetest. + local save_weather_legacy = function () + local file = io.open(minetest.get_worldpath().."/weather_v6", "w+") + file:write(weather_legacy) + file:close() + end + + 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 + end + end) --Get snow at position. local get_snow = function(pos) - if minetest.get_heat(pos) <= 0 and minetest.get_humidity(pos) > 65 then - return true + --Legacy support. + if weather_legacy == "snow" then + local perlin1 = minetest.env:get_perlin(112,3, 0.5, 150) + if perlin1:get2d( {x=pos.x, y=pos.z} ) > 0.53 then + return true + else + return false + end else return false end diff --git a/util.lua b/util.lua index 54eeb8b..20fdd2d 100644 --- a/util.lua +++ b/util.lua @@ -94,7 +94,7 @@ end --legacy-- --Detect if we are running the latest minetest. -if minetest.register_on_mapgen_init and minetest.get_heat and minetest.get_humidity then +if minetest.register_on_mapgen_init then snow.legacy = false else snow.legacy = true