mirror of
https://github.com/Splizard/minetest-mod-snow.git
synced 2024-12-29 16:00:16 +01:00
changes in falling.lua
This commit is contained in:
parent
b3cdf93212
commit
990ace49d8
@ -89,34 +89,63 @@ local OCTAVES3 = 3 -- 3
|
|||||||
local PERSISTENCE3 = 0.5 -- 0.5
|
local PERSISTENCE3 = 0.5 -- 0.5
|
||||||
local SCALE3 = 250 -- 250
|
local SCALE3 = 250 -- 250
|
||||||
|
|
||||||
--Get snow at position.
|
-- cache perlin noise tests
|
||||||
local rarity, perlin_scale
|
local perlin_scale, rarity
|
||||||
local function get_snow(pos)
|
local cold_perl_values = {}
|
||||||
--Legacy support.
|
setmetatable(cold_perl_values, {__mode = "kv"})
|
||||||
if weather_legacy ~= "snow" then
|
local function cold_perlin_test(x, y)
|
||||||
return false
|
if not cold_perl_values[y] then
|
||||||
|
cold_perl_values[y] = {}
|
||||||
|
setmetatable(cold_perl_values[y], {__mode = "kv"})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local v = cold_perl_values[y][x]
|
||||||
|
if v ~= nil then
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
|
||||||
if not rarity then
|
if not rarity then
|
||||||
rarity = snow.mapgen.smooth_rarity_min
|
rarity = snow.mapgen.smooth_rarity_min
|
||||||
perlin_scale = snow.mapgen.perlin_scale
|
perlin_scale = snow.mapgen.perlin_scale
|
||||||
end
|
end
|
||||||
local perlin1 = minetest.get_perlin(112,3, 0.5, perlin_scale)
|
|
||||||
if perlin1:get2d({x=pos.x, y=pos.z}) < rarity then
|
v = minetest.get_perlin(112,3, 0.5, perlin_scale):get2d({x=x, y=y}) >= rarity
|
||||||
return false
|
cold_perl_values[y][x] = v
|
||||||
|
return v
|
||||||
end
|
end
|
||||||
|
|
||||||
-- disable falling snow in desert
|
-- disable falling snow in desert
|
||||||
local desert_perlin = minetest.get_perlin(SEEDDIFF3, OCTAVES3, PERSISTENCE3, SCALE3)
|
local desert_perl_values = {}
|
||||||
local noise3 = desert_perlin:get2d({x=pos.x+150,y=pos.z+50}) -- Offsets must match minetest mapgen desert perlin.
|
setmetatable(desert_perl_values, {__mode = "kv"})
|
||||||
if noise3 > 0.35 then -- Smooth transition 0.35 to 0.45.
|
local function is_desert(x, y)
|
||||||
return false
|
if not desert_perl_values[y] then
|
||||||
|
desert_perl_values[y] = {}
|
||||||
|
setmetatable(desert_perl_values[y], {__mode = "kv"})
|
||||||
end
|
end
|
||||||
return true
|
|
||||||
|
local v = desert_perl_values[y][x]
|
||||||
|
if v ~= nil then
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Offsets must match minetest mapgen desert perlin.
|
||||||
|
-- Smooth transition 0.35 to 0.45.
|
||||||
|
v = minetest.get_perlin(SEEDDIFF3, OCTAVES3, PERSISTENCE3, SCALE3):get2d({x=x+150,y=y+50}) <= 0.35
|
||||||
|
desert_perl_values[y][x] = v
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
|
||||||
|
--Get snow at position.
|
||||||
|
local function get_snow(pos)
|
||||||
|
return weather_legacy == "snow" --Legacy support.
|
||||||
|
and cold_perlin_test(pos.x, pos.z)
|
||||||
|
and not is_desert(pos.x, pos.z)
|
||||||
end
|
end
|
||||||
|
|
||||||
local addvectors = vector.add
|
local addvectors = vector.add
|
||||||
|
|
||||||
--Returns a random position between minp and maxp.
|
--Returns a random position between minp and maxp.
|
||||||
|
-- TODO: make a fload random position
|
||||||
local function randpos(minp, maxp)
|
local function randpos(minp, maxp)
|
||||||
local x,z
|
local x,z
|
||||||
if minp.x > maxp.x then
|
if minp.x > maxp.x then
|
||||||
|
Loading…
Reference in New Issue
Block a user