mirror of
https://github.com/Uberi/Minetest-WorldEdit.git
synced 2024-12-26 18:50:40 +01:00
Many thanks to Smitje for providing a working example of roations.
Changes: fixed rotation and transposition of non-sqaure regions, makers are now moved to the new region boundaries after rotation/transposition, small consistency fixes, finally fix the /hide command.
This commit is contained in:
parent
f087c3ef71
commit
e5331d39ae
@ -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 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 y
|
||||||
//transpose x z
|
//transpose x z
|
||||||
@ -155,7 +155,7 @@ Flip the current WorldEdit region along the x/y/z/? axis.
|
|||||||
|
|
||||||
### //rotate x/y/z/? <angle>
|
### //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 x 90
|
||||||
//rotate y 180
|
//rotate y 180
|
||||||
|
@ -38,11 +38,11 @@ Duplicates the region defined by positions `pos1` and `pos2` along the `axis` ax
|
|||||||
|
|
||||||
Returns the number of nodes stacked.
|
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").
|
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)
|
### 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.
|
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).
|
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)
|
### 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`.
|
Adds a spiral at `pos` with width `width`, height `height`, space between walls `spacer`, composed of `nodename`.
|
||||||
|
|
||||||
|
Returns the number of nodes added.
|
||||||
|
|
||||||
Visualization
|
Visualization
|
||||||
-------------
|
-------------
|
||||||
Contained in visualization.lua, this module allows nodes to be visualized in different ways.
|
Contained in visualization.lua, this module allows nodes to be visualized in different ways.
|
||||||
|
@ -191,10 +191,28 @@ worldedit.stack = function(pos1, pos2, axis, count)
|
|||||||
return worldedit.volume(pos1, pos2)
|
return worldedit.volume(pos1, pos2)
|
||||||
end
|
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)
|
worldedit.transpose = function(pos1, pos2, axis1, axis2)
|
||||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
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 pos = {x=pos1.x, y=0, z=0}
|
||||||
local env = minetest.env
|
local env = minetest.env
|
||||||
while pos.x <= pos2.x do
|
while pos.x <= pos2.x do
|
||||||
@ -203,16 +221,16 @@ worldedit.transpose = function(pos1, pos2, axis1, axis2)
|
|||||||
pos.z = pos1.z
|
pos.z = pos1.z
|
||||||
while pos.z <= pos2.z do
|
while pos.z <= pos2.z do
|
||||||
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 compare(extent1, extent2) then --transpose only if below the diagonal
|
||||||
local node1 = env:get_node(pos)
|
local node1 = env:get_node(pos)
|
||||||
local meta1 = env:get_meta(pos):to_table()
|
local meta1 = env:get_meta(pos):to_table()
|
||||||
local value1, value2 = pos[axis1], pos[axis2]
|
local value1, value2 = pos[axis1], pos[axis2] --save position values
|
||||||
pos[axis1], pos[axis2] = value1 + extent2, value2 + extent1
|
pos[axis1], pos[axis2] = pos1[axis1] + extent2, pos1[axis2] + extent1 --swap axis extents
|
||||||
local node2 = env:get_node(pos)
|
local node2 = env:get_node(pos)
|
||||||
local meta2 = env:get_meta(pos):to_table()
|
local meta2 = env:get_meta(pos):to_table()
|
||||||
env:add_node(pos, node1)
|
env:add_node(pos, node1)
|
||||||
env:get_meta(pos):from_table(meta1)
|
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:add_node(pos, node2)
|
||||||
env:get_meta(pos):from_table(meta2)
|
env:get_meta(pos):from_table(meta2)
|
||||||
end
|
end
|
||||||
@ -222,7 +240,7 @@ worldedit.transpose = function(pos1, pos2, axis1, axis2)
|
|||||||
end
|
end
|
||||||
pos.x = pos.x + 1
|
pos.x = pos.x + 1
|
||||||
end
|
end
|
||||||
return worldedit.volume(pos1, pos2)
|
return worldedit.volume(pos1, pos2), pos1, newpos2
|
||||||
end
|
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
|
--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
|
end
|
||||||
angle = angle % 360
|
angle = angle % 360
|
||||||
|
|
||||||
|
local count
|
||||||
if angle == 90 then
|
if angle == 90 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)
|
||||||
elseif angle == 180 then
|
elseif angle == 180 then
|
||||||
worldedit.flip(pos1, pos2, axis1)
|
worldedit.flip(pos1, pos2, axis1)
|
||||||
worldedit.flip(pos1, pos2, axis2)
|
count = worldedit.flip(pos1, pos2, axis2)
|
||||||
elseif angle == 270 then
|
elseif angle == 270 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)
|
||||||
end
|
end
|
||||||
return worldedit.volume(pos1, pos2)
|
return count, pos1, pos2
|
||||||
end
|
end
|
||||||
|
|
||||||
--digs a region defined by positions `pos1` and `pos2`, returning the number of nodes dug
|
--digs a region defined by positions `pos1` and `pos2`, returning the number of nodes dug
|
||||||
|
@ -115,17 +115,17 @@ minetest.register_on_punchnode(function(pos, node, puncher)
|
|||||||
worldedit.pos1[name] = pos
|
worldedit.pos1[name] = pos
|
||||||
worldedit.mark_pos1(name)
|
worldedit.mark_pos1(name)
|
||||||
worldedit.set_pos[name] = "pos2" --set position 2 on the next invocation
|
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
|
elseif worldedit.set_pos[name] == "pos1only" then --setting position 1 only
|
||||||
worldedit.pos1[name] = pos
|
worldedit.pos1[name] = pos
|
||||||
worldedit.mark_pos1(name)
|
worldedit.mark_pos1(name)
|
||||||
worldedit.set_pos[name] = nil --finished setting positions
|
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
|
elseif worldedit.set_pos[name] == "pos2" then --setting position 2
|
||||||
worldedit.pos2[name] = pos
|
worldedit.pos2[name] = pos
|
||||||
worldedit.mark_pos2(name)
|
worldedit.mark_pos2(name)
|
||||||
worldedit.set_pos[name] = nil --finished setting positions
|
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
|
end
|
||||||
end)
|
end)
|
||||||
@ -472,7 +472,14 @@ minetest.register_chatcommand("/transpose", {
|
|||||||
return
|
return
|
||||||
end
|
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")
|
minetest.chat_send_player(name, count .. " nodes transposed")
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
@ -525,7 +532,14 @@ minetest.register_chatcommand("/rotate", {
|
|||||||
return
|
return
|
||||||
end
|
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")
|
minetest.chat_send_player(name, count .. " nodes rotated")
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
@ -547,8 +561,24 @@ minetest.register_chatcommand("/dig", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_chatcommand("/hide", {
|
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>",
|
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},
|
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]
|
||||||
@ -562,8 +592,8 @@ minetest.register_chatcommand("/hide", {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local count = worldedit.hide(pos1, pos2, param)
|
local count = worldedit.suppress(pos1, pos2, param)
|
||||||
minetest.chat_send_player(name, count .. " nodes hidden")
|
minetest.chat_send_player(name, count .. " nodes suppressed")
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user