diff options
| -rw-r--r-- | Chat Commands.md | 4 | ||||
| -rw-r--r-- | WorldEdit API.md | 10 | ||||
| -rw-r--r-- | worldedit/manipulations.lua | 43 | ||||
| -rw-r--r-- | worldedit_commands/init.lua | 46 | 
4 files changed, 77 insertions, 26 deletions
| diff --git a/Chat Commands.md b/Chat Commands.md index b90318b..28db902 100644 --- a/Chat Commands.md +++ b/Chat Commands.md @@ -137,7 +137,7 @@ Stack the current WorldEdit region along the x/y/z/? axis <count> times.  ### //transpose x/y/z/? x/y/z/?
 -Transpose the current WorldEdit region along the x/y/z/? and x/y/z/? axes.
 +Transpose the current WorldEdit positions and region along the x/y/z/? and x/y/z/? axes.
      //transpose x y
      //transpose x z
 @@ -155,7 +155,7 @@ Flip the current WorldEdit region along the x/y/z/? axis.  ### //rotate x/y/z/? <angle>
 -Rotate the current WorldEdit region along the x/y/z/? axis by angle <angle> (90 degree increment).
 +Rotate the current WorldEdit positions and region along the x/y/z/? axis by angle <angle> (integer multiple of 90 degrees).
      //rotate x 90
      //rotate y 180
 diff --git a/WorldEdit API.md b/WorldEdit API.md index ddf9a1e..c6f1ace 100644 --- a/WorldEdit API.md +++ b/WorldEdit API.md @@ -38,11 +38,11 @@ Duplicates the region defined by positions `pos1` and `pos2` along the `axis` ax  Returns the number of nodes stacked.
 -### count = worldedit.transpose(pos1, pos2, axis1, axis2)
 +### count, newpos1, newpos2 = worldedit.transpose(pos1, pos2, axis1, axis2)
  Transposes a region defined by the positions `pos1` and `pos2` between the `axis1` and `axis2` axes ("x" or "y" or "z").
 -Returns the number of nodes transposed.
 +Returns the number of nodes transposed, the new position 1, and the new position 2.
  ### count = worldedit.flip(pos1, pos2, axis)
 @@ -50,11 +50,11 @@ Flips a region defined by the positions `pos1` and `pos2` along the `axis` axis  Returns the number of nodes flipped.
 -### count = worldedit.rotate(pos1, pos2, angle)
 +### count, newpos2, newpos2 = worldedit.rotate(pos1, pos2, angle)
  Rotates a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise around the y axis (supporting 90 degree increments only).
 -Returns the number of nodes rotated.
 +Returns the number of nodes rotated, the new position 1, and the new position 2.
  ### count = worldedit.dig(pos1, pos2)
 @@ -100,6 +100,8 @@ Returns the number of nodes added.  Adds a spiral at `pos` with width `width`, height `height`, space between walls `spacer`, composed of `nodename`.
 +Returns the number of nodes added.
 +
  Visualization
  -------------
  Contained in visualization.lua, this module allows nodes to be visualized in different ways.
 diff --git a/worldedit/manipulations.lua b/worldedit/manipulations.lua index ad64df6..02490ff 100644 --- a/worldedit/manipulations.lua +++ b/worldedit/manipulations.lua @@ -191,10 +191,28 @@ worldedit.stack = function(pos1, pos2, axis, count)  	return worldedit.volume(pos1, pos2)
  end
 ---transposes a region defined by the positions `pos1` and `pos2` between the `axis1` and `axis2` axes, returning the number of nodes transposed
 +--transposes a region defined by the positions `pos1` and `pos2` between the `axis1` and `axis2` axes, returning the number of nodes transposed, the new position 1, and the new position 2
  worldedit.transpose = function(pos1, pos2, axis1, axis2)
  	local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
 +	local compare
 +	local extent1, extent2 = pos2[axis1] - pos1[axis1], pos2[axis2] - pos1[axis2]
 +
 +	if extent1 > extent2 then
 +		compare = function(extent1, extent2)
 +			return extent1 > extent2
 +		end
 +	else
 +		compare = function(extent1, extent2)
 +			return extent1 < extent2
 +		end
 +	end
 +
 +	--calculate the new position 2 after transposition
 +	local newpos2 = {x=pos1.x, y=pos1.y, z=pos1.z}
 +	newpos2[axis1] = pos1[axis1] + extent2
 +	newpos2[axis2] = pos1[axis2] + extent1
 +
  	local pos = {x=pos1.x, y=0, z=0}
  	local env = minetest.env
  	while pos.x <= pos2.x do
 @@ -203,16 +221,16 @@ worldedit.transpose = function(pos1, pos2, axis1, axis2)  			pos.z = pos1.z
  			while pos.z <= pos2.z do
  				local extent1, extent2 = pos[axis1] - pos1[axis1], pos[axis2] - pos1[axis2]
 -				if extent1 < extent2 then
 +				if compare(extent1, extent2) then --transpose only if below the diagonal
  					local node1 = env:get_node(pos)
  					local meta1 = env:get_meta(pos):to_table()
 -					local value1, value2 = pos[axis1], pos[axis2]
 -					pos[axis1], pos[axis2] = value1 + extent2, value2 + extent1
 +					local value1, value2 = pos[axis1], pos[axis2] --save position values
 +					pos[axis1], pos[axis2] = pos1[axis1] + extent2, pos1[axis2] + extent1 --swap axis extents
  					local node2 = env:get_node(pos)
  					local meta2 = env:get_meta(pos):to_table()
  					env:add_node(pos, node1)
  					env:get_meta(pos):from_table(meta1)
 -					pos[axis1], pos[axis2] = value1, value2
 +					pos[axis1], pos[axis2] = value1, value2 --restore position values
  					env:add_node(pos, node2)
  					env:get_meta(pos):from_table(meta2)
  				end
 @@ -222,7 +240,7 @@ worldedit.transpose = function(pos1, pos2, axis1, axis2)  		end
  		pos.x = pos.x + 1
  	end
 -	return worldedit.volume(pos1, pos2)
 +	return worldedit.volume(pos1, pos2), pos1, newpos2
  end
  --flips a region defined by the positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z"), returning the number of nodes flipped
 @@ -272,17 +290,18 @@ worldedit.rotate = function(pos1, pos2, axis, angle)  	end
  	angle = angle % 360
 +	local count
  	if angle == 90 then
 -		worldedit.transpose(pos1, pos2, axis1, axis2)
 -		worldedit.flip(pos1, pos2, axis2)
 +		worldedit.flip(pos1, pos2, axis1)
 +		count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2)
  	elseif angle == 180 then
  		worldedit.flip(pos1, pos2, axis1)
 -		worldedit.flip(pos1, pos2, axis2)
 +		count = worldedit.flip(pos1, pos2, axis2)
  	elseif angle == 270 then
 -		worldedit.transpose(pos1, pos2, axis1, axis2)
 -		worldedit.flip(pos1, pos2, axis1)
 +		worldedit.flip(pos1, pos2, axis2)
 +		count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2)
  	end
 -	return worldedit.volume(pos1, pos2)
 +	return count, pos1, pos2
  end
  --digs a region defined by positions `pos1` and `pos2`, returning the number of nodes dug
 diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index ad6dac8..4529470 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -115,17 +115,17 @@ minetest.register_on_punchnode(function(pos, node, puncher)  			worldedit.pos1[name] = pos
  			worldedit.mark_pos1(name)
  			worldedit.set_pos[name] = "pos2" --set position 2 on the next invocation
 -			minetest.chat_send_player(name, "WorldEdit region position 1 set to " .. minetest.pos_to_string(pos))
 +			minetest.chat_send_player(name, "WorldEdit position 1 set to " .. minetest.pos_to_string(pos))
  		elseif worldedit.set_pos[name] == "pos1only" then --setting position 1 only
  			worldedit.pos1[name] = pos
  			worldedit.mark_pos1(name)
  			worldedit.set_pos[name] = nil --finished setting positions
 -			minetest.chat_send_player(name, "WorldEdit region position 1 set to " .. minetest.pos_to_string(pos))
 +			minetest.chat_send_player(name, "WorldEdit position 1 set to " .. minetest.pos_to_string(pos))
  		elseif worldedit.set_pos[name] == "pos2" then --setting position 2
  			worldedit.pos2[name] = pos
  			worldedit.mark_pos2(name)
  			worldedit.set_pos[name] = nil --finished setting positions
 -			minetest.chat_send_player(name, "WorldEdit region position 2 set to " .. minetest.pos_to_string(pos))
 +			minetest.chat_send_player(name, "WorldEdit position 2 set to " .. minetest.pos_to_string(pos))
  		end
  	end
  end)
 @@ -472,7 +472,14 @@ minetest.register_chatcommand("/transpose", {  			return
  		end
 -		local count = worldedit.transpose(pos1, pos2, axis1, axis2)
 +		local count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2)
 +
 +		--reset markers to transposed positions
 +		worldedit.pos1[name] = pos1
 +		worldedit.pos2[name] = pos2
 +		worldedit.mark_pos1(name)
 +		worldedit.mark_pos2(name)
 +
  		minetest.chat_send_player(name, count .. " nodes transposed")
  	end,
  })
 @@ -525,7 +532,14 @@ minetest.register_chatcommand("/rotate", {  			return
  		end
 -		local count = worldedit.rotate(pos1, pos2, axis, angle)
 +		local count, pos1, pos2 = worldedit.rotate(pos1, pos2, axis, angle)
 +
 +		--reset markers to rotated positions
 +		worldedit.pos1[name] = pos1
 +		worldedit.pos2[name] = pos2
 +		worldedit.mark_pos1(name)
 +		worldedit.mark_pos2(name)
 +
  		minetest.chat_send_player(name, count .. " nodes rotated")
  	end,
  })
 @@ -547,8 +561,24 @@ minetest.register_chatcommand("/dig", {  })
  minetest.register_chatcommand("/hide", {
 +	params = "",
 +	description = "Hide all nodes in the current WorldEdit region non-destructively",
 +	privs = {worldedit=true},
 +	func = function(name, param)
 +		local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
 +		if pos1 == nil or pos2 == nil then
 +			minetest.chat_send_player(name, "No WorldEdit region selected")
 +			return
 +		end
 +
 +		local count = worldedit.hide(pos1, pos2)
 +		minetest.chat_send_player(name, count .. " nodes hidden")
 +	end,
 +})
 +
 +minetest.register_chatcommand("/suppress", {
  	params = "<node>",
 -	description = "Hide all <node> in the current WorldEdit region non-destructively",
 +	description = "Suppress all <node> in the current WorldEdit region non-destructively",
  	privs = {worldedit=true},
  	func = function(name, param)
  		local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
 @@ -562,8 +592,8 @@ minetest.register_chatcommand("/hide", {  			return
  		end
 -		local count = worldedit.hide(pos1, pos2, param)
 -		minetest.chat_send_player(name, count .. " nodes hidden")
 +		local count = worldedit.suppress(pos1, pos2, param)
 +		minetest.chat_send_player(name, count .. " nodes suppressed")
  	end,
  })
 | 
