mirror of
https://github.com/Splizard/minetest-mod-snow.git
synced 2024-12-28 23:40:17 +01:00
Get snowfall into a stable state.
This commit is contained in:
parent
be207a0044
commit
5c8e2d306e
@ -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.
|
||||||
|
61
init.lua
61
init.lua
@ -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,33 +416,45 @@ 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
|
||||||
local ground_y = nil
|
in_biome = true
|
||||||
for y=10,0,-1 do
|
elseif not smooth and test > 0.53 then
|
||||||
if env:get_node({x=pos.x,y=y,z=pos.z}).name ~= "air" then
|
in_biome = true
|
||||||
ground_y = y
|
end
|
||||||
break
|
if in_biome then
|
||||||
|
--Check if block is under cover
|
||||||
|
local ground_y = nil
|
||||||
|
for y=15,0,-1 do
|
||||||
|
if env:get_node({x=pos.x,y=y+pos.y,z=pos.z}).name ~= "air" then
|
||||||
|
ground_y = pos.y+y
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if ground_y then
|
||||||
|
local n = env:get_node({x=pos.x,y=ground_y,z=pos.z})
|
||||||
|
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
|
||||||
end
|
end
|
||||||
if ground_y then
|
snow_fall({x=pos.x,y=ground_y+15,z=pos.z})
|
||||||
local n = env:get_node({x=pos.x,y=ground_y,z=pos.z})
|
if snow.debug then
|
||||||
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
|
print("snowfall at x"..pos.x.." y"..pos.z)
|
||||||
snow_fall({x=pos.x,y=ground_y+15,z=pos.z})
|
|
||||||
if snow.debug then
|
|
||||||
print("snowfall at x"..pos.x.." y"..pos.z)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 256 B After Width: | Height: | Size: 350 B |
Loading…
Reference in New Issue
Block a user