--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
--wip: copy slice by slice using schematic method in the copy axis and transfer metadata in separate loop (and if the amount is greater than the length in the axis, copy whole thing at a time)
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
--wip: move slice by slice using schematic method in the move axis and transfer metadata in separate loop (and if the amount is greater than the length in the axis, copy whole thing at a time and erase original after, using schematic method)
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
--scales the region defined by positions `pos1` and `pos2` by an factor of positive integer `factor` with `pos1` as the origin, returning the number of nodes scaled, the new scaled position 1, and the new scaled position 2
--transposes a region defined by the positions `pos1` and `pos2` between the `axis1` and `axis2` axes, returning the number of nodes transposed, the new transposed position 1, and the new transposed 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