2020-04-16 19:13:14 +02:00
|
|
|
local BLOCK_PREFIX = "regional_weather:snow_cover_"
|
2020-05-29 21:53:33 +02:00
|
|
|
local CHECK_DISTANCE = 3
|
|
|
|
local MAX_AMOUNT = 20
|
2020-04-16 19:13:14 +02:00
|
|
|
|
2020-04-18 08:03:02 +02:00
|
|
|
if not minetest.get_modpath("default")
|
2020-04-18 17:26:01 +02:00
|
|
|
or default.node_sound_snow_defaults == nil
|
2020-04-18 08:03:02 +02:00
|
|
|
or not regional_weather.settings.snow then
|
2020-04-16 19:13:14 +02:00
|
|
|
for i = 1,5 do
|
|
|
|
minetest.register_alias(BLOCK_PREFIX .. i, "air")
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-04-22 00:54:27 +02:00
|
|
|
local destruction_handler = function(pos)
|
|
|
|
pos.y = pos.y - 1
|
|
|
|
if minetest.get_node(pos).name == "default:dirt_with_snow" then
|
|
|
|
minetest.set_node(pos, {name = "default:dirt_with_grass"})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-16 19:13:14 +02:00
|
|
|
for i = 1,5 do
|
|
|
|
local node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {-0.5, -0.5, -0.5, 0.5, 0.2*i - 0.5, 0.5}
|
|
|
|
}
|
|
|
|
|
|
|
|
minetest.register_node(BLOCK_PREFIX .. i, {
|
|
|
|
tiles = { "default_snow.png" },
|
|
|
|
drawtype = "nodebox",
|
|
|
|
buildable_to = i < 3,
|
|
|
|
floodable = true,
|
|
|
|
walkable = i > 3,
|
|
|
|
paramtype = "light",
|
|
|
|
node_box = node_box,
|
|
|
|
groups = {
|
|
|
|
not_in_creative_inventory = 1,
|
|
|
|
crumbly = 3,
|
|
|
|
falling_node = 1,
|
|
|
|
snowy = 1,
|
2020-05-29 21:53:33 +02:00
|
|
|
weather_snow_cover = i
|
2020-04-16 19:13:14 +02:00
|
|
|
},
|
|
|
|
sounds = default.node_sound_snow_defaults(),
|
|
|
|
drop = "default:snow " .. math.ceil(i / 2),
|
|
|
|
on_construct = function(pos)
|
|
|
|
pos.y = pos.y - 1
|
|
|
|
if minetest.get_node(pos).name == "default:dirt_with_grass" then
|
|
|
|
minetest.set_node(pos, {name = "default:dirt_with_snow"})
|
|
|
|
end
|
2020-04-18 17:26:01 +02:00
|
|
|
end,
|
2020-04-22 00:54:27 +02:00
|
|
|
on_destruct = destruction_handler,
|
|
|
|
on_flood = destruction_handler
|
2020-04-16 19:13:14 +02:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
climate_api.register_abm({
|
|
|
|
label = "create snow covers",
|
|
|
|
nodenames = {
|
|
|
|
"group:soil",
|
|
|
|
"group:leaves",
|
|
|
|
"group:stone",
|
|
|
|
"default:snowblock",
|
|
|
|
"group:coverable_by_snow"
|
|
|
|
},
|
|
|
|
neighbors = { "air" },
|
2020-04-25 15:50:45 +02:00
|
|
|
interval = 25,
|
|
|
|
chance = 40,
|
2020-04-24 01:36:58 +02:00
|
|
|
catch_up = false,
|
2020-04-16 19:13:14 +02:00
|
|
|
|
|
|
|
conditions = {
|
|
|
|
min_height = regional_weather.settings.min_height,
|
|
|
|
max_height = regional_weather.settings.max_height,
|
|
|
|
min_humidity = 55,
|
|
|
|
max_heat = 30,
|
2020-05-29 21:53:33 +02:00
|
|
|
daylight = 15,
|
|
|
|
not_biome = {
|
|
|
|
"cold_desert",
|
|
|
|
"cold_desert_ocean",
|
|
|
|
"desert",
|
|
|
|
"desert_ocean",
|
|
|
|
"sandstone_desert",
|
|
|
|
"sandstone_desert_ocean"
|
|
|
|
}
|
2020-04-16 19:13:14 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
pos_override = function(pos)
|
|
|
|
return vector.add(pos, { x = 0, y = 1, z = 0 })
|
|
|
|
end,
|
|
|
|
|
|
|
|
action = function (pos, node, env)
|
2020-05-29 21:53:33 +02:00
|
|
|
-- only override air nodes
|
2020-04-26 18:10:46 +02:00
|
|
|
if node.name ~= "air" then return end
|
2020-05-29 21:53:33 +02:00
|
|
|
-- do not place snow if area is not fully loaded
|
|
|
|
if minetest.find_node_near(pos, CHECK_DISTANCE, "ignore") then return end
|
|
|
|
-- do not place snow if already enpugh snow
|
|
|
|
local pos1 = vector.add(pos, { x = -CHECK_DISTANCE, y = -1, z = -CHECK_DISTANCE })
|
|
|
|
local pos2 = vector.add(pos, { x = CHECK_DISTANCE, y = 1, z = CHECK_DISTANCE })
|
|
|
|
local preplaced = minetest.find_nodes_in_area(pos1, pos2, "group:weather_snow_cover")
|
|
|
|
if preplaced ~= nil and #preplaced >= MAX_AMOUNT then return end
|
|
|
|
minetest.set_node(pos, { name = BLOCK_PREFIX .. "1" })
|
2020-04-16 19:13:14 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
climate_api.register_abm({
|
|
|
|
label = "replace flora with snow covers and stack covers higher",
|
|
|
|
nodenames = {
|
|
|
|
"group:flora",
|
|
|
|
"group:grass",
|
|
|
|
"group:plant",
|
2020-05-29 21:53:33 +02:00
|
|
|
"group:weather_snow_cover"
|
2020-04-16 19:13:14 +02:00
|
|
|
},
|
2020-04-25 15:50:45 +02:00
|
|
|
neighbors = { "air" },
|
|
|
|
interval = 25,
|
|
|
|
chance = 30,
|
2020-04-24 01:36:58 +02:00
|
|
|
catch_up = false,
|
2020-04-16 19:13:14 +02:00
|
|
|
|
|
|
|
conditions = {
|
|
|
|
min_height = regional_weather.settings.min_height,
|
|
|
|
max_height = regional_weather.settings.max_height,
|
|
|
|
min_humidity = 55,
|
|
|
|
max_heat = 30,
|
2020-05-29 21:53:33 +02:00
|
|
|
daylight = 15,
|
|
|
|
not_biome = {
|
|
|
|
"cold_desert",
|
|
|
|
"cold_desert_ocean",
|
|
|
|
"desert",
|
|
|
|
"desert_ocean",
|
|
|
|
"sandstone_desert",
|
|
|
|
"sandstone_desert_ocean"
|
|
|
|
}
|
2020-04-16 19:13:14 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
action = function (pos, node, env)
|
2020-05-29 21:53:33 +02:00
|
|
|
local value = minetest.get_item_group(node.name, "weather_snow_cover") or 0
|
|
|
|
if value == 0 then
|
|
|
|
-- do not override plants unless marked as buildable_to
|
|
|
|
local def = minetest.registered_nodes[node.name]
|
|
|
|
if def == nil or not def.buildable_to then return end
|
|
|
|
-- do not override plants of the frost_resistance group
|
|
|
|
local resistance = minetest.get_item_group(node.name, "frost_resistance") or 0
|
|
|
|
if resistance > 0 then return end
|
|
|
|
end
|
|
|
|
-- do not place snow if area is not fully loaded
|
|
|
|
if minetest.find_node_near(pos, CHECK_DISTANCE, "ignore") then return end
|
|
|
|
-- do not place snow if already enpugh snow
|
|
|
|
local pos1 = vector.add(pos, { x = -CHECK_DISTANCE, y = -1, z = -CHECK_DISTANCE })
|
|
|
|
local pos2 = vector.add(pos, { x = CHECK_DISTANCE, y = 1, z = CHECK_DISTANCE })
|
|
|
|
local preplaced = minetest.find_nodes_in_area(pos1, pos2, "group:weather_snow_cover")
|
|
|
|
if preplaced ~= nil and #preplaced >= MAX_AMOUNT then return end
|
2020-04-16 19:13:14 +02:00
|
|
|
if value < 5 then
|
|
|
|
minetest.set_node(pos, { name = BLOCK_PREFIX .. (value + 1) })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
climate_api.register_abm({
|
|
|
|
label = "melt snow covers",
|
2020-05-29 21:53:33 +02:00
|
|
|
nodenames = { "group:weather_snow_cover" },
|
|
|
|
interval = 15,
|
|
|
|
chance = 4,
|
2020-04-24 01:36:58 +02:00
|
|
|
catch_up = true,
|
2020-04-16 19:13:14 +02:00
|
|
|
|
|
|
|
conditions = {
|
2020-04-18 17:26:01 +02:00
|
|
|
min_heat = 30
|
2020-04-16 19:13:14 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
action = function (pos, node, env)
|
2020-05-29 21:53:33 +02:00
|
|
|
local value = minetest.get_item_group(node.name, "weather_snow_cover")
|
2020-04-16 19:13:14 +02:00
|
|
|
if value == nil then value = 0 end
|
|
|
|
if value > 1 then
|
|
|
|
minetest.set_node(pos, { name = BLOCK_PREFIX .. (value - 1) })
|
|
|
|
elseif regional_weather.settings.puddles then
|
2020-05-29 21:53:33 +02:00
|
|
|
minetest.set_node(pos, regional_weather.get_random_puddle())
|
2020-04-16 19:13:14 +02:00
|
|
|
else
|
|
|
|
minetest.set_node(pos, { name = "air" })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|