Get snowfall into a stable state.

This commit is contained in:
Splizard 2012-12-18 11:14:27 +13:00
parent be207a0044
commit 5c8e2d306e
3 changed files with 40 additions and 23 deletions

View File

@ -1,6 +1,6 @@
--This file contains configuration options for snow mod. --This file contains configuration options for snow mod.
--Enables experimental falling snow. --Enables falling snow.
snow.enable_snowfall = false snow.enable_snowfall = false
--Enables debuging. --Enables debuging.

View File

@ -379,7 +379,7 @@ minetest.register_abm({
if snow.enable_snowfall then if snow.enable_snowfall then
--Snowing (WIP) --Snowing
snow_fall=function (pos) snow_fall=function (pos)
local obj=minetest.env:add_entity(pos, "snow:fall_entity") local obj=minetest.env:add_entity(pos, "snow:fall_entity")
obj:setvelocity({x=0, y=-1, z=0}) obj:setvelocity({x=0, y=-1, z=0})
@ -401,7 +401,12 @@ if snow.enable_snowfall then
local pos = self.object:getpos() local pos = self.object:getpos()
local node = minetest.env:get_node(pos) local node = minetest.env:get_node(pos)
if self.object:getvelocity().y == 0 then if self.lastpos and self.object:getvelocity().y == 0 then
if minetest.env:get_node({x=self.lastpos.x,z=self.lastpos.z,y=self.lastpos.y}).name == "snow:moss" then
minetest.env:add_node({x=self.lastpos.x,z=self.lastpos.z,y=self.lastpos.y},{name="snow:snow",param2=1})
self.object:remove()
return
end
minetest.env:place_node(self.lastpos,{name="snow:snow"}) minetest.env:place_node(self.lastpos,{name="snow:snow"})
self.object:remove() self.object:remove()
end end
@ -411,28 +416,42 @@ if snow.enable_snowfall then
minetest.register_entity("snow:fall_entity", snow_fall_ENTITY) minetest.register_entity("snow:fall_entity", snow_fall_ENTITY)
--Snowing abm --Regenerate Snow
minetest.register_abm({ minetest.register_abm({
nodenames = {"default:dirt_with_grass"}, nodenames = {"default:dirt_with_grass", "default:desert_sand", "snow:moss"},
interval = 30, interval = 500,
chance = 50, chance = 150,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
--Check we are in the right biome
local env = minetest.env local env = minetest.env
local perlin1 = env:get_perlin(112,3, 0.5, 150) local perlin1 = env:get_perlin(112,3, 0.5, 150)
local test = perlin1:get2d({x=pos.x, y=pos.z}) local test = perlin1:get2d({x=pos.x, y=pos.z})
if test > 0.53 then local in_biome = false
if pos.y >= -10 then local smooth = snow.smooth
if not env:find_node_near(pos, 10, "default:desert_sand") then if smooth and (test > 0.73 or (test > 0.43 and math.random(0,29) > (0.73 - test) * 100 )) then
in_biome = true
elseif not smooth and test > 0.53 then
in_biome = true
end
if in_biome then
--Check if block is under cover
local ground_y = nil local ground_y = nil
for y=10,0,-1 do for y=15,0,-1 do
if env:get_node({x=pos.x,y=y,z=pos.z}).name ~= "air" then if env:get_node({x=pos.x,y=y+pos.y,z=pos.z}).name ~= "air" then
ground_y = y ground_y = pos.y+y
break break
end end
end end
if ground_y then if ground_y then
local n = env:get_node({x=pos.x,y=ground_y,z=pos.z}) local n = env:get_node({x=pos.x,y=ground_y,z=pos.z})
if math.random(4) == 1 or (n.name ~= "snow:snow" and n.name ~= "snow:snow_block" and n.name ~= "snow:ice" and n.name ~= "default:water_source") then if (n.name ~= "snow:snow" and n.name ~= "snow:snow_block" and n.name ~= "snow:ice" and n.name ~= "default:water_source" and n.name ~= "default:papyrus") then
local obj = minetest.env:get_objects_inside_radius({x=pos.x,y=ground_y+20,z=pos.z}, 15)
for i,v in pairs(obj) do
e = v:get_luaentity()
if e ~= nil and e.name == "snow:fall_entity" then
return
end
end
snow_fall({x=pos.x,y=ground_y+15,z=pos.z}) snow_fall({x=pos.x,y=ground_y+15,z=pos.z})
if snow.debug then if snow.debug then
print("snowfall at x"..pos.x.." y"..pos.z) print("snowfall at x"..pos.x.." y"..pos.z)
@ -441,7 +460,5 @@ if snow.enable_snowfall then
end end
end end
end end
end
end
}) })
end end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 256 B

After

Width:  |  Height:  |  Size: 350 B