--transposes a region defined by the positions `pos1` and `pos2` between the `axis1` and `axis2` axes, returning the number of nodes transposed
worldedit.transpose = function(pos1, pos2, axis1, axis2)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local pos = {x=pos1.x, y=0, z=0}
local env = minetest.env
while pos.x <= pos2.x do
pos.y = pos1.y
while pos.y <= pos2.y do
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
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] = pos1[axis1] + extent2, pos1[axis2] + extent1 --This line changed
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
env:add_node(pos, node2)
env:get_meta(pos):from_table(meta2)
end
pos.z = pos.z + 1
end
pos.y = pos.y + 1
end
pos.x = pos.x + 1
end
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
worldedit.transpose = function(pos1, pos2, axis1, axis2)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
if pos2[axis1]-pos1[axis1] >= pos2[axis2]-pos1[axis2] then --new
largerOrSmaler = function(n1, n2) return n1 > n2 end --new
else --new
largerOrSmaler = function(n1, n2) return n1 < n2 end --new
end --new
local pos = {x=pos1.x, y=0, z=0}
local env = minetest.env
while pos.x <= pos2.x do
pos.y = pos1.y
while pos.y <= pos2.y do
pos.z = pos1.z
while pos.z <= pos2.z do
local extent1, extent2 = pos[axis1] - pos1[axis1], pos[axis2] - pos1[axis2]
if largerOrSmaler(extent1, extent2) then --changed
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] = pos1[axis1] + extent2, pos1[axis2] + extent1 --This line changed
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
env:add_node(pos, node2)
env:get_meta(pos):from_table(meta2)
end
pos.z = pos.z + 1
end
pos.y = pos.y + 1
end
pos.x = pos.x + 1
end
return worldedit.volume(pos1, pos2)
end
--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
worldedit.rotate = function(pos1, pos2, axis, angle)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local axis1, axis2
if axis == "x" then
axis1, axis2 = "z", "y"
elseif axis == "y" then
axis1, axis2 = "x", "z"
else --axis == "z"
axis1, axis2 = "y", "x"
end
angle = angle % 360
if angle == 90 then
worldedit.flip(pos1, pos2, axis2) --swapped
worldedit.transpose(pos1, pos2, axis1, axis2) --swapped
elseif angle == 180 then
worldedit.flip(pos1, pos2, axis1)
worldedit.flip(pos1, pos2, axis2)
elseif angle == 270 then
worldedit.flip(pos1, pos2, axis1) --swapped
worldedit.transpose(pos1, pos2, axis1, axis2) --swapped
end
return worldedit.volume(pos1, pos2)
end
Users browsing this forum: Majestic-12 [Bot] and 4 guests