mirror of
				https://github.com/mt-mods/plantlife_modpack.git
				synced 2025-10-31 13:55:25 +01:00 
			
		
		
		
	support avoid_nodes
This commit is contained in:
		| @@ -23,8 +23,15 @@ function pl.register_on_generate(def, plantname, index, func) | |||||||
| 		y_min = def.min_elevation, | 		y_min = def.min_elevation, | ||||||
| 		y_max = def.max_elevation, | 		y_max = def.max_elevation, | ||||||
| 		flags = def.flags, | 		flags = def.flags, | ||||||
| 		decoration = "air", | 		decoration = "air", -- spawn the decoration later | ||||||
| 	} | 	} | ||||||
|  | 	-- handle avoid_nodes (no engine support :\) | ||||||
|  | 	if def.avoid_nodes then | ||||||
|  | 		deco_def.avoid_nodes = def.avoid_nodes | ||||||
|  | 		if def.avoid_radius then | ||||||
|  | 			deco_def.avoid_radius = def.avoid_radius | ||||||
|  | 		end | ||||||
|  | 	end | ||||||
| 	-- handle near_nodes (we can't use the engine function for that) | 	-- handle near_nodes (we can't use the engine function for that) | ||||||
| 	if def.near_nodes then | 	if def.near_nodes then | ||||||
| 		deco_def.near_nodes = def.near_nodes | 		deco_def.near_nodes = def.near_nodes | ||||||
| @@ -60,6 +67,8 @@ end) | |||||||
|  |  | ||||||
| local function place_handler(t) | local function place_handler(t) | ||||||
| 	local def = pl.get_def_from_id(t.id) | 	local def = pl.get_def_from_id(t.id) | ||||||
|  | 	local p_top = {x = pos.x, y = pos.y + 1, z = pos.z} | ||||||
|  |  | ||||||
| 	-- near nodes handler | 	-- near nodes handler | ||||||
| 	if def.near_nodes and | 	if def.near_nodes and | ||||||
| 		#minetest.find_nodes_in_area( | 		#minetest.find_nodes_in_area( | ||||||
| @@ -70,6 +79,13 @@ local function place_handler(t) | |||||||
| 		return -- Long distance neighbours do not match | 		return -- Long distance neighbours do not match | ||||||
| 	end | 	end | ||||||
|  |  | ||||||
|  | 	-- avoid nodes handler | ||||||
|  | 	if def.avoid_nodes and def.avoid_radius then | ||||||
|  | 		if minetest.find_node_near(p_top, def.avoid_radius + math.random(-1.5,2), def.avoid_nodes) then | ||||||
|  | 			return | ||||||
|  | 		end | ||||||
|  | 	end | ||||||
|  |  | ||||||
| 	-- run spawn function | 	-- run spawn function | ||||||
| 	local spawn_func = def[2] | 	local spawn_func = def[2] | ||||||
| 	spawn_func(t.pos) | 	spawn_func(t.pos) | ||||||
| @@ -77,9 +93,8 @@ local function place_handler(t) | |||||||
| 	-- some fun | 	-- some fun | ||||||
| 	local player = minetest.get_player_by_name("Niklp") | 	local player = minetest.get_player_by_name("Niklp") | ||||||
| 	-- player:set_pos(t.pos) | 	-- player:set_pos(t.pos) | ||||||
| 	t.pos.y = t.pos.y + 3 |  | ||||||
| 	minetest.add_particle({ | 	minetest.add_particle({ | ||||||
| 		pos = t.pos, | 		pos = p_top, | ||||||
| 		expirationtime = 15, | 		expirationtime = 15, | ||||||
| 		playername = player:get_player_name(), | 		playername = player:get_player_name(), | ||||||
| 		glow = minetest.LIGHT_MAX, | 		glow = minetest.LIGHT_MAX, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user