--modifies positions `pos1` and `pos2` so that each component of `pos1` is less than or equal to its corresponding conent of `pos2`, returning two new positions
worldedit.sort_pos=function(pos1,pos2)
pos1={x=pos1.x,y=pos1.y,z=pos1.z}
pos2={x=pos2.x,y=pos2.y,z=pos2.z}
ifpos1.x>pos2.xthen
pos2.x,pos1.x=pos1.x,pos2.x
end
ifpos1.y>pos2.ythen
pos2.y,pos1.y=pos1.y,pos2.y
end
ifpos1.z>pos2.zthen
pos2.z,pos1.z=pos1.z,pos2.z
end
returnpos1,pos2
end
--determines the volume of the region defined by positions `pos1` and `pos2`, returning the volume
--replaces all nodes other than `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`, returning the number of nodes replaced
--copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes, returning the number of nodes copied
worldedit.copy=function(pos1,pos2,axis,amount)
localpos1,pos2=worldedit.sort_pos(pos1,pos2)
localenv=minetest.env
ifamount<0then
localpos={x=pos1.x,y=0,z=0}
whilepos.x<=pos2.xdo
pos.y=pos1.y
whilepos.y<=pos2.ydo
pos.z=pos1.z
whilepos.z<=pos2.zdo
localnode=env:get_node(pos)--obtain current node
localmeta=env:get_meta(pos):to_table()--get meta of current node
localvalue=pos[axis]--store current position
pos[axis]=value+amount--move along axis
env:add_node(pos,node)--copy node to new position
env:get_meta(pos):from_table(meta)--set metadata of new node
pos[axis]=value--restore old position
pos.z=pos.z+1
end
pos.y=pos.y+1
end
pos.x=pos.x+1
end
else
localpos={x=pos2.x,y=0,z=0}
whilepos.x>=pos1.xdo
pos.y=pos2.y
whilepos.y>=pos1.ydo
pos.z=pos2.z
whilepos.z>=pos1.zdo
localnode=minetest.env:get_node(pos)--obtain current node
localmeta=env:get_meta(pos):to_table()--get meta of current node
localvalue=pos[axis]--store current position
pos[axis]=value+amount--move along axis
minetest.env:add_node(pos,node)--copy node to new position
env:get_meta(pos):from_table(meta)--set metadata of new node
pos[axis]=value--restore old position
pos.z=pos.z-1
end
pos.y=pos.y-1
end
pos.x=pos.x-1
end
end
returnworldedit.volume(pos1,pos2)
end
--moves the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes, returning the number of nodes moved
worldedit.move=function(pos1,pos2,axis,amount)
localpos1,pos2=worldedit.sort_pos(pos1,pos2)
localenv=minetest.env
ifamount<0then
localpos={x=pos1.x,y=0,z=0}
whilepos.x<=pos2.xdo
pos.y=pos1.y
whilepos.y<=pos2.ydo
pos.z=pos1.z
whilepos.z<=pos2.zdo
localnode=env:get_node(pos)--obtain current node
localmeta=env:get_meta(pos):to_table()--get metadata of current node
env:remove_node(pos)
localvalue=pos[axis]--store current position
pos[axis]=value+amount--move along axis
env:add_node(pos,node)--move node to new position
env:get_meta(pos):from_table(meta)--set metadata of new node
pos[axis]=value--restore old position
pos.z=pos.z+1
end
pos.y=pos.y+1
end
pos.x=pos.x+1
end
else
localpos={x=pos2.x,y=0,z=0}
whilepos.x>=pos1.xdo
pos.y=pos2.y
whilepos.y>=pos1.ydo
pos.z=pos2.z
whilepos.z>=pos1.zdo
localnode=env:get_node(pos)--obtain current node
localmeta=env:get_meta(pos):to_table()--get metadata of current node
env:remove_node(pos)
localvalue=pos[axis]--store current position
pos[axis]=value+amount--move along axis
env:add_node(pos,node)--move node to new position
env:get_meta(pos):from_table(meta)--set metadata of new node
pos[axis]=value--restore old position
pos.z=pos.z-1
end
pos.y=pos.y-1
end
pos.x=pos.x-1
end
end
returnworldedit.volume(pos1,pos2)
end
--duplicates the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") `count` times, returning the number of nodes stacked
--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
--rotates a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise around axis `axis` (90 degree increment), returning the number of nodes rotated
--rotates all oriented nodes in a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise (90 degree increment) around the Y axis, returning the number of nodes oriented