1
0
mirror of https://github.com/Uberi/Minetest-WorldEdit.git synced 2025-06-28 14:16:18 +02:00

New command: //orient, that rotates oriented nodes such as furnaces around the Y-axis by a specified angle.

This commit is contained in:
Anthony Zhang
2013-01-12 16:46:40 -05:00
parent 7cb2df24b8
commit c27ab877f1
4 changed files with 100 additions and 2 deletions

View File

@ -304,6 +304,62 @@ worldedit.rotate = function(pos1, pos2, axis, angle)
return count, pos1, pos2
end
--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
worldedit.orient = function(pos1, pos2, angle)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local nodes = minetest.registered_nodes
local env = minetest.env
local wallmounted = {
[90]={[0]=0, [1]=1, [2]=5, [3]=4, [4]=2, [5]=3},
[180]={[0]=0, [1]=1, [2]=3, [3]=2, [4]=5, [5]=4},
[270]={[0]=0, [1]=1, [2]=4, [3]=5, [4]=3, [5]=2}
}
local facedir = {
[90]={[0]=1, [1]=2, [2]=3, [3]=0},
[180]={[0]=2, [1]=3, [2]=0, [3]=1},
[270]={[0]=3, [1]=0, [2]=1, [3]=2}
}
angle = angle % 360
if angle == 0 then
return 0
end
local wallmounted_substitution = wallmounted[angle]
local facedir_substitution = facedir[angle]
local count = 0
local pos = {x=pos1.x, y=0, z=0}
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 node = env:get_node(pos)
local def = nodes[node.name]
if def then
if def.paramtype2 == "wallmounted" then
node.param2 = wallmounted_substitution[node.param2]
local meta = env:get_meta(pos):to_table()
env:add_node(pos, node)
env:get_meta(pos):from_table(meta)
count = count + 1
elseif def.paramtype2 == "facedir" then
node.param2 = facedir_substitution[node.param2]
local meta = env:get_meta(pos):to_table()
env:add_node(pos, node)
env:get_meta(pos):from_table(meta)
count = count + 1
end
end
pos.z = pos.z + 1
end
pos.y = pos.y + 1
end
pos.x = pos.x + 1
end
return count
end
--fixes the lighting in a region defined by positions `pos1` and `pos2`, returning the number of nodes updated
worldedit.fixlight = function(pos1, pos2)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)