mirror of
				https://github.com/t-affeldt/regional_weather.git
				synced 2025-11-04 01:55:26 +01:00 
			
		
		
		
	Update to new particle API, improve night visibility, move damage effect, improve cloud height calculation
This commit is contained in:
		
							
								
								
									
										10
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								README.md
									
									
									
									
									
								
							@@ -25,6 +25,7 @@ The following mods are recommended to be installed alongside Regional Weather:
 | 
			
		||||
- [Lightning](https://github.com/minetest-mods/lightning): Adds to heavy rain by enabling additional lightning effects
 | 
			
		||||
- [Farming](https://github.com/minetest/minetest_game/tree/master/mods/farming) (as part of MTG) or [Farming Redo](https://forum.minetest.net/viewtopic.php?t=9019): Add farmland and crops to grow food. Farmland wil turn wet during rain effects.
 | 
			
		||||
- [Fire](https://github.com/minetest/minetest_game/tree/master/mods/fire) (as part of MTG): Adds fires that can be caused by lightning strikes and other effects and will be extinguished during rain effects.
 | 
			
		||||
- [Pedology](https://forum.minetest.net/viewtopic.php?f=11&t=9429) Adds a lot of nodes with dynamic wetness and dryness states.
 | 
			
		||||
- [Ambience](https://notabug.org/TenPlus1/ambience): Plays some nice ambient sound effects based on where you are.
 | 
			
		||||
 | 
			
		||||
For easier installation, you can get a lot of these mods as part of my [Climate Modpack](https://github.com/t-affeldt/climate).
 | 
			
		||||
@@ -35,8 +36,6 @@ Go to ``Settings → All Settings → Mods → regional_weather`` to change them
 | 
			
		||||
Also check out the options inside the ``climate_api`` section for additional configuration options, including performance tweaks and feature switches.
 | 
			
		||||
 | 
			
		||||
### Features
 | 
			
		||||
- ``Cause player damage`` (default true):
 | 
			
		||||
	If set to true, sand storms and hail will damage affected players over time.
 | 
			
		||||
- ``Place snow layers`` (default true):
 | 
			
		||||
	If set to true, snow layers will stack up during snowy weather.
 | 
			
		||||
- ``Freeze river water`` (default true):
 | 
			
		||||
@@ -50,6 +49,9 @@ Also check out the options inside the ``climate_api`` section for additional con
 | 
			
		||||
- ``Extinguish fire`` (bool true):
 | 
			
		||||
	If set to true, fires will be extinguished during rain showers.
 | 
			
		||||
	Requires *fire* mod.
 | 
			
		||||
- ``Wetten pedology nodes`` (default true):
 | 
			
		||||
	If set to true, rain will wetten or dry nodes from pedology mod.
 | 
			
		||||
	Requires *pedology* mod.
 | 
			
		||||
 | 
			
		||||
### World Configuration
 | 
			
		||||
- ``Maximum height of weather effects`` (default 120):
 | 
			
		||||
@@ -58,6 +60,10 @@ Also check out the options inside the ``climate_api`` section for additional con
 | 
			
		||||
- ``Minimum height of weather effects`` (default -50):
 | 
			
		||||
	No visual effects will be applied below this height.
 | 
			
		||||
	This will prevent unwanted visuals within large underground caves.
 | 
			
		||||
- ``Cloud height`` (default 120)
 | 
			
		||||
	Average height of cloud bases
 | 
			
		||||
- ``Cloud height variation`` (default 40)
 | 
			
		||||
	Maxmial variation of cloud height from base value
 | 
			
		||||
 | 
			
		||||
## License information
 | 
			
		||||
### Source Code
 | 
			
		||||
 
 | 
			
		||||
@@ -1,30 +0,0 @@
 | 
			
		||||
--[[
 | 
			
		||||
# Player Damage Effect
 | 
			
		||||
Use this effect to damage a player during dangerous weather events.
 | 
			
		||||
Expects a table as the parameter containing the following values:
 | 
			
		||||
- ``value <number>``: The amount of damage to be applied per successful roll per cycle
 | 
			
		||||
- ``chance <number>``: Defines a 1/x chance for the player to get damaged. Higher values result in less frequent damage.
 | 
			
		||||
]]
 | 
			
		||||
 | 
			
		||||
if not minetest.is_yes(minetest.settings:get_bool("enable_damage"))
 | 
			
		||||
or not regional_weather.settings.damage then return end
 | 
			
		||||
 | 
			
		||||
local EFFECT_NAME = "regional_weather:damage"
 | 
			
		||||
 | 
			
		||||
local rng = PcgRandom(7819792)
 | 
			
		||||
 | 
			
		||||
local function handle_effect(player_data)
 | 
			
		||||
	for playername, data in pairs(player_data) do
 | 
			
		||||
		local player = minetest.get_player_by_name(playername)
 | 
			
		||||
		local hp = player:get_hp()
 | 
			
		||||
		for weather, dmg in pairs(data) do
 | 
			
		||||
			if rng:next(1, dmg.chance) == 1 then
 | 
			
		||||
				hp = hp - dmg.value
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
		player:set_hp(hp, "weather damage")
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
climate_api.register_effect(EFFECT_NAME, handle_effect, "tick")
 | 
			
		||||
climate_api.set_effect_cycle(EFFECT_NAME, climate_api.MEDIUM_CYCLE)
 | 
			
		||||
@@ -3,17 +3,33 @@ local CLOUD_SPEED = 1.8
 | 
			
		||||
 | 
			
		||||
local conditions = {}
 | 
			
		||||
 | 
			
		||||
-- see https://en.wikipedia.org/wiki/Cloud_base
 | 
			
		||||
local function calc_cloud_height(heat, humidity, dewpoint)
 | 
			
		||||
	local base = regional_weather.settings.cloud_height
 | 
			
		||||
	-- much lower scale like 20 instead of 1000 fitting for Minetest
 | 
			
		||||
	local scale = regional_weather.settings.cloud_scale
 | 
			
		||||
	local spread = heat - dewpoint
 | 
			
		||||
	local variation = spread / 4.4 * scale * 0.3
 | 
			
		||||
	return base + climate_api.utility.rangelim(variation, -scale, scale)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
local function generate_effects(params)
 | 
			
		||||
	local override = {}
 | 
			
		||||
	local wind = climate_api.environment.get_wind()
 | 
			
		||||
 | 
			
		||||
	local skybox = {priority = 10}
 | 
			
		||||
	skybox.cloud_data = {
 | 
			
		||||
		density = climate_api.utility.rangelim(params.humidity / 100, 0.25, 0.75),
 | 
			
		||||
		density = climate_api.utility.rangelim(params.humidity / 100, 0.15, 0.65),
 | 
			
		||||
		speed = vector.multiply(wind, CLOUD_SPEED),
 | 
			
		||||
		thickness = climate_api.utility.rangelim(params.base_humidity * 0.2, 1, 18)
 | 
			
		||||
		thickness = climate_api.utility.rangelim(params.base_humidity * 0.2, 1, 18),
 | 
			
		||||
		height = calc_cloud_height(params.heat, params.humidity, params.dewpoint),
 | 
			
		||||
		ambient = "#0f0f1050"
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if params.height > -100 and params.humidity > 40 then
 | 
			
		||||
		skybox.cloud_data.color  = "#b2a4a4b0"
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	if params.height > -100 and params.humidity > 65 then
 | 
			
		||||
		skybox.sky_data = {
 | 
			
		||||
			type = "regular",
 | 
			
		||||
@@ -27,6 +43,8 @@ local function generate_effects(params)
 | 
			
		||||
				night_horizon = "#315d9b"
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		skybox.cloud_data.color = "#828e97b5"
 | 
			
		||||
		skybox.cloud_data.ambient = "#20212250"
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	override["climate_api:skybox"] = skybox
 | 
			
		||||
 
 | 
			
		||||
@@ -11,9 +11,14 @@ local conditions = {
 | 
			
		||||
 | 
			
		||||
local effects = {}
 | 
			
		||||
 | 
			
		||||
effects["regional_weather:damage"] = {
 | 
			
		||||
effects["climate_api:damage"] = {
 | 
			
		||||
	chance = 15,
 | 
			
		||||
	value = 3
 | 
			
		||||
	value = 3,
 | 
			
		||||
	check = {
 | 
			
		||||
		type = "raycast",
 | 
			
		||||
		height = 7,
 | 
			
		||||
		velocity = 20
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
effects["climate_api:sound"] = {
 | 
			
		||||
@@ -21,18 +26,19 @@ effects["climate_api:sound"] = {
 | 
			
		||||
	gain = 1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
effects["climate_api:particles"] = {
 | 
			
		||||
	min_pos = {x=-9, y=7, z=-9},
 | 
			
		||||
	max_pos = {x= 9, y=7, z= 9},
 | 
			
		||||
	falling_speed=20,
 | 
			
		||||
	amount=6,
 | 
			
		||||
	exptime=0.7,
 | 
			
		||||
	size=1,
 | 
			
		||||
	textures = {}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
for i = 1,5,1 do
 | 
			
		||||
	effects["climate_api:particles"].textures[i] = "weather_hail" .. i .. ".png"
 | 
			
		||||
local textures = {}
 | 
			
		||||
for i = 1,5 do
 | 
			
		||||
	textures[i] = "weather_hail" .. i .. ".png"
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
effects["climate_api:particles"] = {
 | 
			
		||||
	boxsize = { x = 18, y = 0, z = 18},
 | 
			
		||||
	v_offset = 7,
 | 
			
		||||
	velocity = 20,
 | 
			
		||||
	amount = 6,
 | 
			
		||||
	expirationtime = 0.7,
 | 
			
		||||
	texture = textures,
 | 
			
		||||
	glow = 5
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
climate_api.register_weather(name, conditions, effects)
 | 
			
		||||
 
 | 
			
		||||
@@ -34,14 +34,15 @@ local conditions = {
 | 
			
		||||
local effects = {}
 | 
			
		||||
 | 
			
		||||
effects["climate_api:particles"] = {
 | 
			
		||||
	min_pos = {x=-12, y=-4, z=-12},
 | 
			
		||||
	max_pos = {x= 12, y= 1, z= 12},
 | 
			
		||||
	falling_speed = -0.1,
 | 
			
		||||
	acceleration = {x=0,y=-0.03,z=0},
 | 
			
		||||
	amount = 1,
 | 
			
		||||
	exptime = 5,
 | 
			
		||||
	boxsize = { x = 24, y = 0, z = 24 },
 | 
			
		||||
	vbox = 5,
 | 
			
		||||
	v_offset = -1,
 | 
			
		||||
	velocity = -0.1,
 | 
			
		||||
	acceleration = -0.03,
 | 
			
		||||
	expirationtime = 5,
 | 
			
		||||
	size = 0.8,
 | 
			
		||||
	texture = "weather_pollen.png"
 | 
			
		||||
	texture = "weather_pollen.png",
 | 
			
		||||
	glow = 2
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
climate_api.register_weather(name, conditions, effects)
 | 
			
		||||
 
 | 
			
		||||
@@ -17,14 +17,15 @@ effects["climate_api:sound"] = {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
effects["climate_api:particles"] = {
 | 
			
		||||
	min_pos = {x=-9, y=8, z=-9},
 | 
			
		||||
	max_pos = {x= 9, y=6, z= 9},
 | 
			
		||||
	exptime = 1.1,
 | 
			
		||||
	boxsize = { x = 18, y = 2, z = 18 },
 | 
			
		||||
	v_offset = 6,
 | 
			
		||||
	expirationtime = 1.6,
 | 
			
		||||
	size = 2,
 | 
			
		||||
	amount = 15,
 | 
			
		||||
	falling_speed = 6,
 | 
			
		||||
	acceleration={x=0, y=-0.05, z=0},
 | 
			
		||||
	texture = "weather_raindrop.png"
 | 
			
		||||
	velocity = 6,
 | 
			
		||||
	acceleration = 0.05,
 | 
			
		||||
	texture = "weather_raindrop.png",
 | 
			
		||||
	glow = 5
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
climate_api.register_weather(name, conditions, effects)
 | 
			
		||||
 
 | 
			
		||||
@@ -10,24 +10,32 @@ local conditions = {
 | 
			
		||||
 | 
			
		||||
local effects = {}
 | 
			
		||||
 | 
			
		||||
effects["climate_api:skybox"] = {
 | 
			
		||||
	cloud_data = {
 | 
			
		||||
		color = "#5e676eb5"
 | 
			
		||||
	},
 | 
			
		||||
	priority = 11
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
effects["climate_api:sound"] = {
 | 
			
		||||
	name = "weather_rain_heavy",
 | 
			
		||||
	gain = 1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
effects["climate_api:particles"] = {
 | 
			
		||||
	min_pos = {x=-9, y=7, z=-9},
 | 
			
		||||
	max_pos = {x= 9, y=7, z= 9},
 | 
			
		||||
	falling_speed=7,
 | 
			
		||||
	amount=17,
 | 
			
		||||
	exptime=0.8,
 | 
			
		||||
	min_size=25,
 | 
			
		||||
	max_size=35,
 | 
			
		||||
	textures={
 | 
			
		||||
	boxsize = { x = 18, y = 0, z = 18 },
 | 
			
		||||
	v_offset = 7,
 | 
			
		||||
	velocity = 7,
 | 
			
		||||
	amount = 17,
 | 
			
		||||
	expirationtime = 1.2,
 | 
			
		||||
	minsize = 25,
 | 
			
		||||
	maxsize = 35,
 | 
			
		||||
	texture = {
 | 
			
		||||
		"weather_rain.png",
 | 
			
		||||
		"weather_rain.png",
 | 
			
		||||
		"weather_rain_medium.png"
 | 
			
		||||
	}
 | 
			
		||||
	},
 | 
			
		||||
	glow = 5
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
climate_api.register_weather(name, conditions, effects)
 | 
			
		||||
 
 | 
			
		||||
@@ -24,22 +24,28 @@ effects["climate_api:hud_overlay"] = {
 | 
			
		||||
	color_correction = true
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
effects["regional_weather:damage"] = {
 | 
			
		||||
effects["climate_api:damage"] = {
 | 
			
		||||
	chance = 3,
 | 
			
		||||
	value = 1
 | 
			
		||||
	value = 1,
 | 
			
		||||
	check = {
 | 
			
		||||
		type = "raycast",
 | 
			
		||||
		height = 0,
 | 
			
		||||
		velocity = 0.3
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
effects["climate_api:particles"] = {
 | 
			
		||||
	min_pos = {x=-5, y=-4, z=-5},
 | 
			
		||||
	max_pos = {x= 5, y= 4.5, z= 5},
 | 
			
		||||
	falling_speed=1.2,
 | 
			
		||||
	acceleration={x=0,y=0.8,z=0},
 | 
			
		||||
	amount=40,
 | 
			
		||||
	exptime=1.8,
 | 
			
		||||
	size=20,
 | 
			
		||||
	textures={
 | 
			
		||||
	boxsize = { x = 8, y = 4.5, z = 8 },
 | 
			
		||||
	velocity = 0.6,
 | 
			
		||||
	acceleration = -0.2,
 | 
			
		||||
	amount = 12,
 | 
			
		||||
	expirationtime = 0.7,
 | 
			
		||||
	size = 25,
 | 
			
		||||
	texture = {
 | 
			
		||||
		"weather_sandstorm.png",
 | 
			
		||||
		"weather_sandstorm.png^[transformR180"
 | 
			
		||||
		"weather_sandstorm.png^[transformFY",
 | 
			
		||||
		"weather_sandstorm.png^[transformR180",
 | 
			
		||||
		"weather_sandstorm.png^[transformFYR180"
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -11,19 +11,20 @@ local conditions = {
 | 
			
		||||
 | 
			
		||||
local effects = {}
 | 
			
		||||
 | 
			
		||||
effects["climate_api:particles"] = {
 | 
			
		||||
	min_pos = {x=-12, y=2, z=-12},
 | 
			
		||||
	max_pos = {x= 12, y=8, z= 12},
 | 
			
		||||
	amount = 4,
 | 
			
		||||
	exptime = 7,
 | 
			
		||||
	size = 1,
 | 
			
		||||
	falling_speed = 0.85,
 | 
			
		||||
	acceleration = {x=0, y=0.06, z=0},
 | 
			
		||||
	textures = {}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
local textures = {}
 | 
			
		||||
for i = 1,12,1 do
 | 
			
		||||
	effects["climate_api:particles"].textures[i] = "weather_snowflake" .. i .. ".png"
 | 
			
		||||
	textures[i] = "weather_snowflake" .. i .. ".png"
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
effects["climate_api:particles"] = {
 | 
			
		||||
	boxsize = { x = 24, y = 6, z = 24 },
 | 
			
		||||
	v_offset = 2,
 | 
			
		||||
	amount = 4,
 | 
			
		||||
	expirationtime = 7,
 | 
			
		||||
	velocity = 0.85,
 | 
			
		||||
	acceleration = -0.06,
 | 
			
		||||
	texture = textures,
 | 
			
		||||
	glow = 6
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
climate_api.register_weather(name, conditions, effects)
 | 
			
		||||
 
 | 
			
		||||
@@ -10,6 +10,13 @@ local conditions = {
 | 
			
		||||
 | 
			
		||||
local effects = {}
 | 
			
		||||
 | 
			
		||||
effects["climate_api:skybox"] = {
 | 
			
		||||
	cloud_data = {
 | 
			
		||||
		color = "#5e676eb5"
 | 
			
		||||
	},
 | 
			
		||||
	priority = 11
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
effects["climate_api:hud_overlay"] = {
 | 
			
		||||
	file = "weather_hud_frost.png",
 | 
			
		||||
	z_index = -100,
 | 
			
		||||
@@ -17,13 +24,14 @@ effects["climate_api:hud_overlay"] = {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
effects["climate_api:particles"] = {
 | 
			
		||||
	min_pos = {x=-7, y=3, z=-7},
 | 
			
		||||
	max_pos = {x= 7, y=6, z= 7},
 | 
			
		||||
	exptime=7.5,
 | 
			
		||||
	size=15,
 | 
			
		||||
	amount=6,
 | 
			
		||||
	falling_speed = 0.75,
 | 
			
		||||
	texture="weather_snow.png"
 | 
			
		||||
	boxsize = { x = 14, y = 3, z = 14 },
 | 
			
		||||
	v_offset = 3,
 | 
			
		||||
	expirationtime = 7.5,
 | 
			
		||||
	size = 15,
 | 
			
		||||
	amount = 6,
 | 
			
		||||
	velocity = 0.75,
 | 
			
		||||
	texture = "weather_snow.png",
 | 
			
		||||
	glow = 6
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
climate_api.register_weather(name, conditions, effects)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								init.lua
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								init.lua
									
									
									
									
									
								
							@@ -15,7 +15,6 @@ end
 | 
			
		||||
 | 
			
		||||
regional_weather = {}
 | 
			
		||||
regional_weather.settings = {}
 | 
			
		||||
regional_weather.settings.damage			= get_setting_bool("damage", true)
 | 
			
		||||
regional_weather.settings.snow				= get_setting_bool("snow_layers", true)
 | 
			
		||||
regional_weather.settings.puddles			= get_setting_bool("puddles", true)
 | 
			
		||||
regional_weather.settings.soil				= get_setting_bool("soil", true)
 | 
			
		||||
@@ -24,6 +23,8 @@ regional_weather.settings.ice					= get_setting_bool("ice", true)
 | 
			
		||||
regional_weather.settings.pedology		= get_setting_bool("pedology", true)
 | 
			
		||||
regional_weather.settings.max_height	= get_setting_number("max_height", 120)
 | 
			
		||||
regional_weather.settings.min_height	= get_setting_number("min_height", -50)
 | 
			
		||||
regional_weather.settings.cloud_height= get_setting_number("cloud_height", 120)
 | 
			
		||||
regional_weather.settings.cloud_scale	= get_setting_number("cloud_scale", 40)
 | 
			
		||||
 | 
			
		||||
-- warn about clouds being overriden by MTG weather
 | 
			
		||||
if climate_mod.settings.skybox
 | 
			
		||||
@@ -47,7 +48,6 @@ dofile(modpath.."/ca_weathers/snow_heavy.lua")
 | 
			
		||||
dofile(modpath.."/ca_weathers/storm.lua")
 | 
			
		||||
 | 
			
		||||
-- register environment effects
 | 
			
		||||
dofile(modpath.."/ca_effects/damage.lua")
 | 
			
		||||
dofile(modpath.."/ca_effects/lightning.lua")
 | 
			
		||||
dofile(modpath.."/ca_effects/speed_buff.lua")
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,5 @@
 | 
			
		||||
[Features]
 | 
			
		||||
 | 
			
		||||
# If set to true, sand storms and hail will damage affected players over time.
 | 
			
		||||
regional_weather_damage (Cause player damage) bool true
 | 
			
		||||
 | 
			
		||||
# If set to true, snow layers will stack up during snowy weather.
 | 
			
		||||
regional_weather_snow_layers (Place snow layers) bool true
 | 
			
		||||
 | 
			
		||||
@@ -24,10 +21,16 @@ regional_weather_pedology (Wetten pedology nodes) bool true
 | 
			
		||||
 | 
			
		||||
[World Configuration]
 | 
			
		||||
 | 
			
		||||
# No visual effects will be applied below this height.
 | 
			
		||||
# This will prevent unwanted visuals within large underground caves.
 | 
			
		||||
regional_weather_min_height (Minimum height of weather effects) int -50
 | 
			
		||||
 | 
			
		||||
# No visual effects will be applied above this height.
 | 
			
		||||
# This value defaults to normal cloud height (120 nodes above sea level).
 | 
			
		||||
regional_weather_max_height (Maximum height of weather effects) int 120
 | 
			
		||||
 | 
			
		||||
# No visual effects will be applied below this height.
 | 
			
		||||
# This will prevent unwanted visuals within large underground caves.
 | 
			
		||||
regional_weather_min_height (Minimum height of weather effects) int -50
 | 
			
		||||
# Average height of cloud bases
 | 
			
		||||
regional_weather_cloud_height (Cloud height) int 120
 | 
			
		||||
 | 
			
		||||
# Maxmial variation of cloud height from base value
 | 
			
		||||
regional_weather_cloud_scale (Cloud height variation) int 40
 | 
			
		||||
		Reference in New Issue
	
	Block a user