1
0
mirror of https://github.com/t-affeldt/regional_weather.git synced 2024-11-18 00:18:21 +01:00

Disable snow in deserts, improve puddle clustering

This commit is contained in:
Till Affeldt 2020-05-29 21:53:33 +02:00
parent da4062206d
commit 920f80e044
5 changed files with 112 additions and 33 deletions

View File

@ -1,6 +1,7 @@
local BLOCK_PREFIX = "regional_weather:puddle_"
local VARIANT_COUNT = 39
local MIN_DISTANCE = 4
local CHECK_DISTANCE = 4
local MAX_AMOUNT = 3
local GROUND_COVERS = {
"group:soil",
@ -12,18 +13,32 @@ local GROUND_COVERS = {
"default:permafrost_with_stones"
}
-- clean up puddles if disabled
if not regional_weather.settings.puddles then
for i=1,VARIANT_COUNT do
for r=0,270,90 do
minetest.register_alias(BLOCK_PREFIX .. i .. "_" .. r, "air")
-- set all puddle nodes to air
minetest.register_alias("regional_weather:puddle", "air")
for i = 1, VARIANT_COUNT do
for flip = 0, 1 do
local name = BLOCK_PREFIX .. i
if flip == 1 then
name = name .. "_flipped"
end
minetest.register_alias(name, "air")
end
end
-- return air instead of a puddle
function regional_weather.get_random_puddle()
return { name = "air" }
end
-- end puddle execution
return
end
local node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.49, 0.5}
fixed = { -0.5, -0.5, -0.5, 0.5, -0.49, 0.5 }
}
local apply_water_group
@ -31,8 +46,8 @@ if regional_weather.settings.puddles_water then
apply_water_group = 1
end
for i = 1,VARIANT_COUNT do
for flip = 0,1 do
for i = 1, VARIANT_COUNT do
for flip = 0, 1 do
local name = BLOCK_PREFIX .. i
local index = i
if i < 10 then index = "0" .. i end
@ -75,7 +90,7 @@ end
minetest.register_alias("regional_weather:puddle", BLOCK_PREFIX .. "14")
local function get_random_puddle()
function regional_weather.get_random_puddle()
local index = math.random(1, VARIANT_COUNT)
local rotation = math.random(0, 3) * 90
local flip = math.random(0, 1)
@ -109,16 +124,23 @@ climate_api.register_abm({
end,
action = function (pos, node, env)
-- only override air nodes
if minetest.get_node(pos).name ~= "air" then return end
if minetest.find_node_near(pos, MIN_DISTANCE, "group:weather_puddle") then return end
minetest.set_node(pos, get_random_puddle())
-- do not place puddle if area is not fully loaded
if minetest.find_node_near(pos, CHECK_DISTANCE, "ignore") then return end
-- do not place puddle if already enpugh puddles
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_puddle")
if preplaced ~= nil and #preplaced >= MAX_AMOUNT then return end
minetest.set_node(pos, regional_weather.get_random_puddle())
end
})
-- Makes puddles dry up when not raining
climate_api.register_abm({
label = "remove rain puddles",
nodenames = { "group:regional_weather_puddle" },
nodenames = { "group:weather_puddle" },
interval = 10,
chance = 3,
catch_up = true,
@ -126,8 +148,6 @@ climate_api.register_abm({
action = function (pos, node, env)
if env.humidity < 55 then
minetest.remove_node(pos)
elseif env.heat < 30 and regional_weather.settings.snow_cover then
minetest.set_node(pos, {name = "regional_weather:snow_cover_1"})
end
end
})

View File

@ -1,4 +1,6 @@
local BLOCK_PREFIX = "regional_weather:snow_cover_"
local CHECK_DISTANCE = 3
local MAX_AMOUNT = 20
if not minetest.get_modpath("default")
or default.node_sound_snow_defaults == nil
@ -35,7 +37,7 @@ for i = 1,5 do
crumbly = 3,
falling_node = 1,
snowy = 1,
regional_weather_snow_cover = i
weather_snow_cover = i
},
sounds = default.node_sound_snow_defaults(),
drop = "default:snow " .. math.ceil(i / 2),
@ -69,7 +71,15 @@ climate_api.register_abm({
max_height = regional_weather.settings.max_height,
min_humidity = 55,
max_heat = 30,
daylight = 15
daylight = 15,
not_biome = {
"cold_desert",
"cold_desert_ocean",
"desert",
"desert_ocean",
"sandstone_desert",
"sandstone_desert_ocean"
}
},
pos_override = function(pos)
@ -77,13 +87,16 @@ climate_api.register_abm({
end,
action = function (pos, node, env)
-- only override air nodes
if node.name ~= "air" then return end
local base = minetest.get_node(vector.add(pos, {x=0, y=-1, z=0})).name
local is_soil = minetest.get_item_group(base, "soil") or 0
local is_stone = minetest.get_item_group(base, "stone") or 0
if not (is_soil == 0 and is_stone == 0) then
minetest.set_node(pos, { name = BLOCK_PREFIX .. "1" })
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
minetest.set_node(pos, { name = BLOCK_PREFIX .. "1" })
end
})
@ -93,7 +106,7 @@ climate_api.register_abm({
"group:flora",
"group:grass",
"group:plant",
"group:regional_weather_snow_cover"
"group:weather_snow_cover"
},
neighbors = { "air" },
interval = 25,
@ -105,12 +118,34 @@ climate_api.register_abm({
max_height = regional_weather.settings.max_height,
min_humidity = 55,
max_heat = 30,
daylight = 15
daylight = 15,
not_biome = {
"cold_desert",
"cold_desert_ocean",
"desert",
"desert_ocean",
"sandstone_desert",
"sandstone_desert_ocean"
}
},
action = function (pos, node, env)
local value = minetest.get_item_group(node.name, "regional_weather_snow_cover")
if value == nil then value = 0 end
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
if value < 5 then
minetest.set_node(pos, { name = BLOCK_PREFIX .. (value + 1) })
end
@ -119,9 +154,9 @@ climate_api.register_abm({
climate_api.register_abm({
label = "melt snow covers",
nodenames = { "group:regional_weather_snow_cover" },
interval = 25,
chance = 10,
nodenames = { "group:weather_snow_cover" },
interval = 15,
chance = 4,
catch_up = true,
conditions = {
@ -129,12 +164,12 @@ climate_api.register_abm({
},
action = function (pos, node, env)
local value = minetest.get_item_group(node.name, "regional_weather_snow_cover")
local value = minetest.get_item_group(node.name, "weather_snow_cover")
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
minetest.set_node(pos, { name = "regional_weather:puddle" })
minetest.set_node(pos, regional_weather.get_random_puddle())
else
minetest.set_node(pos, { name = "air" })
end

View File

@ -7,7 +7,15 @@ local conditions = {
max_heat = 45,
min_humidity = 65,
min_windspeed = 2.5,
daylight = 15
daylight = 15,
not_biome = {
"cold_desert",
"cold_desert_ocean",
"desert",
"desert_ocean",
"sandstone_desert",
"sandstone_desert_ocean"
}
}
local effects = {}

View File

@ -6,7 +6,15 @@ local conditions = {
max_heat = 35,
min_humidity = 50,
max_humidity = 65,
daylight = 15
daylight = 15,
not_biome = {
"cold_desert",
"cold_desert_ocean",
"desert",
"desert_ocean",
"sandstone_desert",
"sandstone_desert_ocean"
}
}
local effects = {}

View File

@ -5,7 +5,15 @@ local conditions = {
max_height = regional_weather.settings.max_height,
max_heat = 30,
min_humidity = 65,
daylight = 15
daylight = 15,
not_biome = {
"cold_desert",
"cold_desert_ocean",
"desert",
"desert_ocean",
"sandstone_desert",
"sandstone_desert_ocean"
}
}
local effects = {}