mirror of
				https://github.com/Uberi/Minetest-WorldEdit.git
				synced 2025-11-04 06:35:28 +01:00 
			
		
		
		
	Allow to bulk-set param2 of regions (#144)
This commit is contained in:
		@@ -117,6 +117,10 @@ Set the current WorldEdit region to `<node>`.
 | 
			
		||||
    //set Blue Lightstone
 | 
			
		||||
    //set dirt with grass
 | 
			
		||||
 | 
			
		||||
### `//param2 <param2>`
 | 
			
		||||
 | 
			
		||||
Set the param2 value of all nodes in the current WorldEdit region to `<param2>`.
 | 
			
		||||
 | 
			
		||||
### `//mix <node1> ...`
 | 
			
		||||
 | 
			
		||||
Fill the current WorldEdit region with a random mix of `<node1>`, `...`.
 | 
			
		||||
 
 | 
			
		||||
@@ -27,6 +27,12 @@ Sets a region defined by positions `pos1` and `pos2` to `node_name`. To clear a
 | 
			
		||||
 | 
			
		||||
Returns the number of nodes set.
 | 
			
		||||
 | 
			
		||||
### `count = worldedit.set_param2(pos1, pos2, param2)`
 | 
			
		||||
 | 
			
		||||
Sets the param2 values of all nodes in a region defined by positions `pos1` and `pos2` to `param2`.
 | 
			
		||||
 | 
			
		||||
Returns the number of nodes set.
 | 
			
		||||
 | 
			
		||||
### count = worldedit.replace(pos1, pos2, searchnode, replacenode)
 | 
			
		||||
 | 
			
		||||
Replaces all instances of `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`.
 | 
			
		||||
 
 | 
			
		||||
@@ -38,6 +38,29 @@ function worldedit.set(pos1, pos2, node_names)
 | 
			
		||||
	return worldedit.volume(pos1, pos2)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
--- Sets param2 of a region.
 | 
			
		||||
-- @param pos1
 | 
			
		||||
-- @param pos2
 | 
			
		||||
-- @param param2 Value of param2 to set
 | 
			
		||||
-- @return The number of nodes set.
 | 
			
		||||
function worldedit.set_param2(pos1, pos2, param2)
 | 
			
		||||
	pos1, pos2 = worldedit.sort_pos(pos1, pos2)
 | 
			
		||||
 | 
			
		||||
	local manip, area = mh.init(pos1, pos2)
 | 
			
		||||
	local param2_data = manip:get_param2_data()
 | 
			
		||||
 | 
			
		||||
	-- Set param2 for every node
 | 
			
		||||
	for i in area:iterp(pos1, pos2) do
 | 
			
		||||
		param2_data[i] = param2
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	-- Update map
 | 
			
		||||
	manip:set_param2_data(param2_data)
 | 
			
		||||
	manip:write_to_map()
 | 
			
		||||
	manip:update_map()
 | 
			
		||||
 | 
			
		||||
	return worldedit.volume(pos1, pos2)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
--- Replaces all instances of `search_node` with `replace_node` in a region.
 | 
			
		||||
-- When `inverse` is `true`, replaces all instances that are NOT `search_node`.
 | 
			
		||||
 
 | 
			
		||||
@@ -408,6 +408,25 @@ minetest.register_chatcommand("/set", {
 | 
			
		||||
	end, check_region),
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
minetest.register_chatcommand("/param2", {
 | 
			
		||||
	params = "<param2>",
 | 
			
		||||
	description = "Set param2 of all nodes in the current WorldEdit region to <param2>",
 | 
			
		||||
	privs = {worldedit=true},
 | 
			
		||||
	func = safe_region(function(name, param)
 | 
			
		||||
		local param2 = tonumber(param)
 | 
			
		||||
		if not param2 then
 | 
			
		||||
			worldedit.player_notify(name, "Invalid or missing param2 argument")
 | 
			
		||||
			return
 | 
			
		||||
		elseif param2 < 0 or param2 > 255 then
 | 
			
		||||
			worldedit.player_notify(name, "Param2 is out of range (must be between 0 and 255 inclusive)!")
 | 
			
		||||
			return
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		local count = worldedit.set_param2(worldedit.pos1[name], worldedit.pos2[name], param2)
 | 
			
		||||
		worldedit.player_notify(name, count .. " nodes altered")
 | 
			
		||||
	end, check_region),
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
minetest.register_chatcommand("/mix", {
 | 
			
		||||
	params = "<node1> ...",
 | 
			
		||||
	description = "Fill the current WorldEdit region with a random mix of <node1>, ...",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user