mirror of
				https://github.com/mt-mods/biome_lib.git
				synced 2025-10-31 04:55:33 +01:00 
			
		
		
		
	Compare commits
	
		
			6 Commits
		
	
	
		
			non_mtg
			...
			extra-map-
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 53f55cdb4d | ||
|  | 8ecb401309 | ||
|  | 9ed4858518 | ||
|  | 26dbbb5a67 | ||
|  | ec0a0f0c3b | ||
|  | e92361675f | 
							
								
								
									
										57
									
								
								init.lua
									
									
									
									
									
								
							
							
						
						
									
										57
									
								
								init.lua
									
									
									
									
									
								
							| @@ -9,8 +9,6 @@ | ||||
| biome_lib = {} | ||||
| biome_lib.air = {name = "air"} | ||||
|  | ||||
| plantslib = setmetatable({}, { __index=function(t,k) print("Use of deprecated function:", k) return biome_lib[k] end }) | ||||
|  | ||||
| biome_lib.blocklist_aircheck = {} | ||||
| biome_lib.blocklist_no_aircheck = {} | ||||
|  | ||||
| @@ -36,7 +34,7 @@ local function tableize(s) | ||||
| 	return string.split(string.trim(string.gsub(s, " ", ""))) | ||||
| end | ||||
|  | ||||
| local c1 minetest.settings:get("biome_lib_default_grow_through_nodes") | ||||
| local c1 = minetest.settings:get("biome_lib_default_grow_through_nodes") | ||||
| biome_lib.default_grow_through_nodes = {["air"] = true} | ||||
| if c1 then | ||||
| 	for _, i in ipairs(tableize(c1)) do | ||||
| @@ -46,7 +44,7 @@ else | ||||
| 	biome_lib.default_grow_through_nodes["default:snow"] = true | ||||
| end | ||||
|  | ||||
| local c2 minetest.settings:get("biome_lib_default_water_nodes") | ||||
| local c2 = minetest.settings:get("biome_lib_default_water_nodes") | ||||
| biome_lib.default_water_nodes = {} | ||||
| if c2 then | ||||
| 	for _, i in ipairs(tableize(c2)) do | ||||
| @@ -160,7 +158,7 @@ function biome_lib:set_defaults(biome) | ||||
| 	biome.near_nodes_size = biome.near_nodes_size or 0 | ||||
| 	biome.near_nodes_count = biome.near_nodes_count or 1 | ||||
| 	biome.rarity = biome.rarity or 50 | ||||
| 	biome.max_count = biome.max_count or 5 | ||||
| 	biome.max_count = biome.max_count or 125 | ||||
| 	if biome.check_air ~= false then biome.check_air = true end | ||||
|  | ||||
| -- specific to abm spawner | ||||
| @@ -331,6 +329,7 @@ local function populate_single_surface(biome, pos, perlin_fertile_area, checkair | ||||
| end | ||||
|  | ||||
| function biome_lib:populate_surfaces(biome, nodes_or_function_or_model, snodes, checkair) | ||||
| 	local items_added = 0 | ||||
|  | ||||
| 	biome_lib:set_defaults(biome) | ||||
|  | ||||
| @@ -351,10 +350,10 @@ function biome_lib:populate_surfaces(biome, nodes_or_function_or_model, snodes, | ||||
| 	local num_in_biome_nodes = #in_biome_nodes | ||||
|  | ||||
| 	if num_in_biome_nodes == 0 then | ||||
| 		return | ||||
| 		return 0 | ||||
| 	end | ||||
|  | ||||
| 	for i = 1, math.min(biome.max_count, num_in_biome_nodes) do | ||||
| 	for i = 1, math.min(math.ceil(biome.max_count/25), num_in_biome_nodes) do | ||||
| 		local tries = 0 | ||||
| 		local spawned = false | ||||
| 		while tries < 2 and not spawned do | ||||
| @@ -423,13 +422,27 @@ function biome_lib:populate_surfaces(biome, nodes_or_function_or_model, snodes, | ||||
| 				tries = tries + 1 | ||||
| 			end | ||||
| 		end | ||||
| 		if spawned then items_added = items_added + 1 end | ||||
| 	end | ||||
| 	return items_added | ||||
| end | ||||
|  | ||||
| -- make sure the target block and all 6 neighbors are actually loaded. | ||||
|  | ||||
| local function confirm_block_surroundings(pos) | ||||
| 	return minetest.get_node_or_nil(pos) | ||||
| 	  and minetest.get_node_or_nil({ x=pos.x-16, y=pos.y,   z=pos.z   }) | ||||
| 	  and minetest.get_node_or_nil({ x=pos.x+16, y=pos.y,   z=pos.z   }) | ||||
| 	  and minetest.get_node_or_nil({ x=pos.x,   y=pos.y-16, z=pos.z   }) | ||||
| 	  and minetest.get_node_or_nil({ x=pos.x,   y=pos.y+16, z=pos.z   }) | ||||
| 	  and minetest.get_node_or_nil({ x=pos.x,   y=pos.y,   z=pos.z-16 }) | ||||
| 	  and minetest.get_node_or_nil({ x=pos.x,   y=pos.y,   z=pos.z+16 }) | ||||
| end | ||||
|  | ||||
| -- Primary mapgen spawner, for mods that can work with air checking enabled on | ||||
| -- a surface during the initial map read stage. | ||||
|  | ||||
| function biome_lib:generate_block_with_air_checking() | ||||
| function biome_lib:generate_block_with_air_checking(shutdown) | ||||
| 	if not biome_lib.blocklist_aircheck[1] then | ||||
| 		return | ||||
| 	end | ||||
| @@ -446,14 +459,24 @@ function biome_lib:generate_block_with_air_checking() | ||||
| 		biome_lib.surface_nodes_aircheck.blockhash = | ||||
| 			minetest.find_nodes_in_area_under_air(minp, maxp, biome_lib.surfaceslist_aircheck) | ||||
| 		biome_lib.actioncount_aircheck.blockhash = 1 | ||||
|  | ||||
| 		if #biome_lib.surface_nodes_aircheck.blockhash > 0 then | ||||
| 			biome_lib:dbg("Mapblock at "..minetest.pos_to_string(minp).." added, with "..#biome_lib.surface_nodes_aircheck.blockhash.." surface nodes detected.") | ||||
| 		end | ||||
| 	elseif not shutdown and not confirm_block_surroundings(minp) and #biome_lib.blocklist_aircheck > 1 then | ||||
| 		biome_lib.blocklist_aircheck[#biome_lib.blocklist_aircheck+1] = biome_lib.blocklist_aircheck[1] | ||||
| 		table.remove(biome_lib.blocklist_aircheck, 1) | ||||
| 		biome_lib:dbg("Mapblock at "..minetest.pos_to_string(minp).." had an unloaded neighbor, moved it to the end of the queue.") | ||||
| 	else | ||||
| 		if biome_lib.actionslist_aircheck[biome_lib.actioncount_aircheck.blockhash] then | ||||
| 			-- [1] is biome, [2] is node/function/model | ||||
| 			biome_lib:populate_surfaces( | ||||
| 			local added = biome_lib:populate_surfaces( | ||||
| 				biome_lib.actionslist_aircheck[biome_lib.actioncount_aircheck.blockhash][1], | ||||
| 				biome_lib.actionslist_aircheck[biome_lib.actioncount_aircheck.blockhash][2], | ||||
| 				biome_lib.surface_nodes_aircheck.blockhash, true) | ||||
| 			if added > 0 then | ||||
| 				biome_lib:dbg("Ran biome_lib:populate_surfaces for block at "..minetest.pos_to_string(minp).. | ||||
| 					".  Entry #"..biome_lib.actioncount_aircheck.blockhash.." added "..added.." items.") | ||||
| 			end | ||||
| 			biome_lib.actioncount_aircheck.blockhash = biome_lib.actioncount_aircheck.blockhash + 1 | ||||
| 		else | ||||
| 			table.remove(biome_lib.blocklist_aircheck, 1) | ||||
| @@ -466,7 +489,7 @@ end | ||||
| -- Secondary mapgen spawner, for mods that require disabling of | ||||
| -- checking for air during the initial map read stage. | ||||
|  | ||||
| function biome_lib:generate_block_no_aircheck() | ||||
| function biome_lib:generate_block_no_aircheck(shutdown) | ||||
| 	if not biome_lib.blocklist_no_aircheck[1] then | ||||
| 		return | ||||
| 	end | ||||
| @@ -480,7 +503,9 @@ function biome_lib:generate_block_no_aircheck() | ||||
| 		biome_lib.surface_nodes_no_aircheck.blockhash = | ||||
| 			minetest.find_nodes_in_area(minp, maxp, biome_lib.surfaceslist_no_aircheck) | ||||
| 		biome_lib.actioncount_no_aircheck.blockhash = 1 | ||||
|  | ||||
| 	elseif not shutdown and not confirm_block_surroundings(minp) and #biome_lib.blocklist_no_aircheck > 1 then | ||||
| 		biome_lib.blocklist_no_aircheck[#biome_lib.blocklist_no_aircheck+1] = biome_lib.blocklist_no_aircheck[1] | ||||
| 		table.remove(biome_lib.blocklist_no_aircheck, 1) | ||||
| 	else | ||||
| 		if biome_lib.actionslist_no_aircheck[biome_lib.actioncount_no_aircheck.blockhash] then | ||||
| 			biome_lib:populate_surfaces( | ||||
| @@ -511,10 +536,10 @@ minetest.register_globalstep(function(dtime) | ||||
| 	while (#biome_lib.blocklist_aircheck > 0 or #biome_lib.blocklist_no_aircheck > 0) | ||||
| 	  and biome_lib.globalstep_runtime < 200000 do  -- 0.2 seconds, in uS. | ||||
| 		if #biome_lib.blocklist_aircheck > 0 then | ||||
| 			biome_lib:generate_block_with_air_checking() | ||||
| 			biome_lib:generate_block_with_air_checking(false) | ||||
| 		end | ||||
| 		if #biome_lib.blocklist_no_aircheck > 0 then | ||||
| 			biome_lib:generate_block_no_aircheck() | ||||
| 			biome_lib:generate_block_no_aircheck(false) | ||||
| 		end | ||||
| 		biome_lib.globalstep_runtime = minetest.get_us_time() - biome_lib.globalstep_start_time | ||||
| 	end | ||||
| @@ -531,7 +556,7 @@ minetest.register_on_shutdown(function() | ||||
| 	print("[biome_lib] Stand by, playing out the rest of the aircheck mapblock log") | ||||
| 	print("(there are "..#biome_lib.blocklist_aircheck.." entries)...") | ||||
| 	while #biome_lib.blocklist_aircheck > 0 do | ||||
| 		biome_lib:generate_block_with_air_checking(0.1) | ||||
| 		biome_lib:generate_block_with_air_checking(true) | ||||
| 	end | ||||
| end) | ||||
|  | ||||
| @@ -543,7 +568,7 @@ minetest.register_on_shutdown(function() | ||||
| 	print("[biome_lib] Stand by, playing out the rest of the no-aircheck mapblock log") | ||||
| 	print("(there are "..#biome_lib.blocklist_no_aircheck.." entries)...") | ||||
| 	while #biome_lib.blocklist_no_aircheck > 0 do | ||||
| 		biome_lib:generate_block_no_aircheck(0.1) | ||||
| 		biome_lib:generate_block_no_aircheck(true) | ||||
| 	end | ||||
| end) | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user