From 6bab328d2b28023885d0d924cca762cf41db1fd6 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Tue, 27 Oct 2015 09:13:51 +0100 Subject: [PATCH 1/5] Added 6D facedir management and changed rotate and flip behavior concerning orientation --- ChatCommands.md | 11 +- WorldEdit API.md | 4 +- worldedit/manipulations.lua | 177 ++++++++++++++++++++++---------- worldedit_commands/init.lua | 16 ++- worldedit_gui/functionality.lua | 20 +++- 5 files changed, 154 insertions(+), 74 deletions(-) diff --git a/ChatCommands.md b/ChatCommands.md index 0c8b3a1..256f941 100644 --- a/ChatCommands.md +++ b/ChatCommands.md @@ -276,14 +276,13 @@ Rotate the current WorldEdit positions and region along the x/y/z/? axis by angl //rotate z 270 //rotate ? -90 -### `//orient ` +### `//orient ` -Rotate oriented nodes in the current WorldEdit region around the Y axis by angle `` (90 degree increment) +Change orientation of all oriented nodes in the current WorldEdit region performing (rotate or flip) around the axis by angle (90 degree increment, unused for flip operation). - //orient 90 - //orient 180 - //orient 270 - //orient -90 + //orient rotate x 90 + //orient rotate y -90 + //orient flip x 0 ### `//fixlight` diff --git a/WorldEdit API.md b/WorldEdit API.md index f50b506..ce7c978 100644 --- a/WorldEdit API.md +++ b/WorldEdit API.md @@ -87,9 +87,9 @@ Rotates a region defined by the positions `pos1` and `pos2` by `angle` degrees c Returns the number of nodes rotated, the new position 1, and the new position 2. -### count = worldedit.orient(pos1, pos2, angle) +### count = worldedit.orient(pos1, pos2, operation, axis, angle) -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. +Change orientation of all oriented nodes in a region defined by the positions `pos1` and `pos2` performing `operation` (rotate or flip) around the `axis` axis by angle `angle` (90 degree increment, unused for flip operation) Returns the number of nodes oriented. diff --git a/worldedit/manipulations.lua b/worldedit/manipulations.lua index 365d7b3..3abd20c 100644 --- a/worldedit/manipulations.lua +++ b/worldedit/manipulations.lua @@ -4,6 +4,56 @@ local mh = worldedit.manip_helpers +local facedir_substitutions = { + ['flip'] = { + ['x'] = {[0]=0, 3, 2, 1, 4, 5, 6, 7, 8, 11, 10, 9, 16, 19, 18, 17, 12, 15, 14, 13, 20, 23, 22, 21}, + ['y'] = {[0]=20, 23, 22, 21, 6, 5, 4, 7, 10, 9, 8, 11, 12, 15, 14, 13, 16, 19, 18, 17, 0, 3, 2, 1}, + ['z'] = {[0]=2, 1, 0, 3, 10, 9, 8, 11, 6, 5, 4, 7, 14, 13, 12, 15, 18, 17, 16, 19, 22, 21, 20, 23} + }, + ['rotate'] = { + ['x'] = { + [90] = {[0]=8, 9, 10, 11, 0, 1, 2, 3, 22, 23, 20, 21, 15, 12, 13, 14, 17, 18, 19, 16, 6, 7, 4, 5}, + [180] = {[0]=22, 23, 20, 21, 8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 12, 13, 18, 19, 16, 17, 2, 3, 0, 1}, + [270] = {[0]=4, 5, 6, 7, 22, 23, 20, 21, 0, 1, 2, 3, 13, 14, 15, 12, 19, 16, 17, 18, 10, 11, 8, 9} + }, + ['y'] = { + [90] = {[0]=1, 2, 3, 0, 13, 14, 15, 12, 17, 18, 18, 16, 9, 10, 11, 8, 5, 6, 7, 4, 23, 20, 21, 22}, + [180] = {[0]=2, 3, 0, 1, 10, 11, 8, 9, 6, 7, 7, 5, 18, 18, 16, 17, 14, 15, 12, 13, 22, 23, 20, 21}, + [270] = {[0]=3, 0, 1, 2, 18, 16, 17, 18, 15, 12, 12, 14, 7, 7, 5, 6, 11, 8, 9, 10, 21, 22, 23, 20} + }, + ['z'] = { + [90] = {[0]=12, 13, 14, 15, 7, 4, 5, 6, 9, 10, 11, 8, 20, 21, 22, 23, 0, 1, 2, 3, 16, 17, 18, 19}, + [180] = {[0]=20, 21, 22, 23, 6, 7, 4, 5, 10, 11, 8, 9, 16, 17, 18, 19, 12, 13, 14, 15, 0, 1, 2, 3}, + [270] = {[0]=16, 17, 18, 19, 5, 6, 7, 4, 11, 8, 9, 10, 0, 1, 2, 3, 20, 21, 22, 23, 12, 13, 14, 15} + } + } +} + +local wallmounted_substitutions = { + ['flip'] = { + ['x'] = {[0]=1, 0, 3, 2, 4, 5}, + ['y'] = {[0]=0, 1, 2, 3, 4, 5}, + ['z'] = {[0]=0, 1, 2, 3, 5, 4} + }, + ['rotate'] = { + ['x'] = { + [90] = {[0]=5, 4, 2, 3, 0, 1}, + [180] = {[0]=1, 0, 2, 3, 5, 4}, + [270] = {[0]=4, 5, 2, 3, 1, 0} + }, + ['y'] = { + [90] = {[0]=0, 1, 5, 4, 2, 3}, + [180] = {[0]=0, 1, 3, 2, 5, 4}, + [270] = {[0]=0, 1, 4, 5, 3, 2} + }, + ['z'] = { + [90] = {[0]=2, 3, 1, 0, 4, 5}, + [180] = {[0]=1, 0, 3, 2, 4, 5}, + [270] = {[0]=3, 2, 0, 1, 4, 5} + } + } +} + --- Sets a region to `node_names`. -- @param pos1 -- @param pos2 @@ -336,7 +386,6 @@ function worldedit.stretch(pos1, pos2, stretch_x, stretch_y, stretch_z) return worldedit.volume(pos1, pos2) * stretch_x * stretch_y * stretch_z, pos1, new_pos2 end - --- Transposes a region between two axes. -- @return The number of nodes transposed. -- @return The new transposed position 1. @@ -399,9 +448,9 @@ function worldedit.transpose(pos1, pos2, axis1, axis2) end ---- Flips a region along `axis`. +--- Flips a region along `axis`. Flips only nodes, no change on nodes orientations -- @return The number of nodes flipped. -function worldedit.flip(pos1, pos2, axis) +function worldedit.flipnodes(pos1, pos2, axis) local pos1, pos2 = worldedit.sort_pos(pos1, pos2) worldedit.keep_loaded(pos1, pos2) @@ -437,68 +486,42 @@ function worldedit.flip(pos1, pos2, axis) return worldedit.volume(pos1, pos2) end - ---- Rotates a region clockwise around an axis. --- @param pos1 --- @param pos2 --- @param axis Axis ("x", "y", or "z"). --- @param angle Angle in degrees (90 degree increments only). --- @return The number of nodes rotated. --- @return The new first position. --- @return The new second position. -function worldedit.rotate(pos1, pos2, axis, angle) - local pos1, pos2 = worldedit.sort_pos(pos1, pos2) - - local other1, other2 = worldedit.get_axis_others(axis) - angle = angle % 360 - - local count - if angle == 90 then - worldedit.flip(pos1, pos2, other1) - count, pos1, pos2 = worldedit.transpose(pos1, pos2, other1, other2) - elseif angle == 180 then - worldedit.flip(pos1, pos2, other1) - count = worldedit.flip(pos1, pos2, other2) - elseif angle == 270 then - worldedit.flip(pos1, pos2, other2) - count, pos1, pos2 = worldedit.transpose(pos1, pos2, other1, other2) - else - error("Only 90 degree increments are supported!") - end - return count, pos1, pos2 -end - - ---- Rotates all oriented nodes in a region clockwise around the Y axis. +--- Change orientation of all oriented nodes in a region. -- @param pos1 -- @param pos2 +-- @param operation Kind of operation : flip or rotate. +-- @param axis Orientation axis : x, y or z -- @param angle Angle in degrees (90 degree increments only). -- @return The number of nodes oriented. --- TODO: Support 6D facedir rotation along arbitrary axis. -function worldedit.orient(pos1, pos2, angle) +--- TODO : When flipping, try to manage diametral symetric nodes (should be rotated instead of flipped) +function worldedit.orient(pos1, pos2, operation, axis, angle) local pos1, pos2 = worldedit.sort_pos(pos1, pos2) local registered_nodes = minetest.registered_nodes - local wallmounted = { - [90] = {[0]=0, 1, 5, 4, 2, 3}, - [180] = {[0]=0, 1, 3, 2, 5, 4}, - [270] = {[0]=0, 1, 4, 5, 3, 2} - } - local facedir = { - [90] = {[0]=1, 2, 3, 0}, - [180] = {[0]=2, 3, 0, 1}, - [270] = {[0]=3, 0, 1, 2} - } + if axis ~= 'x' and axis ~= 'y' and axis ~= 'z' then + error("Axis should be 'x', 'y' or 'z'!") + end - angle = angle % 360 - if angle == 0 then - return 0 + local facedir_substitution + local wallmounted_substitution + + if operation == "rotate" then + angle = angle % 360 + if angle == 0 then + return + else + if angle % 90 ~= 0 then + error("Only 90 degree increments are supported!") + end + facedir_substitution = facedir_substitutions[operation][axis][angle] + wallmounted_substitution = wallmounted_substitutions[operation][axis][angle] + end + elseif operation == "flip" then + facedir_substitution = facedir_substitutions[operation][axis] + wallmounted_substitution = wallmounted_substitutions[operation][axis] + else + error("Operation should be 'rotate' or 'flip'!") end - if angle % 90 ~= 0 then - error("Only 90 degree increments are supported!") - end - local wallmounted_substitution = wallmounted[angle] - local facedir_substitution = facedir[angle] worldedit.keep_loaded(pos1, pos2) @@ -537,6 +560,48 @@ function worldedit.orient(pos1, pos2, angle) return count end +--- Rotates a region clockwise around an axis. Oriented nodes are rotated accordingly. +-- @param pos1 +-- @param pos2 +-- @param axis Axis ("x", "y", or "z"). +-- @param angle Angle in degrees (90 degree increments only). +-- @return The number of nodes rotated. +-- @return The new first position. +-- @return The new second position. +function worldedit.rotate(pos1, pos2, axis, angle) + local pos1, pos2 = worldedit.sort_pos(pos1, pos2) + + local other1, other2 = worldedit.get_axis_others(axis) + angle = angle % 360 + + local count + if angle == 90 then + worldedit.flipnodes(pos1, pos2, other1) + count, pos1, pos2 = worldedit.transpose(pos1, pos2, other1, other2) + elseif angle == 180 then + worldedit.flipnodes(pos1, pos2, other1) + count = worldedit.flipnodes(pos1, pos2, other2) + elseif angle == 270 then + worldedit.flipnodes(pos1, pos2, other2) + count, pos1, pos2 = worldedit.transpose(pos1, pos2, other1, other2) + else + error("Only 90 degree increments are supported!") + end + worldedit.orient(pos1, pos2, "rotate", axis, angle) + return count, pos1, pos2 +end + +--- Flips a region along `axis`. Oriented nodes are flipped accordingly. +-- @param pos1 +-- @param pos2 +-- @param axis Axis ("x", "y", or "z"). +-- @return The number of nodes flipped. +function worldedit.flip(pos1, pos2, axis) + local count + count = worldedit.flipnodes(pos1, pos2, axis) + worldedit.orient(pos1, pos2, "flip", axis, 0) + return count +end --- Attempts to fix the lighting in a region. -- @return The number of nodes updated. diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index 83a127e..5e3b4ed 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -806,20 +806,26 @@ minetest.register_chatcommand("/rotate", { }) minetest.register_chatcommand("/orient", { - params = "", - description = "Rotate oriented nodes in the current WorldEdit region around the Y axis by angle (90 degree increment)", + params = " ", + description = "Change orientation of all oriented nodes in the current WorldEdit region performing (rotate or flip) around the axis by angle (90 degree increment, unused for flip operation)", privs = {worldedit=true}, func = safe_region(function(name, param) - local found, _, angle = param:find("^([+-]?%d+)$") - local count = worldedit.orient(worldedit.pos1[name], worldedit.pos2[name], angle) + local found, _, operation, axis, angle = param:find("^(.+)%s+([xyz%?])%s+([+-]?%d+)$") + if axis == "?" then axis = worldedit.player_axis(name) end + local count = worldedit.orient(worldedit.pos1[name], worldedit.pos2[name], operation, axis, angle) worldedit.player_notify(name, count .. " nodes oriented") end, function(name, param) - local found, _, angle = param:find("^([+-]?%d+)$") + local found, _, operation, axis, angle = param:find("^(.+)%s+([xyz%?])%s+([+-]?%d+)$") if found == nil then worldedit.player_notify(name, "invalid usage: " .. param) return nil end + if operation ~= 'flip' and operation ~= 'rotate' then + worldedit.player_notify(name, "invalid usage: operation must be flip or rotate") + return nil + end + if angle % 90 ~= 0 then worldedit.player_notify(name, "invalid usage: angle must be multiple of 90") return nil diff --git a/worldedit_gui/functionality.lua b/worldedit_gui/functionality.lua index 989c9eb..fb6e9f3 100644 --- a/worldedit_gui/functionality.lua +++ b/worldedit_gui/functionality.lua @@ -10,10 +10,10 @@ local gui_count1 = {} --mapping of player names to a quantity (arbitrary strings local gui_count2 = {} --mapping of player names to a quantity (arbitrary strings may also appear as values) local gui_count3 = {} --mapping of player names to a quantity (arbitrary strings may also appear as values) local gui_angle = {} --mapping of player names to an angle (one of 90, 180, 270, representing the angle in degrees clockwise) +local gui_operation = {} -- mapping of player names to operations (flip or rotate, see orient command) local gui_filename = {} --mapping of player names to file names (arbitrary strings may also appear as values) local gui_formspec = {} --mapping of player names to formspecs local gui_code = {} --mapping of player names to formspecs - --set default values setmetatable(gui_nodename1, {__index = function() return "Cobblestone" end}) setmetatable(gui_nodename2, {__index = function() return "Stone" end}) @@ -26,6 +26,7 @@ setmetatable(gui_count1, {__index = function() return "3" end}) setmetatable(gui_count2, {__index = function() return "6" end}) setmetatable(gui_count3, {__index = function() return "4" end}) setmetatable(gui_angle, {__index = function() return 90 end}) +setmetatable(gui_operation, {__index = function() return 1 end}) setmetatable(gui_filename, {__index = function() return "building" end}) setmetatable(gui_formspec, {__index = function() return "size[5,5]\nlabel[0,0;Hello, world!]" end}) setmetatable(gui_code, {__index = function() return "minetest.chat_send_player(\"singleplayer\", \"Hello, world!\")" end}) @@ -40,6 +41,11 @@ local angle_values = {90, 180, 270} setmetatable(angle_indices, {__index = function () return 1 end}) setmetatable(angle_values, {__index = function () return 90 end}) +local operation_indices = {["Rotate"]=1, ["Flip"]=2} +local operation_values = {"rotate", "flip"} +setmetatable(operation_indices, {__index = function () return 1 end}) +setmetatable(operation_values, {__index = function () return "rotate" end}) + --given multiple sets of privileges, produces a single set of privs that would have the same effect as requiring all of them at the same time local combine_privs = function(...) local result = {} @@ -486,18 +492,22 @@ end) worldedit.register_gui_function("worldedit_gui_orient", { name = "Orient", privs = minetest.chatcommands["/orient"].privs, get_formspec = function(name) - local angle = gui_angle[name] - return "size[5,3]" .. worldedit.get_formspec_header("worldedit_gui_orient") .. - string.format("dropdown[0,1;2.5;worldedit_gui_orient_angle;90 degrees,180 degrees,270 degrees;%s]", angle) .. + local operation, axis, angle = gui_operation[name], gui_axis1[name], gui_angle[name] + return "size[8.5,3]" .. worldedit.get_formspec_header("worldedit_gui_orient") .. + string.format("dropdown[0,1;2.5;worldedit_gui_orient_operation;Rotate,Flip;%d]", operation) .. + string.format("dropdown[3,1;2.5;worldedit_gui_orient_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) .. + string.format("dropdown[6,1;2.5;worldedit_gui_orient_angle;90 degrees,180 degrees,270 degrees;%s]", angle) .. "button_exit[0,2.5;3,0.8;worldedit_gui_orient_submit;Orient]" end, }) worldedit.register_gui_handler("worldedit_gui_orient", function(name, fields) if fields.worldedit_gui_orient_submit then + gui_operation[name] = operation_indices[fields.worldedit_gui_orient_operation] + gui_axis1[name] = axis_indices[fields.worldedit_gui_orient_axis] gui_angle[name] = angle_indices[fields.worldedit_gui_orient_angle] worldedit.show_page(name, "worldedit_gui_orient") - minetest.chatcommands["/orient"].func(name, angle_values[gui_angle[name]]) + minetest.chatcommands["/orient"].func(name, string.format("%s %s %s", operation_values[gui_operation[name]], axis_values[gui_axis1[name]], angle_values[gui_angle[name]])) return true end return false From 80f013f973c34583732ba4f51090030d33068af9 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Wed, 28 Oct 2015 09:10:46 +0100 Subject: [PATCH 2/5] Renamed flipnodes to flip_nodes and some changes in comments --- worldedit/manipulations.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/worldedit/manipulations.lua b/worldedit/manipulations.lua index 3abd20c..67984f0 100644 --- a/worldedit/manipulations.lua +++ b/worldedit/manipulations.lua @@ -450,7 +450,7 @@ end --- Flips a region along `axis`. Flips only nodes, no change on nodes orientations -- @return The number of nodes flipped. -function worldedit.flipnodes(pos1, pos2, axis) +function worldedit.flip_nodes(pos1, pos2, axis) local pos1, pos2 = worldedit.sort_pos(pos1, pos2) worldedit.keep_loaded(pos1, pos2) @@ -489,11 +489,11 @@ end --- Change orientation of all oriented nodes in a region. -- @param pos1 -- @param pos2 --- @param operation Kind of operation : flip or rotate. --- @param axis Orientation axis : x, y or z +-- @param operation Kind of operation: flip or rotate. +-- @param axis Orientation axis: x, y or z -- @param angle Angle in degrees (90 degree increments only). -- @return The number of nodes oriented. ---- TODO : When flipping, try to manage diametral symetric nodes (should be rotated instead of flipped) +--- TODO: When flipping, try to manage diametral symetric nodes (should be rotated instead of flipped) function worldedit.orient(pos1, pos2, operation, axis, angle) local pos1, pos2 = worldedit.sort_pos(pos1, pos2) local registered_nodes = minetest.registered_nodes @@ -576,13 +576,13 @@ function worldedit.rotate(pos1, pos2, axis, angle) local count if angle == 90 then - worldedit.flipnodes(pos1, pos2, other1) + worldedit.flip_nodes(pos1, pos2, other1) count, pos1, pos2 = worldedit.transpose(pos1, pos2, other1, other2) elseif angle == 180 then - worldedit.flipnodes(pos1, pos2, other1) - count = worldedit.flipnodes(pos1, pos2, other2) + worldedit.flip_nodes(pos1, pos2, other1) + count = worldedit.flip_nodes(pos1, pos2, other2) elseif angle == 270 then - worldedit.flipnodes(pos1, pos2, other2) + worldedit.flip_nodes(pos1, pos2, other2) count, pos1, pos2 = worldedit.transpose(pos1, pos2, other1, other2) else error("Only 90 degree increments are supported!") @@ -598,7 +598,7 @@ end -- @return The number of nodes flipped. function worldedit.flip(pos1, pos2, axis) local count - count = worldedit.flipnodes(pos1, pos2, axis) + count = worldedit.flip_nodes(pos1, pos2, axis) worldedit.orient(pos1, pos2, "flip", axis, 0) return count end From 3673d9bf5ea18071b547337437259752955b50ee Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Thu, 29 Oct 2015 10:13:03 +0100 Subject: [PATCH 3/5] Fix rotate y 180 facedir substitutions --- worldedit/manipulations.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/worldedit/manipulations.lua b/worldedit/manipulations.lua index 67984f0..740efa4 100644 --- a/worldedit/manipulations.lua +++ b/worldedit/manipulations.lua @@ -17,9 +17,9 @@ local facedir_substitutions = { [270] = {[0]=4, 5, 6, 7, 22, 23, 20, 21, 0, 1, 2, 3, 13, 14, 15, 12, 19, 16, 17, 18, 10, 11, 8, 9} }, ['y'] = { - [90] = {[0]=1, 2, 3, 0, 13, 14, 15, 12, 17, 18, 18, 16, 9, 10, 11, 8, 5, 6, 7, 4, 23, 20, 21, 22}, - [180] = {[0]=2, 3, 0, 1, 10, 11, 8, 9, 6, 7, 7, 5, 18, 18, 16, 17, 14, 15, 12, 13, 22, 23, 20, 21}, - [270] = {[0]=3, 0, 1, 2, 18, 16, 17, 18, 15, 12, 12, 14, 7, 7, 5, 6, 11, 8, 9, 10, 21, 22, 23, 20} + [90] = {[0]=1, 2, 3, 0, 13, 14, 15, 12, 17, 18, 19, 16, 9, 10, 11, 8, 5, 6, 7, 4, 23, 20, 21, 22}, + [180] = {[0]=2, 3, 0, 1, 10, 11, 8, 9, 6, 7, 4, 5, 18, 19, 16, 17, 14, 15, 12, 13, 22, 23, 20, 21}, + [270] = {[0]=3, 0, 1, 2, 19, 16, 17, 18, 15, 12, 13, 14, 7, 4, 5, 6, 11, 8, 9, 10, 21, 22, 23, 20} }, ['z'] = { [90] = {[0]=12, 13, 14, 15, 7, 4, 5, 6, 9, 10, 11, 8, 20, 21, 22, 23, 0, 1, 2, 3, 16, 17, 18, 19}, From 44ada256d59a4c10583e13b45ec680e76aed76b8 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Wed, 4 Nov 2015 13:16:37 +0100 Subject: [PATCH 4/5] Add diagonal symetric node flip management and some rotation fixes --- worldedit/init.lua | 3 ++ worldedit/manipulations.lua | 88 +++++++++++++++++++++++++++++++++++-- 2 files changed, 87 insertions(+), 4 deletions(-) diff --git a/worldedit/init.lua b/worldedit/init.lua index e193454..47a41eb 100644 --- a/worldedit/init.lua +++ b/worldedit/init.lua @@ -42,3 +42,6 @@ if minetest.setting_getbool("log_mods") then print("[WorldEdit] Loaded!") end +-- Once every mods loaded, gather diagonal nodes +minetest.after(1, worldedit.load_diag_nodes_inventory) + diff --git a/worldedit/manipulations.lua b/worldedit/manipulations.lua index 740efa4..e79137c 100644 --- a/worldedit/manipulations.lua +++ b/worldedit/manipulations.lua @@ -1,14 +1,21 @@ --- Generic node manipulations. -- @module worldedit.manipulations -local mh = worldedit.manip_helpers +-- List of diagonal symetric nodes. Node name as key +worldedit.diagonal_nodes = {} +local mh = worldedit.manip_helpers local facedir_substitutions = { ['flip'] = { - ['x'] = {[0]=0, 3, 2, 1, 4, 5, 6, 7, 8, 11, 10, 9, 16, 19, 18, 17, 12, 15, 14, 13, 20, 23, 22, 21}, + ['x'] = {[0]=0, 3, 2, 1, 4, 7, 6, 5, 8, 11, 10, 9, 16, 19, 18, 17, 12, 15, 14, 13, 20, 23, 22, 21}, ['y'] = {[0]=20, 23, 22, 21, 6, 5, 4, 7, 10, 9, 8, 11, 12, 15, 14, 13, 16, 19, 18, 17, 0, 3, 2, 1}, - ['z'] = {[0]=2, 1, 0, 3, 10, 9, 8, 11, 6, 5, 4, 7, 14, 13, 12, 15, 18, 17, 16, 19, 22, 21, 20, 23} + ['z'] = {[0]=2, 1, 0, 3, 10, 9, 8, 11, 6, 5, 4, 7, 14, 13, 12, 15, 18, 17, 16, 19, 22, 21, 20, 23}, + ['diag'] = { + ['x'] = {[0]=1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 17, 16, 19, 18, 13, 12, 15, 14, 21, 20, 23, 22}, + ['y'] = {[0]=21, 20, 23, 22, 7, 6, 5, 4, 11, 10, 9, 8, 13, 12, 15, 14, 17, 16, 19, 18, 1, 0, 3, 2}, + ['z'] = {[0]=3, 2, 1, 0, 11, 10, 9, 8, 7, 6, 5, 4, 15, 14, 13, 12, 19, 18, 17, 16, 23, 22, 21, 20}, + } }, ['rotate'] = { ['x'] = { @@ -544,7 +551,11 @@ function worldedit.orient(pos1, pos2, operation, axis, angle) get_meta(pos):from_table(meta) count = count + 1 elseif def.paramtype2 == "facedir" then - node.param2 = facedir_substitution[node.param2] + if operation == 'flip' and worldedit.diagonal_nodes[node.name] then + node.param2 = facedir_substitutions[operation]['diag'][axis][node.param2] + else + node.param2 = facedir_substitution[node.param2] + end local meta = get_meta(pos):to_table() set_node(pos, node) get_meta(pos):from_table(meta) @@ -660,3 +671,72 @@ function worldedit.clear_objects(pos1, pos2) return count end +function worldedit.load_diag_nodes_inventory () + + -- Moreblocks / Circular saw nodes + local circular_saw_diag_names = { + 'micro_%s_1', 'micro_%s_2', 'micro_%s_4', 'micro_%s', 'micro_%s_12', 'micro_%s_14', 'micro_%s_15', + 'stair_%s_outer', 'stair_%s_inner', + 'slope_%s_outer', 'slope_%s_outer_half', 'slope_%s_outer_half_raised', + 'slope_%s_inner', 'slope_%s_inner_half', 'slope_%s_inner_half_raised', + 'slope_%s_inner_cut', 'slope_%s_inner_cut_half', 'slope_%s_inner_cut_half_raised', + 'slope_%s_outer_cut', 'slope_%s_outer_cut_half', 'slope_%s_outer_cut_half_raised', + 'slope_%s_cut'} + + if circular_saw then + for _, name_parts in ipairs(circular_saw.known_nodes) do + for _, name_format in ipairs(circular_saw_diag_names) do + local modname = name_parts[1] or "" + local material = name_parts[2] or "" + local name = modname..":"..string.format(name_format, material) + worldedit.diagonal_nodes[name] = name + end + end + end + + -- Homedecor roof blocks + if minetest.get_modpath("homedecor") then + local homedecor_nodes = { + "shingle_outer_corner_wood", "shingle_outer_corner_asphalt", + "shingle_outer_corner_terracotta", "shingle_inner_corner_wood", + "shingle_inner_corner_asphalt", "shingle_inner_corner_terracotta" + } + for _, name in ipairs(homedecor_nodes) do + worldedit.diagonal_nodes["homedecor:"..name] = "homedecor"..name + end + end + + -- Trunks roof blocks + if minetest.get_modpath("trunks") then + worldedit.diagonal_nodes["trunks:twigs_roof_corner"] = "trunks:twigs_roof_corner" + worldedit.diagonal_nodes["trunks:twigs_roof_corner_2"] = "trunks:twigs_roof_corner_2" + end + + -- Dryplants roof blocks + if minetest.get_modpath("dryplants") then + worldedit.diagonal_nodes["dryplants:reed_roof_corner"] = "dryplants:reed_roof_corner" + worldedit.diagonal_nodes["dryplants:reed_roof_corner_2"] = "dryplants:reed_roof_corner_2" + worldedit.diagonal_nodes["dryplants:wetreed_roof_corner"] = "dryplants:wetreed_roof_corner" + worldedit.diagonal_nodes["dryplants:wetreed_roof_corner_2"] = "dryplants:wetreed_roof_corner_2" + end + + -- Technics CNC nodes + if minetest.get_modpath("technic") then + local cnc_materials = { + "default:dirt", "default:wood", "default:stone", "default:cobble", + "default:brick", "default:sandstone", "default:leaves", "default:tree", + "default:steelblock", "default:bronzeblock", + "technic:stainless_steel_block", "technic:marble", "technic:granite"} + + local cnc_suffixes = { + "_technic_cnc_slope_inner_edge", "_technic_cnc_slope_inner_edge_upsdown", + "_technic_cnc_slope_edge_upsdown", "_technic_cnc_twocurvededge", + "_technic_cnc_element_edge_double", "_technic_cnc_element_edge"} + + for _, material in ipairs(cnc_materials) do + for _, suffix in ipairs(cnc_suffixes) do + worldedit.diagonal_nodes[material..suffix] = material..suffix + end + end + end +end From 9eb0b24566b8a2c7357d776e971a021172ccfe04 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Wed, 4 Nov 2015 13:23:32 +0100 Subject: [PATCH 5/5] Remove trailing spaces --- worldedit/manipulations.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/worldedit/manipulations.lua b/worldedit/manipulations.lua index e79137c..a69e4a0 100644 --- a/worldedit/manipulations.lua +++ b/worldedit/manipulations.lua @@ -674,14 +674,14 @@ end function worldedit.load_diag_nodes_inventory () -- Moreblocks / Circular saw nodes - local circular_saw_diag_names = { - 'micro_%s_1', 'micro_%s_2', 'micro_%s_4', 'micro_%s', 'micro_%s_12', 'micro_%s_14', 'micro_%s_15', - 'stair_%s_outer', 'stair_%s_inner', - 'slope_%s_outer', 'slope_%s_outer_half', 'slope_%s_outer_half_raised', - 'slope_%s_inner', 'slope_%s_inner_half', 'slope_%s_inner_half_raised', - 'slope_%s_inner_cut', 'slope_%s_inner_cut_half', 'slope_%s_inner_cut_half_raised', - 'slope_%s_outer_cut', 'slope_%s_outer_cut_half', 'slope_%s_outer_cut_half_raised', - 'slope_%s_cut'} + local circular_saw_diag_names = { + 'micro_%s_1', 'micro_%s_2', 'micro_%s_4', 'micro_%s', 'micro_%s_12', 'micro_%s_14', 'micro_%s_15', + 'stair_%s_outer', 'stair_%s_inner', + 'slope_%s_outer', 'slope_%s_outer_half', 'slope_%s_outer_half_raised', + 'slope_%s_inner', 'slope_%s_inner_half', 'slope_%s_inner_half_raised', + 'slope_%s_inner_cut', 'slope_%s_inner_cut_half', 'slope_%s_inner_cut_half_raised', + 'slope_%s_outer_cut', 'slope_%s_outer_cut_half', 'slope_%s_outer_cut_half_raised', + 'slope_%s_cut'} if circular_saw then for _, name_parts in ipairs(circular_saw.known_nodes) do