mirror of
				https://github.com/mt-mods/biome_lib.git
				synced 2025-10-31 13:05:23 +01:00 
			
		
		
		
	Compare commits
	
		
			45 Commits
		
	
	
		
			2018-11-09
			...
			eabc053c05
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | eabc053c05 | ||
|  | dd650da443 | ||
|  | 0a34e3c7af | ||
|  | 07c2b1d9d4 | ||
|  | 1dc0febd8c | ||
|  | 50f921a85a | ||
|  | 6009f261c2 | ||
|  | 531577afcf | ||
|  | e346fd599f | ||
|  | 212024a9b4 | ||
|  | 1d2593f022 | ||
|  | 3bc8737e2d | ||
|  | 0ea4cb3848 | ||
|  | bef0a0d87e | ||
|  | 89ca62e492 | ||
|  | a325c2ccd8 | ||
|  | 8ecb401309 | ||
|  | 9ed4858518 | ||
|  | 26dbbb5a67 | ||
|  | ec0a0f0c3b | ||
|  | e92361675f | ||
|  | 7f1fec6ae0 | ||
|  | f569bb1fbd | ||
|  | f2a807b814 | ||
|  | 9b7705c380 | ||
|  | c9f6235815 | ||
|  | ddd88613e0 | ||
|  | 27cd07cb36 | ||
|  | ac8738d837 | ||
|  | 0005af6022 | ||
|  | 228296411e | ||
|  | 353ca0cbd4 | ||
|  | d65c72d48b | ||
|  | 10a1089767 | ||
|  | 5a910875af | ||
|  | a96f015ce9 | ||
|  | d72e15f1d0 | ||
|  | 29899f2d36 | ||
|  | 0837ff7fd2 | ||
|  | ff9ce531d6 | ||
|  | fa304f9d18 | ||
|  | b7d69a8487 | ||
|  | f056d6d76e | ||
|  | 6935e73994 | ||
|  | ad12e97281 | 
							
								
								
									
										71
									
								
								API.txt
									
									
									
									
									
								
							
							
						
						
									
										71
									
								
								API.txt
									
									
									
									
									
								
							| @@ -72,6 +72,7 @@ biome = { | |||||||
| 	---- most likely want to use at least some of these to limit how and | 	---- most likely want to use at least some of these to limit how and | ||||||
| 	---- where your objects are spawned. | 	---- where your objects are spawned. | ||||||
|  |  | ||||||
|  | 	label = string,		-- set this to identify the ABM for Minetest's profiler | ||||||
| 	avoid_nodes = {table},	-- same meaning as savoid, above | 	avoid_nodes = {table},	-- same meaning as savoid, above | ||||||
| 	avoid_radius = num,	-- same as sradius | 	avoid_radius = num,	-- same as sradius | ||||||
| 	seed_diff = num,	-- The Perlin seed difference value passed to the | 	seed_diff = num,	-- The Perlin seed difference value passed to the | ||||||
| @@ -342,14 +343,18 @@ into something else over time.  This function has no return value, and accepts | |||||||
| a biome definition table as the only parameter.  These are defined like so: | a biome definition table as the only parameter.  These are defined like so: | ||||||
|  |  | ||||||
| options = { | options = { | ||||||
| 	grow_plant = "string", -- Name of the node to be grown into something | 	label = string,		-- set this to identify the ABM for Minetest's | ||||||
| 						-- else.  This value is passed to the ABM as the | 						-- profiler.  If not set, biome_lib will set it to  | ||||||
| 						-- "nodenames" parameter, so it is the plants | 						-- "biome_lib grow_plants(): " appended with the node | ||||||
| 						-- themselves that are the ABM trigger, rather than | 						-- in grow_plant (or the first item if it's a table) | ||||||
|  | 	grow_plant = "string" or {table}, -- Name(s) of the node(s) to be grown | ||||||
|  | 						-- into something else.  This value is passed to the | ||||||
|  | 						-- ABM as the "nodenames" parameter, so the plants | ||||||
|  | 						-- themselves are the ABM trigger, rather than | ||||||
| 						-- the ground they spawned on.  A plant will only grow | 						-- the ground they spawned on.  A plant will only grow | ||||||
| 						-- if the node above it is air.  Can also be a table, | 						-- if the node above it is air.  If you use a table, | ||||||
| 						-- but note that all nodes referenced therein will be | 						-- note that all nodes referenced therein will be | ||||||
| 						-- grown into the same object. | 						-- grown into the same final object. | ||||||
| 	grow_delay = num,	-- Passed as the ABM "interval" parameter, as with | 	grow_delay = num,	-- Passed as the ABM "interval" parameter, as with | ||||||
| 						-- spawning. | 						-- spawning. | ||||||
| 	grow_chance = num,	-- Passed as the ABM "chance" parameter. | 	grow_chance = num,	-- Passed as the ABM "chance" parameter. | ||||||
| @@ -441,12 +446,22 @@ question is already loaded, or false if not. | |||||||
|  |  | ||||||
|  |  | ||||||
| ===== | ===== | ||||||
| dbg(string) | dbg(string, level) | ||||||
|  |  | ||||||
| This is a simple debug output function which takes one string parameter.  It | This is a simple debug output function which takes one string parameter.  It | ||||||
| just checks if DEBUG is true and outputs the phrase "[Plantlife] " followed by | just checks if DEBUG is true and outputs the phrase "[Plantlife] " followed by | ||||||
| the supplied string, via the print() function, if so. | the supplied string, via the print() function, if so. | ||||||
|  |  | ||||||
|  | 'level' is a number that, if supplied, dictates the lowest 'biome_lib_debug' | ||||||
|  | can be set to in minetest.conf for this message to be displayed.  Both the | ||||||
|  | default log level and the default message level are 0, thus always showing the | ||||||
|  | supplied message. | ||||||
|  |  | ||||||
|  | Although it's not set in stone, a good practice is to use a level of 0 (or | ||||||
|  | just omit the value) for anything that generally important enough that it | ||||||
|  | ought always be shown, 1 for errors, 2 for warnings, 3 for info, 4 for verbose | ||||||
|  | spammy stuff. | ||||||
|  |  | ||||||
| ===== | ===== | ||||||
| biome_lib:generate_tree(pos, treemodel) | biome_lib:generate_tree(pos, treemodel) | ||||||
| biome_lib:grow_tree(pos, treemodel) | biome_lib:grow_tree(pos, treemodel) | ||||||
| @@ -583,3 +598,43 @@ And this particular one is mapped slightly differently from the others: | |||||||
|  |  | ||||||
| (Note the +150 and +50 offsets) | (Note the +150 and +50 offsets) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | ================== | ||||||
|  | Default game nodes | ||||||
|  | ================== | ||||||
|  |  | ||||||
|  | Although this project was intended to be used with minetest_game, it can be | ||||||
|  | configured to work with something else instead.  All you need to do is provide | ||||||
|  | the names of the nodes in your game you want biome_lib's internals to use. | ||||||
|  |  | ||||||
|  | Put these settings in your game's minetest.conf (or your client's own config, | ||||||
|  | if desired).  You'll need to set all of them. | ||||||
|  |  | ||||||
|  | biome_lib_default_grow_through_nodes | ||||||
|  | 	Comma-separated list of things that a spawned node is allowed to grow | ||||||
|  | 	through.  Air is always added to whatever you specify. | ||||||
|  | 	Default:  air, default:snow | ||||||
|  |  | ||||||
|  | biome_lib_default_water_nodes | ||||||
|  | 	Comma-separated list of nodes that should be treated as water for the sake | ||||||
|  | 	of looking for neighboring "wet" ground. | ||||||
|  | 	Default: default:water_source, default:water_flowing, | ||||||
|  | 		default:river_water_source, default:river_water_flowing | ||||||
|  |  | ||||||
|  | biome_lib_default_wet_surfaces | ||||||
|  | 	Comma-separated list of nodes that should be considered "wet" if one of | ||||||
|  | 	the aforementioned water nodes is nearby. | ||||||
|  | 	Default: default:dirt, default:dirt_with_grass, default:sand | ||||||
|  |  | ||||||
|  | biome_lib_default_grow_nodes | ||||||
|  | 	Comma-separated list of nodes that something must be sitting on to be | ||||||
|  | 	able to actively change from one thing to another (such as a sapling | ||||||
|  | 	growing into a tree), to be used for ALL growable nodes, if the calling | ||||||
|  | 	mod doesn't provide its own lists. | ||||||
|  | 	Default: "default:dirt_with_grass" | ||||||
|  |  | ||||||
|  | biome_lib_default_ground_nodes | ||||||
|  | 	Comma-separated list of nodes to use as the "root" of something that can | ||||||
|  | 	gradually climb up a wall, to be used for ALL such nodes, if the calling | ||||||
|  | 	mod doesn't provide its own lists. | ||||||
|  | 	Default: "default:dirt_with_grass" | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ Both mapgen-based spawning and ABM-based spawning is supported. Growing code is | |||||||
|  |  | ||||||
| It is primarily intended for mapgen v6, but it should work fine when used with mapgen v7. | It is primarily intended for mapgen v6, but it should work fine when used with mapgen v7. | ||||||
|  |  | ||||||
| **Dependencies**: default from minetest_game | **Dependencies:** nothing, but if you don't use `minetest_game`, you'll need to supply some settings (see API.txt). | ||||||
|  |  | ||||||
| **Recommends**: [Plantlife Modpack](https://github.com/minetest-mods/plantlife_modpack),  | **Recommends**: [Plantlife Modpack](https://github.com/minetest-mods/plantlife_modpack),  | ||||||
| [More Trees](https://github.com/minetest-mods/moretrees) | [More Trees](https://github.com/minetest-mods/moretrees) | ||||||
|   | |||||||
| @@ -1,3 +0,0 @@ | |||||||
| default |  | ||||||
| intllib? |  | ||||||
|  |  | ||||||
							
								
								
									
										90
									
								
								growth.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								growth.lua
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,90 @@ | |||||||
|  | local time_scale = ... | ||||||
|  |  | ||||||
|  | -- The growing ABM | ||||||
|  |  | ||||||
|  | function biome_lib.check_surface(name, nodes) | ||||||
|  | 	if not nodes then return true end | ||||||
|  | 	if type(nodes) == "string" then return nodes == name end | ||||||
|  | 	if nodes.set and nodes[name] then | ||||||
|  | 		return true | ||||||
|  | 	else | ||||||
|  | 		for _, n in ipairs(nodes) do | ||||||
|  | 			if name == n then return true end | ||||||
|  | 		end | ||||||
|  | 	end | ||||||
|  | 	return false | ||||||
|  | end | ||||||
|  |  | ||||||
|  | function biome_lib:grow_plants(opts) | ||||||
|  |  | ||||||
|  | 	local options = opts | ||||||
|  |  | ||||||
|  | 	options.height_limit = options.height_limit or 5 | ||||||
|  | 	options.ground_nodes = options.ground_nodes or biome_lib.default_ground_nodes | ||||||
|  | 	options.grow_nodes = options.grow_nodes or biome_lib.default_grow_nodes | ||||||
|  | 	options.seed_diff = options.seed_diff or 0 | ||||||
|  |  | ||||||
|  | 	local n | ||||||
|  |  | ||||||
|  | 	if type(options.grow_plant) == "table" then | ||||||
|  | 		n = "multi: "..options.grow_plant[1]..", ..." | ||||||
|  | 	else | ||||||
|  | 		n = options.grow_plant | ||||||
|  | 	end | ||||||
|  |  | ||||||
|  | 	options.label = options.label or "biome_lib grow_plants(): "..n | ||||||
|  |  | ||||||
|  | 	if options.grow_delay*time_scale >= 1 then | ||||||
|  | 		options.interval = options.grow_delay*time_scale | ||||||
|  | 	else | ||||||
|  | 		options.interval = 1 | ||||||
|  | 	end | ||||||
|  |  | ||||||
|  | 	minetest.register_abm({ | ||||||
|  | 		nodenames = { options.grow_plant }, | ||||||
|  | 		interval = options.interval, | ||||||
|  | 		chance = options.grow_chance, | ||||||
|  | 		label = options.label, | ||||||
|  | 		action = function(pos, node, active_object_count, active_object_count_wider) | ||||||
|  | 			local p_top = {x=pos.x, y=pos.y+1, z=pos.z} | ||||||
|  | 			local p_bot = {x=pos.x, y=pos.y-1, z=pos.z} | ||||||
|  | 			local n_top = minetest.get_node(p_top) | ||||||
|  | 			local n_bot = minetest.get_node(p_bot) | ||||||
|  | 			local root_node = minetest.get_node({x=pos.x, y=pos.y-options.height_limit, z=pos.z}) | ||||||
|  | 			local walldir = nil | ||||||
|  | 			if options.need_wall and options.verticals_list then | ||||||
|  | 				walldir = biome_lib:find_adjacent_wall(p_top, options.verticals_list, options.choose_random_wall) | ||||||
|  | 			end | ||||||
|  | 			if biome_lib.default_grow_through_nodes[n_top.name] | ||||||
|  | 			  and (not options.need_wall or (options.need_wall and walldir)) then | ||||||
|  | 				if options.grow_vertically and walldir then | ||||||
|  | 					if biome_lib:search_downward(pos, options.height_limit, options.ground_nodes) then | ||||||
|  | 						minetest.swap_node(p_top, { name = options.grow_plant, param2 = walldir}) | ||||||
|  | 					end | ||||||
|  |  | ||||||
|  | 				elseif biome_lib.check_surface(n_bot.name, options.grow_nodes) then | ||||||
|  | 					if not options.grow_result and not options.grow_function then | ||||||
|  | 						minetest.swap_node(pos, biome_lib.air) | ||||||
|  |  | ||||||
|  | 					else | ||||||
|  | 						biome_lib:replace_object(pos, options.grow_result, options.grow_function, options.facedir, options.seed_diff) | ||||||
|  | 					end | ||||||
|  | 				end | ||||||
|  | 			end | ||||||
|  | 		end | ||||||
|  | 	}) | ||||||
|  | end | ||||||
|  |  | ||||||
|  |  | ||||||
|  | -- spawn_tree() on generate is routed through here so that other mods can hook | ||||||
|  | -- into it. | ||||||
|  |  | ||||||
|  | function biome_lib:generate_tree(pos, nodes_or_function_or_model) | ||||||
|  | 	minetest.spawn_tree(pos, nodes_or_function_or_model) | ||||||
|  | end | ||||||
|  |  | ||||||
|  | -- and this one's for the call used in the growing code | ||||||
|  |  | ||||||
|  | function biome_lib:grow_tree(pos, nodes_or_function_or_model) | ||||||
|  | 	minetest.spawn_tree(pos, nodes_or_function_or_model) | ||||||
|  | end | ||||||
							
								
								
									
										2
									
								
								mod.conf
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								mod.conf
									
									
									
									
									
								
							| @@ -1 +1,3 @@ | |||||||
| name = biome_lib | name = biome_lib | ||||||
|  | min_minetest_version = 5.2.0 | ||||||
|  | optional_depends = default, intllib | ||||||
|   | |||||||
							
								
								
									
										75
									
								
								search_functions.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								search_functions.lua
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,75 @@ | |||||||
|  |  | ||||||
|  | -- function to decide if a node has a wall that's in verticals_list{} | ||||||
|  | -- returns wall direction of valid node, or nil if invalid. | ||||||
|  |  | ||||||
|  | function biome_lib:find_adjacent_wall(pos, verticals, randomflag) | ||||||
|  | 	local verts = dump(verticals) | ||||||
|  | 	if randomflag then | ||||||
|  | 		local walltab = {} | ||||||
|  | 		 | ||||||
|  | 		if string.find(verts, minetest.get_node({ x=pos.x-1, y=pos.y, z=pos.z   }).name) then walltab[#walltab + 1] = 3 end | ||||||
|  | 		if string.find(verts, minetest.get_node({ x=pos.x+1, y=pos.y, z=pos.z   }).name) then walltab[#walltab + 1] = 2 end | ||||||
|  | 		if string.find(verts, minetest.get_node({ x=pos.x  , y=pos.y, z=pos.z-1 }).name) then walltab[#walltab + 1] = 5 end | ||||||
|  | 		if string.find(verts, minetest.get_node({ x=pos.x  , y=pos.y, z=pos.z+1 }).name) then walltab[#walltab + 1] = 4 end | ||||||
|  |  | ||||||
|  | 		if #walltab > 0 then return walltab[math.random(1, #walltab)] end | ||||||
|  |  | ||||||
|  | 	else | ||||||
|  | 		if string.find(verts, minetest.get_node({ x=pos.x-1, y=pos.y, z=pos.z   }).name) then return 3 end | ||||||
|  | 		if string.find(verts, minetest.get_node({ x=pos.x+1, y=pos.y, z=pos.z   }).name) then return 2 end | ||||||
|  | 		if string.find(verts, minetest.get_node({ x=pos.x  , y=pos.y, z=pos.z-1 }).name) then return 5 end | ||||||
|  | 		if string.find(verts, minetest.get_node({ x=pos.x  , y=pos.y, z=pos.z+1 }).name) then return 4 end | ||||||
|  | 	end | ||||||
|  | 	return nil | ||||||
|  | end | ||||||
|  |  | ||||||
|  | -- Function to search downward from the given position, looking for the first | ||||||
|  | -- node that matches the ground table.  Returns the new position, or nil if | ||||||
|  | -- height limit is exceeded before finding it. | ||||||
|  |  | ||||||
|  | function biome_lib:search_downward(pos, heightlimit, ground) | ||||||
|  | 	for i = 0, heightlimit do | ||||||
|  | 		if string.find(dump(ground), minetest.get_node({x=pos.x, y=pos.y-i, z = pos.z}).name) then | ||||||
|  | 			return {x=pos.x, y=pos.y-i, z = pos.z} | ||||||
|  | 		end | ||||||
|  | 	end | ||||||
|  | 	return false | ||||||
|  | end | ||||||
|  |  | ||||||
|  | function biome_lib:find_open_side(pos) | ||||||
|  | 	if minetest.get_node({ x=pos.x-1, y=pos.y, z=pos.z }).name == "air" then | ||||||
|  | 		return {newpos = { x=pos.x-1, y=pos.y, z=pos.z }, facedir = 2} | ||||||
|  | 	end | ||||||
|  | 	if minetest.get_node({ x=pos.x+1, y=pos.y, z=pos.z }).name == "air" then | ||||||
|  | 		return {newpos = { x=pos.x+1, y=pos.y, z=pos.z }, facedir = 3} | ||||||
|  | 	end | ||||||
|  | 	if minetest.get_node({ x=pos.x, y=pos.y, z=pos.z-1 }).name == "air" then | ||||||
|  | 		return {newpos = { x=pos.x, y=pos.y, z=pos.z-1 }, facedir = 4} | ||||||
|  | 	end | ||||||
|  | 	if minetest.get_node({ x=pos.x, y=pos.y, z=pos.z+1 }).name == "air" then | ||||||
|  | 		return {newpos = { x=pos.x, y=pos.y, z=pos.z+1 }, facedir = 5} | ||||||
|  | 	end | ||||||
|  | 	return nil | ||||||
|  | end | ||||||
|  |  | ||||||
|  | -- "Record" the map chunks being generated by the core mapgen, | ||||||
|  | -- split into individual mapblocks to reduce lag | ||||||
|  |  | ||||||
|  | minetest.register_on_generated(function(minp, maxp, blockseed) | ||||||
|  | 	local timestamp = minetest.get_us_time() | ||||||
|  | 	for x = 0, 4 do | ||||||
|  | 		local minx = minp.x + x*16 | ||||||
|  | 		for y = 0, 4 do | ||||||
|  | 			local miny = minp.y + y*16 | ||||||
|  | 			for z = 0, 4 do | ||||||
|  | 				local minz = minp.z + z*16 | ||||||
|  |  | ||||||
|  | 				local bmin = {x=minx, y=miny, z=minz} | ||||||
|  | 				local bmax = {x=minx + 15, y=miny + 15, z=minz + 15} | ||||||
|  | 				biome_lib.block_log[#biome_lib.block_log + 1] = { bmin, bmax, true, timestamp } | ||||||
|  | 				biome_lib.block_log[#biome_lib.block_log + 1] = { bmin, bmax, false, timestamp } | ||||||
|  | 			end | ||||||
|  | 		end | ||||||
|  | 	end | ||||||
|  | 	biome_lib.run_block_recheck_list = true | ||||||
|  | end) | ||||||
		Reference in New Issue
	
	Block a user