mirror of
https://github.com/Uberi/Minetest-WorldEdit.git
synced 2024-12-27 03:00:40 +01:00
commit
a25a2a1fb0
@ -165,11 +165,12 @@ Flip the current WorldEdit region along the x/y/z/? axis.
|
|||||||
|
|
||||||
### //rotate
|
### //rotate
|
||||||
|
|
||||||
Rotate the current WorldEdit region around the y axis by angle <angle> (90 degree increment).
|
Rotate the current WorldEdit region around the axis <axis> by angle <angle> (90 degree increment).
|
||||||
|
|
||||||
//rotate 90
|
//rotate x 90
|
||||||
//rotate 180
|
//rotate y 180
|
||||||
//rotate 270
|
//rotate z 270
|
||||||
|
//rotate ? -90
|
||||||
|
|
||||||
### //dig
|
### //dig
|
||||||
|
|
||||||
|
@ -268,9 +268,12 @@ worldedit.copy = function(pos1, pos2, axis, amount)
|
|||||||
pos.z = pos1.z
|
pos.z = pos1.z
|
||||||
while pos.z <= pos2.z do
|
while pos.z <= pos2.z do
|
||||||
local node = env:get_node(pos)
|
local node = env:get_node(pos)
|
||||||
|
local meta1 = env:get_meta(pos):to_table()
|
||||||
local value = pos[axis]
|
local value = pos[axis]
|
||||||
pos[axis] = value + amount
|
pos[axis] = value + amount
|
||||||
env:add_node(pos, node)
|
env:add_node(pos, node)
|
||||||
|
local meta2 = env:get_meta(pos)
|
||||||
|
meta2:from_table(meta1)
|
||||||
pos[axis] = value
|
pos[axis] = value
|
||||||
pos.z = pos.z + 1
|
pos.z = pos.z + 1
|
||||||
end
|
end
|
||||||
@ -286,9 +289,12 @@ worldedit.copy = function(pos1, pos2, axis, amount)
|
|||||||
pos.z = pos2.z
|
pos.z = pos2.z
|
||||||
while pos.z >= pos1.z do
|
while pos.z >= pos1.z do
|
||||||
local node = minetest.env:get_node(pos)
|
local node = minetest.env:get_node(pos)
|
||||||
|
local meta1 = env:get_meta(pos):to_table()
|
||||||
local value = pos[axis]
|
local value = pos[axis]
|
||||||
pos[axis] = value + amount
|
pos[axis] = value + amount
|
||||||
minetest.env:add_node(pos, node)
|
minetest.env:add_node(pos, node)
|
||||||
|
local meta2 = env:get_meta(pos)
|
||||||
|
meta2:from_table(meta1)
|
||||||
pos[axis] = value
|
pos[axis] = value
|
||||||
pos.z = pos.z - 1
|
pos.z = pos.z - 1
|
||||||
end
|
end
|
||||||
@ -313,10 +319,13 @@ worldedit.move = function(pos1, pos2, axis, amount)
|
|||||||
pos.z = pos1.z
|
pos.z = pos1.z
|
||||||
while pos.z <= pos2.z do
|
while pos.z <= pos2.z do
|
||||||
local node = env:get_node(pos)
|
local node = env:get_node(pos)
|
||||||
|
local meta1 = env:get_meta(pos):to_table()
|
||||||
env:remove_node(pos)
|
env:remove_node(pos)
|
||||||
local value = pos[axis]
|
local value = pos[axis]
|
||||||
pos[axis] = value + amount
|
pos[axis] = value + amount
|
||||||
env:add_node(pos, node)
|
env:add_node(pos, node)
|
||||||
|
local meta2 = env:get_meta(pos)
|
||||||
|
meta2:from_table(meta1)
|
||||||
pos[axis] = value
|
pos[axis] = value
|
||||||
pos.z = pos.z + 1
|
pos.z = pos.z + 1
|
||||||
end
|
end
|
||||||
@ -331,11 +340,14 @@ worldedit.move = function(pos1, pos2, axis, amount)
|
|||||||
while pos.y >= pos1.y do
|
while pos.y >= pos1.y do
|
||||||
pos.z = pos2.z
|
pos.z = pos2.z
|
||||||
while pos.z >= pos1.z do
|
while pos.z >= pos1.z do
|
||||||
local node = minetest.env:get_node(pos)
|
local node = env:get_node(pos)
|
||||||
|
local meta1 = env:get_meta(pos):to_table()
|
||||||
env:remove_node(pos)
|
env:remove_node(pos)
|
||||||
local value = pos[axis]
|
local value = pos[axis]
|
||||||
pos[axis] = value + amount
|
pos[axis] = value + amount
|
||||||
minetest.env:add_node(pos, node)
|
env:add_node(pos, node)
|
||||||
|
local meta2 = env:get_meta(pos)
|
||||||
|
meta2:from_table(meta1)
|
||||||
pos[axis] = value
|
pos[axis] = value
|
||||||
pos.z = pos.z - 1
|
pos.z = pos.z - 1
|
||||||
end
|
end
|
||||||
@ -378,12 +390,18 @@ worldedit.transpose = function(pos1, pos2, axis1, axis2)
|
|||||||
local extent1, extent2 = pos[axis1] - pos1[axis1], pos[axis2] - pos1[axis2]
|
local extent1, extent2 = pos[axis1] - pos1[axis1], pos[axis2] - pos1[axis2]
|
||||||
if extent1 < extent2 then
|
if extent1 < extent2 then
|
||||||
local node1 = env:get_node(pos)
|
local node1 = env:get_node(pos)
|
||||||
|
local meta1a = env:get_meta(pos):to_table()
|
||||||
local value1, value2 = pos[axis1], pos[axis2]
|
local value1, value2 = pos[axis1], pos[axis2]
|
||||||
pos[axis1], pos[axis2] = pos1[axis1] + extent1, pos1[axis2] + extent2
|
pos[axis1], pos[axis2] = pos1[axis1] + extent2, pos1[axis2] + extent1
|
||||||
local node2 = env:get_node(pos)
|
local node2 = env:get_node(pos)
|
||||||
|
local meta2a = env:get_meta(pos):to_table()
|
||||||
env:add_node(pos, node1)
|
env:add_node(pos, node1)
|
||||||
pos[axis1], pos[axis2] = value1, value2
|
local meta1b = env:get_meta(pos)
|
||||||
|
meta1b:from_table(meta1a)
|
||||||
|
pos[axis1], pos[axis2] = pos1[axis1] + extent1, pos1[axis2] + extent2
|
||||||
env:add_node(pos, node2)
|
env:add_node(pos, node2)
|
||||||
|
local meta2b = env:get_meta(pos)
|
||||||
|
meta2b:from_table(meta2a)
|
||||||
end
|
end
|
||||||
pos.z = pos.z + 1
|
pos.z = pos.z + 1
|
||||||
end
|
end
|
||||||
@ -408,12 +426,18 @@ worldedit.flip = function(pos1, pos2, axis)
|
|||||||
pos.z = pos1.z
|
pos.z = pos1.z
|
||||||
while pos.z <= pos2.z do
|
while pos.z <= pos2.z do
|
||||||
local node1 = env:get_node(pos)
|
local node1 = env:get_node(pos)
|
||||||
|
local meta1a = env:get_meta(pos):to_table()
|
||||||
local value = pos[axis]
|
local value = pos[axis]
|
||||||
pos[axis] = start - value
|
pos[axis] = start - value
|
||||||
local node2 = env:get_node(pos)
|
local node2 = env:get_node(pos)
|
||||||
|
local meta2a = env:get_meta(pos):to_table()
|
||||||
env:add_node(pos, node1)
|
env:add_node(pos, node1)
|
||||||
|
local meta1b = env:get_meta(pos)
|
||||||
|
meta1b:from_table(meta1a)
|
||||||
pos[axis] = value
|
pos[axis] = value
|
||||||
env:add_node(pos, node2)
|
env:add_node(pos, node2)
|
||||||
|
local meta2b = env:get_meta(pos)
|
||||||
|
meta2b:from_table(meta2a)
|
||||||
pos.z = pos.z + 1
|
pos.z = pos.z + 1
|
||||||
end
|
end
|
||||||
pos.y = pos.y + 1
|
pos.y = pos.y + 1
|
||||||
@ -423,10 +447,17 @@ worldedit.flip = function(pos1, pos2, axis)
|
|||||||
return worldedit.volume(pos1, pos2)
|
return worldedit.volume(pos1, pos2)
|
||||||
end
|
end
|
||||||
|
|
||||||
--rotates a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise around the y axis (supporting 90 degree increments only), returning the number of nodes rotated
|
--rotates a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise (if you are looking in the negative direction) around the `axis` (supporting 90 degree increments only), returning the number of nodes rotated
|
||||||
worldedit.rotate = function(pos1, pos2, angle)
|
worldedit.rotate = function(pos1, pos2, axis, angle)
|
||||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
|
||||||
|
if axis == 'x' then
|
||||||
|
axes = {'z', 'y'}
|
||||||
|
elseif axis == 'y' then
|
||||||
|
axes = {'x', 'z'}
|
||||||
|
else--if axis == 'z' then
|
||||||
|
axes = {'y', 'x'}
|
||||||
|
end
|
||||||
angle = angle % 360
|
angle = angle % 360
|
||||||
|
|
||||||
local pos = {x=pos1.x, y=0, z=0}
|
local pos = {x=pos1.x, y=0, z=0}
|
||||||
@ -435,18 +466,14 @@ worldedit.rotate = function(pos1, pos2, angle)
|
|||||||
local env = minetest.env
|
local env = minetest.env
|
||||||
|
|
||||||
if angle == 90 then
|
if angle == 90 then
|
||||||
worldedit.transpose(pos1, pos2, "x", "z")
|
worldedit.transpose(pos1, pos2, axes[1], axes[2])
|
||||||
pos1.x, pos1.z = pos1.z, pos1.x
|
worldedit.flip(pos1, pos2, axes[2])
|
||||||
pos2.x, pos2.z = pos2.z, pos2.x
|
|
||||||
worldedit.flip(pos1, pos2, "z")
|
|
||||||
elseif angle == 180 then
|
elseif angle == 180 then
|
||||||
worldedit.flip(pos1, pos2, "x")
|
worldedit.flip(pos1, pos2, axes[1])
|
||||||
worldedit.flip(pos1, pos2, "z")
|
worldedit.flip(pos1, pos2, axes[2])
|
||||||
elseif angle == 270 then
|
elseif angle == 270 then
|
||||||
worldedit.transpose(pos1, pos2, "x", "z")
|
worldedit.transpose(pos1, pos2, axes[1], axes[2])
|
||||||
pos1.x, pos1.z = pos1.z, pos1.x
|
worldedit.flip(pos1, pos2, axes[1])
|
||||||
pos2.x, pos2.z = pos2.z, pos2.x
|
|
||||||
worldedit.flip(pos1, pos2, "x")
|
|
||||||
else
|
else
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
13
init.lua
13
init.lua
@ -410,8 +410,8 @@ minetest.register_chatcommand("/flip", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_chatcommand("/rotate", {
|
minetest.register_chatcommand("/rotate", {
|
||||||
params = "<angle>",
|
params = "<axis> <angle>",
|
||||||
description = "Rotate the current WorldEdit region around the y axis by angle <angle> (90 degree increment)",
|
description = "Rotate the current WorldEdit region around the axis <axis> by angle <angle> (90 degree increment)",
|
||||||
privs = {worldedit=true},
|
privs = {worldedit=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
||||||
@ -420,17 +420,20 @@ minetest.register_chatcommand("/rotate", {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
angle = tonumber(param)
|
local found, _, axis, angle = param:find("^([xyz%?])%s+([+-]?%d+)$")
|
||||||
if angle == nil then
|
if found == nil then
|
||||||
minetest.chat_send_player(name, "Invalid usage: " .. param)
|
minetest.chat_send_player(name, "Invalid usage: " .. param)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
if axis == "?" then
|
||||||
|
axis = worldedit.player_axis(name)
|
||||||
|
end
|
||||||
if angle % 90 ~= 0 then
|
if angle % 90 ~= 0 then
|
||||||
minetest.chat_send_player(name, "Invalid usage: angle must be multiple of 90")
|
minetest.chat_send_player(name, "Invalid usage: angle must be multiple of 90")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local count = worldedit.rotate(pos1, pos2, angle)
|
local count = worldedit.rotate(pos1, pos2, axis, angle)
|
||||||
minetest.chat_send_player(name, count .. " nodes rotated")
|
minetest.chat_send_player(name, count .. " nodes rotated")
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user