Rain and snow where appropriate(biome, heat, alt)

This commit is contained in:
cora 2022-07-30 03:57:40 +02:00
parent a9e139f27d
commit eb5378afec
3 changed files with 72 additions and 12 deletions

View file

@ -41,6 +41,13 @@ local psdef= {
local textures = {"weather_pack_rain_raindrop_1.png", "weather_pack_rain_raindrop_2.png"} local textures = {"weather_pack_rain_raindrop_1.png", "weather_pack_rain_raindrop_2.png"}
function mcl_weather.has_rain(pos)
if mgname == "singlenode" or mgname == "v6" then return true end
local bd = minetest.get_biome_data(pos)
if bd.heat > 90 then return false end
return true
end
function mcl_weather.rain.sound_handler(player) function mcl_weather.rain.sound_handler(player)
return minetest.sound_play("weather_rain", { return minetest.sound_play("weather_rain", {
to_player = player:get_player_name(), to_player = player:get_player_name(),
@ -166,13 +173,17 @@ function mcl_weather.rain.make_weather()
for _, player in pairs(get_connected_players()) do for _, player in pairs(get_connected_players()) do
local pos=player:get_pos() local pos=player:get_pos()
if mcl_weather.is_underwater(player) or not mcl_worlds.has_weather(pos) then if mcl_weather.is_underwater(player) or not mcl_worlds.has_weather(pos) or not mcl_weather.has_rain(pos) then
mcl_weather.rain.remove_sound(player) mcl_weather.rain.remove_sound(player)
mcl_weather.remove_spawners_player(player) mcl_weather.remove_spawners_player(player)
else else
mcl_weather.rain.add_player(player) if mcl_weather.has_snow(pos) then
mcl_weather.rain.add_rain_particles(player) mcl_weather.snow.add_player(player)
mcl_weather.rain.update_sound(player) else
mcl_weather.rain.add_player(player)
mcl_weather.rain.add_rain_particles(player)
mcl_weather.rain.update_sound(player)
end
end end
end end
end end

View file

@ -4,6 +4,42 @@ mcl_weather.snow = {}
local PARTICLES_COUNT_SNOW = tonumber(minetest.settings:get("mcl_weather_snow_particles")) or 100 local PARTICLES_COUNT_SNOW = tonumber(minetest.settings:get("mcl_weather_snow_particles")) or 100
mcl_weather.snow.init_done = false mcl_weather.snow.init_done = false
local mgname = minetest.get_mapgen_setting("mg_name")
local snow_biomes = {
"ColdTaiga_underground",
"IcePlains_underground",
"IcePlainsSpikes_underground",
"MegaTaiga_underground",
"Taiga_underground",
"IcePlains_deep_ocean",
"MegaSpruceTaiga_deep_ocean",
"IcePlainsSpikes_ocean",
"StoneBeach_ocean",
"ColdTaiga_deep_ocean",
"MegaTaiga_ocean",
"StoneBeach_deep_ocean",
"IcePlainsSpikes_deep_ocean",
"ColdTaiga_ocean",
"MegaTaiga_deep_ocean",
"MegaSpruceTaiga_ocean",
"ExtremeHills+_ocean",
"IcePlains_ocean",
"Taiga_ocean",
"Taiga_deep_ocean",
"StoneBeach",
"ColdTaiga_beach_water",
"Taiga_beach",
"ColdTaiga_beach",
"Taiga",
"ExtremeHills+_snowtop",
"MegaSpruceTaiga",
"MegaTaiga",
"ExtremeHills+",
"ColdTaiga",
"IcePlainsSpikes",
"IcePlains",
}
local psdef= { local psdef= {
amount = PARTICLES_COUNT_SNOW, amount = PARTICLES_COUNT_SNOW,
@ -25,6 +61,18 @@ local psdef= {
glow = 1 glow = 1
} }
function mcl_weather.has_snow(pos)
if mgname == "singlenode" or mgname == "v6" then return true end
local bd = minetest.get_biome_data(pos)
local bn = minetest.get_biome_name(bd.biome)
local minheight = -64
if bn:find("Taiga") then minheight = 100 end
if bn:find("MegaSpruce") then minheight = 140 end
if pos.y < minheight then return false end
if table.indexof(snow_biomes,bn) ~= -1 then return true end
return false
end
function mcl_weather.snow.set_sky_box() function mcl_weather.snow.set_sky_box()
mcl_weather.skycolor.add_layer( mcl_weather.skycolor.add_layer(
"weather-pack-snow-sky", "weather-pack-snow-sky",
@ -46,9 +94,11 @@ function mcl_weather.snow.clear()
mcl_weather.remove_all_spawners() mcl_weather.remove_all_spawners()
end end
-- Simple random texture getter function mcl_weather.snow.add_player(player)
function mcl_weather.snow.get_texture() for i=1,2 do
return "weather_pack_snow_snowflake"..math.random(1,2)..".png" psdef.texture="weather_pack_snow_snowflake"..i..".png"
mcl_weather.add_spawner_player(player,"snow"..i,psdef)
end
end end
local timer = 0 local timer = 0
@ -70,13 +120,10 @@ minetest.register_globalstep(function(dtime)
end end
for _, player in pairs(get_connected_players()) do for _, player in pairs(get_connected_players()) do
if mcl_weather.is_underwater(player) or not mcl_worlds.has_weather(player:get_pos()) then if mcl_weather.is_underwater(player) or not mcl_worlds.has_weather(player:get_pos()) or not mcl_weather.has_snow(player:get_pos()) then
mcl_weather.remove_spawners_player(player) mcl_weather.remove_spawners_player(player)
else else
for i=1,2 do mcl_weather.snow.add_player(player)
psdef.texture="weather_pack_snow_snowflake"..i..".png"
mcl_weather.add_spawner_player(player,"snow"..i,psdef)
end
end end
end end
end) end)

View file

@ -54,6 +54,8 @@ function mcl_weather.add_spawner_player(pl,id,ps)
particlespawners[name] = {} particlespawners[name] = {}
end end
if not particlespawners[name][id] then if not particlespawners[name][id] then
mcl_weather.remove_spawners_player(pl)
particlespawners[name] = {}
ps.playername =name ps.playername =name
ps.attached = pl ps.attached = pl
particlespawners[name][id]=minetest.add_particlespawner(ps) particlespawners[name][id]=minetest.add_particlespawner(ps)