mirror of
				https://github.com/mt-mods/plantlife_modpack.git
				synced 2025-10-30 21:35:37 +01:00 
			
		
		
		
	improve near_nodes support
This commit is contained in:
		| @@ -111,18 +111,34 @@ pl_seaweed.grow_seaweed = function(pos) | ||||
| 	minetest.swap_node(right_here, {name=node_name, param2=math.random(1,3)}) | ||||
| end | ||||
|  | ||||
| biome_lib.register_on_generate({ | ||||
| 		surface = {"default:water_source"}, | ||||
| 		max_count = seaweed_max_count, | ||||
| 		rarity = seaweed_rarity, | ||||
| 		min_elevation = 1, | ||||
| 		max_elevation = 40, | ||||
| 		near_nodes = {"default:dirt_with_grass"}, | ||||
| 		near_nodes_size = 4, | ||||
| 		near_nodes_vertical = 1, | ||||
| 		near_nodes_count = 1, | ||||
| 		plantlife_limit = -0.9, | ||||
| pl.register_on_generate({ | ||||
|         place_on = { | ||||
|             "default:water_source" | ||||
|         }, | ||||
| 		noise_params = { | ||||
| 			scale = 0.00234375, | ||||
| 			offset = 0, | ||||
| 			seed = 0, | ||||
| 			octaves = 3, | ||||
| 			lacunarity = 2, | ||||
| 			flags = "absvalue", | ||||
| 			spread = { | ||||
| 				x = 100, | ||||
| 				y = 100, | ||||
| 				z = 100 | ||||
| 			}, | ||||
| 			persist = 0.6 | ||||
| 		}, | ||||
| 		flags = "all_floors", | ||||
| 		y_min = 1, | ||||
| 		y_max = 40, | ||||
| 		near_nodes = { | ||||
|             "default:dirt_with_grass" | ||||
|         }, | ||||
|         near_nodes_size = 1 | ||||
| 	}, | ||||
| 	"pl_seaweed:water_grass", | ||||
| 	nil, | ||||
| 	pl_seaweed.grow_seaweed | ||||
| ) | ||||
|  | ||||
|   | ||||
| @@ -1,8 +1,10 @@ | ||||
| pl = {} | ||||
| local deco = {} | ||||
|  | ||||
| dofile(minetest.get_modpath("plantlife_lib") .. DIR_DELIM .. "util.lua") | ||||
|  | ||||
| function pl.get_def_from_id(id) | ||||
| 	for i, _ in pairs(deco) do | ||||
| 	for i, _ in ipairs(deco) do | ||||
| 		if deco[i][1].id and deco[i][1].id == id then | ||||
| 			return deco[i] | ||||
| 		end | ||||
| @@ -20,25 +22,33 @@ function pl.register_on_generate(def, plantname, index, func) | ||||
| 		noise_params = def.noise_params, | ||||
| 		y_min = def.min_elevation, | ||||
| 		y_max = def.max_elevation, | ||||
| 		spawn_by = def.near_nodes, | ||||
| 		num_spawn_by = def.near_nodes_count, | ||||
| 		flags = def.flags, | ||||
| 		decoration = "air", | ||||
| 		near_nodes_size = def.near_nodes_size, | ||||
| 		near_nodes_count = def.near_nodes_count, | ||||
| 	} | ||||
| 	-- handle near_nodes (we can't use the engine function for that) | ||||
| 	if def.near_nodes then | ||||
| 		deco_def.near_nodes = def.near_nodes | ||||
| 		if def.near_nodes_size then | ||||
| 			deco_def.near_nodes_size = def.near_nodes_size | ||||
| 			if def.near_nodes_vertical then | ||||
| 				deco_def.near_nodes_vertical = def.near_nodes_vertical | ||||
| 			end | ||||
| 		end | ||||
| 		deco_def.near_nodes_count = def.near_nodes_count or 1 | ||||
| 	end | ||||
| 	-- save def | ||||
| 	local next = #deco + 1 | ||||
| 	deco[next] = {} | ||||
| 	deco[next][1] = deco_def | ||||
| 	deco[next][2] = func or nil | ||||
| 	minetest.register_decoration(deco_def) | ||||
| 	print(dump(deco)) | ||||
| 	-- print(dump(deco)) | ||||
| end | ||||
|  | ||||
| local ids = {} | ||||
| minetest.register_on_mods_loaded(function() | ||||
|     -- print(dump(deco)) | ||||
|     for k, v in pairs(deco) do | ||||
|     for k, v in ipairs(deco) do | ||||
| 		local id = minetest.get_decoration_id(deco[k][1].name) | ||||
|         deco[k][1].id = id | ||||
| 		table.insert(ids, id) | ||||
| @@ -51,7 +61,7 @@ end) | ||||
| local function place_handler(t) | ||||
| 	local def = pl.get_def_from_id(t.id) | ||||
| 	-- near nodes handler | ||||
| 	if def.near_nodes_count and -- not tested yet | ||||
| 	if def.near_nodes and | ||||
| 		#minetest.find_nodes_in_area( | ||||
| 			{x = t.pos.x-def.near_nodes_size, y = t.pos.y-def.near_nodes_vertical, z = t.pos.z-def.near_nodes_size}, | ||||
| 			{x = t.pos.x+def.near_nodes_size, y = t.pos.y+def.near_nodes_vertical, z = t.pos.z+def.near_nodes_size}, | ||||
| @@ -67,6 +77,7 @@ local function place_handler(t) | ||||
| 	-- some fun | ||||
| 	local player = minetest.get_player_by_name("Niklp") | ||||
| 	-- player:set_pos(t.pos) | ||||
| 	t.pos.y = t.pos.y + 3 | ||||
| 	minetest.add_particle({ | ||||
| 		pos = t.pos, | ||||
| 		expirationtime = 15, | ||||
| @@ -78,9 +89,10 @@ local function place_handler(t) | ||||
| end | ||||
|  | ||||
| minetest.register_on_generated(function(minp, maxp, blockseed) | ||||
| 	local t0 = minetest.get_us_time() | ||||
|     local g = minetest.get_mapgen_object("gennotify") | ||||
|     local locations = {} | ||||
| 	for _, id in pairs(ids) do | ||||
| 	for _, id in ipairs(ids) do | ||||
| 		local deco_locations = g["decoration#" .. id] or {} | ||||
| 		-- print("dl: " .. dump2(deco_locations)) | ||||
| 		for k, pos in pairs(deco_locations) do | ||||
| @@ -93,10 +105,12 @@ minetest.register_on_generated(function(minp, maxp, blockseed) | ||||
| 		end | ||||
| 	end | ||||
|     if #locations == 0 then return end | ||||
| 	print("locations: " .. dump2(locations)) | ||||
| 	-- print("locations: " .. dump2(locations)) | ||||
|     for _, t in ipairs(locations) do | ||||
| 		place_handler(t) | ||||
|     end | ||||
| 	local t1 = minetest.get_us_time() | ||||
| 	print((t1 - t0) / 1000 .. " ms") | ||||
| end) | ||||
|  | ||||
| --[[ Example plant | ||||
|   | ||||
							
								
								
									
										14
									
								
								plantlife_lib/util.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								plantlife_lib/util.lua
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| -- Biome lib util functions | ||||
|  | ||||
| function pl.get_nodedef_field(nodename, fieldname) | ||||
| 	if not minetest.registered_nodes[nodename] then | ||||
| 		return nil | ||||
| 	end | ||||
| 	return minetest.registered_nodes[nodename][fieldname] | ||||
| end | ||||
|  | ||||
| if minetest.get_modpath("unified_inventory") or not minetest.settings:get_bool("creative_mode") then | ||||
| 	pl.expect_infinite_stacks = false | ||||
| else | ||||
| 	pl.expect_infinite_stacks = true | ||||
| end | ||||
| @@ -169,19 +169,35 @@ biome_lib.register_on_generate({ | ||||
| end | ||||
|  | ||||
| if Twigs_on_water == true then | ||||
| biome_lib.register_on_generate({ | ||||
|     surface = {"default:water_source"}, | ||||
|     max_count = Twigs_on_water_Max_Count, | ||||
|     rarity = Twigs_on_water_Rarity, | ||||
|     min_elevation = 1, | ||||
| 	max_elevation = 40, | ||||
| 	near_nodes = {"group:tree"}, | ||||
| 	near_nodes_size = 3, | ||||
| 	near_nodes_vertical = 1, | ||||
| 	near_nodes_count = 1, | ||||
|     plantlife_limit = -0.9, | ||||
|   }, | ||||
|   abstract_trunks.place_twig | ||||
| pl.register_on_generate({ | ||||
| 		place_on = { | ||||
| 			"default:water_source" | ||||
| 		}, | ||||
| 		noise_params = { | ||||
| 			flags = "absvalue", | ||||
| 			offset = 0, | ||||
| 			scale = 0.05, | ||||
| 			spread = { | ||||
| 				z = 100, | ||||
| 				x = 100, | ||||
| 				y = 100 | ||||
| 			}, | ||||
| 			seed = 0, | ||||
| 			octaves = 3, | ||||
| 			lacunarity = 2, | ||||
| 			persist = 0.6 | ||||
| 		}, | ||||
| 		flags = "all_floors", | ||||
| 		y_min = 1, | ||||
| 		y_max = 40, | ||||
| 		near_nodes = {"group:tree"}, | ||||
| 		near_nodes_size = 3, | ||||
| 		near_nodes_vertical = 1, | ||||
| 		near_nodes_count = 1 | ||||
| 	}, | ||||
| 	"trunks:on_water", | ||||
| 	nil, | ||||
| 	abstract_trunks.place_twig | ||||
| ) | ||||
| end | ||||
|  | ||||
| @@ -356,24 +372,43 @@ abstract_trunks.grow_moss_on_ground = function(pos) | ||||
|  | ||||
| end | ||||
|  | ||||
| biome_lib.register_on_generate({ | ||||
|     surface = {"default:dirt_with_grass"}, | ||||
|     max_count = Moss_on_ground_Max_Count, | ||||
|     rarity = Moss_on_ground_Rarity, | ||||
|     min_elevation = 1, | ||||
| 	max_elevation = 40, | ||||
| 	near_nodes = { | ||||
| 		"group:tree", | ||||
| 		"ferns:fern_03", | ||||
| 		"ferns:fern_02", | ||||
| 		"ferns:fern_01" | ||||
| pl.register_on_generate({ | ||||
|         y_max = 40, | ||||
|         flags = "all_floors", | ||||
|         deco_type = "simple", | ||||
|         place_on = { | ||||
| 			"default:dirt_with_grass" | ||||
|         }, | ||||
|         noise_params = { | ||||
| 			offset = 0, | ||||
| 			scale = 0.1, | ||||
| 			persist = 0.6, | ||||
| 			seed = 0, | ||||
| 			octaves = 3, | ||||
| 			lacunarity = 2, | ||||
| 			flags = "absvalue", | ||||
| 			spread = { | ||||
| 				x = 100, | ||||
| 				y = 100, | ||||
| 				z = 100 | ||||
| 			} | ||||
|         }, | ||||
|         flags = "all_floors", | ||||
| 		y_min = 1,  | ||||
| 		y_max = 40, | ||||
| 		near_nodes = { | ||||
| 			"group:tree", | ||||
| 			"ferns:fern_03", | ||||
| 			"ferns:fern_02", | ||||
| 			"ferns:fern_01" | ||||
| 		}, | ||||
| 		near_nodes_size = 2, | ||||
| 		near_nodes_vertical = 1, | ||||
| 		near_nodes_count = 1 | ||||
| 	}, | ||||
| 	near_nodes_size = 2, | ||||
| 	near_nodes_vertical = 1, | ||||
| 	near_nodes_count = 1, | ||||
|     plantlife_limit = -0.9, | ||||
|   }, | ||||
|   abstract_trunks.grow_moss_on_ground | ||||
| 	"trunks:on_dirt_with_grass", | ||||
| 	nil, | ||||
| 	abstract_trunks.grow_moss_on_ground | ||||
| ) | ||||
| end | ||||
|  | ||||
|   | ||||
| @@ -73,25 +73,41 @@ abstract_woodsoils.place_soil = function(pos) | ||||
| 	end | ||||
| end | ||||
|  | ||||
| biome_lib.register_on_generate({ | ||||
|     surface = { | ||||
| 		"group:tree", | ||||
| 		"ferns:fern_03", | ||||
| 		"ferns:fern_02", | ||||
| 		"ferns:fern_01" | ||||
| pl.register_on_generate({ | ||||
| 		place_on = { | ||||
| 			"group:tree", | ||||
| 			"ferns:fern_03", | ||||
| 			"ferns:fern_02", | ||||
| 			"ferns:fern_01" | ||||
| 		}, | ||||
|         noise_params = { | ||||
| 			flags = "absvalue", | ||||
| 			offset = 0, | ||||
| 			scale = 0.15625, | ||||
| 			spread = { | ||||
| 				x = 100, | ||||
| 				y = 100, | ||||
| 				z = 100 | ||||
| 			}, | ||||
| 			seed = 0, | ||||
| 			octaves = 3, | ||||
| 			persist = 0.6, | ||||
| 			lacunarity = 2 | ||||
|         }, | ||||
| 		flags = "all_floors,force_placement", | ||||
| 		y_min = 1, | ||||
|         y_max = 40, | ||||
| 		near_nodes = { | ||||
| 			"group:tree", | ||||
| 			"ferns:fern_03", | ||||
| 			"ferns:fern_02", | ||||
| 			"ferns:fern_01" | ||||
| 		}, | ||||
|         near_nodes_count = 4 | ||||
| 	}, | ||||
|     max_count = 1000, | ||||
|     rarity = 1, | ||||
|     min_elevation = 1, | ||||
| 	max_elevation = 40, | ||||
| 	near_nodes = {"group:tree","ferns:fern_03","ferns:fern_02","ferns:fern_01"}, | ||||
| 	near_nodes_size = 5, | ||||
| 	near_nodes_vertical = 1, | ||||
| 	near_nodes_count = 4, | ||||
|     plantlife_limit = -1, | ||||
|     check_air = false, | ||||
|   }, | ||||
|   "abstract_woodsoils.place_soil" | ||||
| 	"woodsoils:place_soil", | ||||
| 	nil, | ||||
| 	abstract_woodsoils.place_soil | ||||
| ) | ||||
|  | ||||
| pl.register_on_generate({ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user