mirror of
				https://github.com/t-affeldt/regional_weather.git
				synced 2025-10-31 16:15:30 +01:00 
			
		
		
		
	Disable snow in deserts, improve puddle clustering
This commit is contained in:
		| @@ -1,6 +1,7 @@ | |||||||
| local BLOCK_PREFIX = "regional_weather:puddle_" | local BLOCK_PREFIX = "regional_weather:puddle_" | ||||||
| local VARIANT_COUNT = 39 | local VARIANT_COUNT = 39 | ||||||
| local MIN_DISTANCE = 4 | local CHECK_DISTANCE = 4 | ||||||
|  | local MAX_AMOUNT = 3 | ||||||
|  |  | ||||||
| local GROUND_COVERS = { | local GROUND_COVERS = { | ||||||
| 	"group:soil", | 	"group:soil", | ||||||
| @@ -12,18 +13,32 @@ local GROUND_COVERS = { | |||||||
| 	"default:permafrost_with_stones" | 	"default:permafrost_with_stones" | ||||||
| } | } | ||||||
|  |  | ||||||
|  | -- clean up puddles if disabled | ||||||
| if not regional_weather.settings.puddles then | if not regional_weather.settings.puddles then | ||||||
| 	for i=1,VARIANT_COUNT do | 	-- set all puddle nodes to air | ||||||
| 		for r=0,270,90  do | 	minetest.register_alias("regional_weather:puddle", "air") | ||||||
| 			minetest.register_alias(BLOCK_PREFIX .. i .. "_" .. r, "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 | ||||||
| 	end | 	end | ||||||
|  |  | ||||||
|  | 	-- return air instead of a puddle | ||||||
|  | 	function regional_weather.get_random_puddle() | ||||||
|  | 		return { name = "air" } | ||||||
|  | 	end | ||||||
|  |  | ||||||
|  | 	-- end puddle execution | ||||||
| 	return | 	return | ||||||
| end | end | ||||||
|  |  | ||||||
| local node_box = { | local node_box = { | ||||||
| 	type  = "fixed", | 	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 | local apply_water_group | ||||||
| @@ -31,8 +46,8 @@ if regional_weather.settings.puddles_water then | |||||||
| 	apply_water_group = 1 | 	apply_water_group = 1 | ||||||
| end | end | ||||||
|  |  | ||||||
| for i = 1,VARIANT_COUNT do | for i = 1, VARIANT_COUNT do | ||||||
| 	for flip = 0,1 do | 	for flip = 0, 1 do | ||||||
| 		local name = BLOCK_PREFIX .. i | 		local name = BLOCK_PREFIX .. i | ||||||
| 		local index = i | 		local index = i | ||||||
| 		if i < 10 then index = "0" .. i end | 		if i < 10 then index = "0" .. i end | ||||||
| @@ -75,7 +90,7 @@ end | |||||||
|  |  | ||||||
| minetest.register_alias("regional_weather:puddle", BLOCK_PREFIX .. "14") | 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 index = math.random(1, VARIANT_COUNT) | ||||||
| 	local rotation = math.random(0, 3) * 90 | 	local rotation = math.random(0, 3) * 90 | ||||||
| 	local flip = math.random(0, 1) | 	local flip = math.random(0, 1) | ||||||
| @@ -109,16 +124,23 @@ climate_api.register_abm({ | |||||||
| 	 end, | 	 end, | ||||||
|  |  | ||||||
|    action = function (pos, node, env) |    action = function (pos, node, env) | ||||||
|  | 		 -- only override air nodes | ||||||
| 		 if minetest.get_node(pos).name ~= "air" then return end | 		 if minetest.get_node(pos).name ~= "air" then return end | ||||||
| 		 if minetest.find_node_near(pos, MIN_DISTANCE, "group:weather_puddle") then return end | 		 -- do not place puddle if area is not fully loaded | ||||||
| 		 minetest.set_node(pos, get_random_puddle()) | 		 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 | 	 end | ||||||
| }) | }) | ||||||
|  |  | ||||||
| -- Makes puddles dry up when not raining | -- Makes puddles dry up when not raining | ||||||
| climate_api.register_abm({ | climate_api.register_abm({ | ||||||
| 	label = "remove rain puddles", | 	label = "remove rain puddles", | ||||||
| 	nodenames	= { "group:regional_weather_puddle" }, | 	nodenames	= { "group:weather_puddle" }, | ||||||
| 	interval	= 10, | 	interval	= 10, | ||||||
| 	chance		= 3, | 	chance		= 3, | ||||||
| 	catch_up	= true, | 	catch_up	= true, | ||||||
| @@ -126,8 +148,6 @@ climate_api.register_abm({ | |||||||
| 	action = function (pos, node, env) | 	action = function (pos, node, env) | ||||||
| 		if env.humidity < 55 then | 		if env.humidity < 55 then | ||||||
| 			minetest.remove_node(pos) | 			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 | ||||||
| 	end | 	end | ||||||
| }) | }) | ||||||
|   | |||||||
| @@ -1,4 +1,6 @@ | |||||||
| local BLOCK_PREFIX = "regional_weather:snow_cover_" | local BLOCK_PREFIX = "regional_weather:snow_cover_" | ||||||
|  | local CHECK_DISTANCE = 3 | ||||||
|  | local MAX_AMOUNT = 20 | ||||||
|  |  | ||||||
| if not minetest.get_modpath("default") | if not minetest.get_modpath("default") | ||||||
| or default.node_sound_snow_defaults == nil | or default.node_sound_snow_defaults == nil | ||||||
| @@ -35,7 +37,7 @@ for i = 1,5 do | |||||||
| 			crumbly = 3, | 			crumbly = 3, | ||||||
| 			falling_node = 1, | 			falling_node = 1, | ||||||
| 			snowy = 1, | 			snowy = 1, | ||||||
| 			regional_weather_snow_cover = i | 			weather_snow_cover = i | ||||||
| 		}, | 		}, | ||||||
| 		sounds = default.node_sound_snow_defaults(), | 		sounds = default.node_sound_snow_defaults(), | ||||||
| 		drop = "default:snow " .. math.ceil(i / 2), | 		drop = "default:snow " .. math.ceil(i / 2), | ||||||
| @@ -69,7 +71,15 @@ climate_api.register_abm({ | |||||||
| 		 max_height		= regional_weather.settings.max_height, | 		 max_height		= regional_weather.settings.max_height, | ||||||
| 		 min_humidity	= 55, | 		 min_humidity	= 55, | ||||||
| 		 max_heat			= 30, | 		 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) | 	 pos_override = function(pos) | ||||||
| @@ -77,13 +87,16 @@ climate_api.register_abm({ | |||||||
| 	 end, | 	 end, | ||||||
|  |  | ||||||
|    action = function (pos, node, env) |    action = function (pos, node, env) | ||||||
|  | 		 -- only override air nodes | ||||||
| 		 if node.name ~= "air" then return end | 		 if node.name ~= "air" then return end | ||||||
| 		 local base = minetest.get_node(vector.add(pos, {x=0, y=-1, z=0})).name | 		 -- do not place snow if area is not fully loaded | ||||||
| 		 local is_soil = minetest.get_item_group(base, "soil") or 0 | 		 if minetest.find_node_near(pos, CHECK_DISTANCE, "ignore") then return end | ||||||
| 		 local is_stone = minetest.get_item_group(base, "stone") or 0 | 		 -- do not place snow if already enpugh snow | ||||||
| 		 if not (is_soil == 0 and is_stone == 0) then | 		 local pos1 = vector.add(pos, { x = -CHECK_DISTANCE, y = -1, z = -CHECK_DISTANCE }) | ||||||
| 		 	minetest.set_node(pos, { name = BLOCK_PREFIX .. "1" }) | 		 local pos2 = vector.add(pos, { x =  CHECK_DISTANCE, y =  1, z =  CHECK_DISTANCE }) | ||||||
| 		end | 		 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 | 	 end | ||||||
| }) | }) | ||||||
|  |  | ||||||
| @@ -93,7 +106,7 @@ climate_api.register_abm({ | |||||||
| 		"group:flora", | 		"group:flora", | ||||||
| 		"group:grass", | 		"group:grass", | ||||||
| 		"group:plant", | 		"group:plant", | ||||||
| 		"group:regional_weather_snow_cover" | 		"group:weather_snow_cover" | ||||||
| 	}, | 	}, | ||||||
| 	neighbors	= { "air" }, | 	neighbors	= { "air" }, | ||||||
| 	interval	= 25, | 	interval	= 25, | ||||||
| @@ -105,12 +118,34 @@ climate_api.register_abm({ | |||||||
| 		 max_height		= regional_weather.settings.max_height, | 		 max_height		= regional_weather.settings.max_height, | ||||||
| 		 min_humidity	= 55, | 		 min_humidity	= 55, | ||||||
| 		 max_heat			= 30, | 		 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) |    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") or 0 | ||||||
| 		 if value == nil then value = 0 end | 		 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 | 		 if value < 5 then | ||||||
| 			 minetest.set_node(pos, { name = BLOCK_PREFIX .. (value + 1) }) | 			 minetest.set_node(pos, { name = BLOCK_PREFIX .. (value + 1) }) | ||||||
| 		 end | 		 end | ||||||
| @@ -119,9 +154,9 @@ climate_api.register_abm({ | |||||||
|  |  | ||||||
| climate_api.register_abm({ | climate_api.register_abm({ | ||||||
| 	label			= "melt snow covers", | 	label			= "melt snow covers", | ||||||
| 	nodenames	= { "group:regional_weather_snow_cover" }, | 	nodenames	= { "group:weather_snow_cover" }, | ||||||
| 	interval	= 25, | 	interval	= 15, | ||||||
| 	chance		= 10, | 	chance		= 4, | ||||||
| 	catch_up	= true, | 	catch_up	= true, | ||||||
|  |  | ||||||
| 	 conditions	= { | 	 conditions	= { | ||||||
| @@ -129,12 +164,12 @@ climate_api.register_abm({ | |||||||
| 	 }, | 	 }, | ||||||
|  |  | ||||||
|    action = function (pos, node, env) |    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 == nil then value = 0 end | ||||||
| 			if value > 1 then | 			if value > 1 then | ||||||
| 				minetest.set_node(pos, { name = BLOCK_PREFIX .. (value - 1) }) | 				minetest.set_node(pos, { name = BLOCK_PREFIX .. (value - 1) }) | ||||||
| 			elseif regional_weather.settings.puddles then | 			elseif regional_weather.settings.puddles then | ||||||
| 				minetest.set_node(pos, { name = "regional_weather:puddle" }) | 				minetest.set_node(pos, regional_weather.get_random_puddle()) | ||||||
| 			else | 			else | ||||||
| 				minetest.set_node(pos, { name = "air" }) | 				minetest.set_node(pos, { name = "air" }) | ||||||
| 			end | 			end | ||||||
|   | |||||||
| @@ -7,7 +7,15 @@ local conditions = { | |||||||
| 	max_heat				= 45, | 	max_heat				= 45, | ||||||
| 	min_humidity		= 65, | 	min_humidity		= 65, | ||||||
| 	min_windspeed		= 2.5, | 	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 = {} | local effects = {} | ||||||
|   | |||||||
| @@ -6,7 +6,15 @@ local conditions = { | |||||||
| 	max_heat				= 35, | 	max_heat				= 35, | ||||||
| 	min_humidity		= 50, | 	min_humidity		= 50, | ||||||
| 	max_humidity		= 65, | 	max_humidity		= 65, | ||||||
| 	daylight				= 15 | 	daylight				= 15, | ||||||
|  | 	not_biome				= { | ||||||
|  | 		"cold_desert", | ||||||
|  | 		"cold_desert_ocean", | ||||||
|  | 		"desert", | ||||||
|  | 		"desert_ocean", | ||||||
|  | 		"sandstone_desert", | ||||||
|  | 		"sandstone_desert_ocean" | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| local effects = {} | local effects = {} | ||||||
|   | |||||||
| @@ -5,7 +5,15 @@ local conditions = { | |||||||
| 	max_height = regional_weather.settings.max_height, | 	max_height = regional_weather.settings.max_height, | ||||||
| 	max_heat				= 30, | 	max_heat				= 30, | ||||||
| 	min_humidity		= 65, | 	min_humidity		= 65, | ||||||
| 	daylight				= 15 | 	daylight				= 15, | ||||||
|  | 	not_biome				= { | ||||||
|  | 		"cold_desert", | ||||||
|  | 		"cold_desert_ocean", | ||||||
|  | 		"desert", | ||||||
|  | 		"desert_ocean", | ||||||
|  | 		"sandstone_desert", | ||||||
|  | 		"sandstone_desert_ocean" | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| local effects = {} | local effects = {} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user