From 0b01520118bdbe42b2c505522107e974711e612b Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 18 Jul 2021 12:39:48 -0700 Subject: [PATCH 01/49] sets (not working) --- worldeditadditions/init.lua | 55 +++++++++++++++++ worldeditadditions/utils/set.lua | 101 +++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 worldeditadditions/utils/set.lua diff --git a/worldeditadditions/init.lua b/worldeditadditions/init.lua index 7c4154a..e118c9f 100644 --- a/worldeditadditions/init.lua +++ b/worldeditadditions/init.lua @@ -6,6 +6,61 @@ -- @author Starbeamrainbowlabs worldeditadditions = {} +worldeditadditions.modpath = minetest.get_modpath("worldeditadditions") +dofile(worldeditadditions.modpath.."/utils/vector.lua") +worldeditadditions.Set = dofile(worldeditadditions.modpath.."/utils/set.lua") +worldeditadditions.Vector3 = dofile(worldeditadditions.modpath.."/utils/vector3.lua") +worldeditadditions.Mesh, +worldeditadditions.Face = dofile(worldeditadditions.modpath.."/utils/mesh.lua") + +worldeditadditions.Queue = dofile(worldeditadditions.modpath.."/utils/queue.lua") +worldeditadditions.LRU = dofile(worldeditadditions.modpath.."/utils/lru.lua") + + +dofile(worldeditadditions.modpath.."/utils/strings/init.lua") +dofile(worldeditadditions.modpath.."/utils/format/init.lua") +dofile(worldeditadditions.modpath.."/utils/parse/init.lua") +dofile(worldeditadditions.modpath.."/utils/tables/init.lua") + +dofile(worldeditadditions.modpath.."/utils/numbers.lua") +dofile(worldeditadditions.modpath.."/utils/nodes.lua") +dofile(worldeditadditions.modpath.."/utils/node_identification.lua") +dofile(worldeditadditions.modpath.."/utils/terrain.lua") +dofile(worldeditadditions.modpath.."/utils/raycast_adv.lua") -- For the farwand +dofile(worldeditadditions.modpath.."/utils/axes.lua") + +dofile(worldeditadditions.modpath.."/lib/compat/saplingnames.lua") + +dofile(worldeditadditions.modpath.."/lib/floodfill.lua") +dofile(worldeditadditions.modpath.."/lib/overlay.lua") +dofile(worldeditadditions.modpath.."/lib/layers.lua") +dofile(worldeditadditions.modpath.."/lib/fillcaves.lua") +dofile(worldeditadditions.modpath.."/lib/ellipsoid.lua") +dofile(worldeditadditions.modpath.."/lib/torus.lua") +dofile(worldeditadditions.modpath.."/lib/line.lua") +dofile(worldeditadditions.modpath.."/lib/walls.lua") +dofile(worldeditadditions.modpath.."/lib/replacemix.lua") +dofile(worldeditadditions.modpath.."/lib/maze2d.lua") +dofile(worldeditadditions.modpath.."/lib/maze3d.lua") +dofile(worldeditadditions.modpath.."/lib/hollow.lua") +dofile(worldeditadditions.modpath.."/lib/scale_up.lua") +dofile(worldeditadditions.modpath.."/lib/scale_down.lua") +dofile(worldeditadditions.modpath.."/lib/scale.lua") +dofile(worldeditadditions.modpath.."/lib/conv/conv.lua") +dofile(worldeditadditions.modpath.."/lib/erode/erode.lua") +dofile(worldeditadditions.modpath.."/lib/noise/init.lua") + +dofile(worldeditadditions.modpath.."/lib/count.lua") + +dofile(worldeditadditions.modpath.."/lib/bonemeal.lua") +dofile(worldeditadditions.modpath.."/lib/forest.lua") + +dofile(worldeditadditions.modpath.."/lib/ellipsoidapply.lua") +dofile(worldeditadditions.modpath.."/lib/airapply.lua") + +dofile(worldeditadditions.modpath.."/lib/subdivide.lua") +dofile(worldeditadditions.modpath.."/lib/selection/stack.lua") +dofile(worldeditadditions.modpath.."/lib/selection/cloud.lua") local wea = worldeditadditions wea.modpath = minetest.get_modpath("worldeditadditions") diff --git a/worldeditadditions/utils/set.lua b/worldeditadditions/utils/set.lua new file mode 100644 index 0000000..d5ea57d --- /dev/null +++ b/worldeditadditions/utils/set.lua @@ -0,0 +1,101 @@ +--- Sets for lua! +-- local Set = {} +--- Option 1: +-- Set.__index = Set +-- Set.__newindex = function(tbl, key, value) +-- if not tbl.__protected[key] then +-- rawset(tbl,key,value) +-- else +-- error("Protected!") +-- end +-- end +-- Set.__protected = { +-- __protected=true, +-- new=true, +-- add=true, +-- delete=true, +-- has=true +-- } + +--- Option 2: +local Set = {} +Set.__index = Set +Set.__newindex = function(tbl, key, value) + rawset(tbl.set,key,value) +end + +--- Creates a new set. +-- @param i any Initial values(s) of the set. +-- @returns Set A table of keys equal to true. +function Set.new(i) + local result = {set={}} + setmetatable(result, Set) + if type(i) == "table" then + for k,v in pairs(i) do result[v] = true end + elseif i then + result[i] = true + end + return result +end +-- a = Set.new({"add","new","thing"}) + +--- Adds item(s) to set. +-- @param a set Set to manipulate. +-- @param i not nil Values(s) to add. +-- @returns bool Success of operation. +function Set.add(a,i) + if type(i) == "table" then + for k,v in pairs(i) do a[v] = true end + else + a[i] = true + end + return true +end + +--- Deletes item(s) from set. +-- @param a set Set to manipulate. +-- @param i not nil Values(s) to delete. +-- @returns bool Success of operation. +function Set.delete(a,i) + if type(i) == "table" then + for k,v in pairs(i) do a[v] = nil end + else + a[i] = nil + end + return true +end + +--- Checks if value(s) are present in set. +-- @param a set Set to inspect. +-- @param i not nil Values(s) to check. +-- @returns bool Value(s) are present? +function Set.has(a,i) + if type(i) == "table" then + for k,v in pairs(i) do + if not a[k] then return false end + end + return true + else + return a[i] ~= nil + end +end + + + +-- ██████ ██████ ███████ ██████ █████ ████████ ██████ ██████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ ██ ██████ █████ ██████ ███████ ██ ██ ██ ██████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██████ ██ ███████ ██ ██ ██ ██ ██ ██████ ██ ██ +-- +-- ██████ ██ ██ ███████ ██████ ██████ ██ ██████ ███████ ███████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ ██ ██ ██ █████ ██████ ██████ ██ ██ ██ █████ ███████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██████ ████ ███████ ██ ██ ██ ██ ██ ██████ ███████ ███████ + +function Set.__call(i) return Set.new(i) end + + +-- Main Return: +return Set From 5ea6ac18d249e026e9a6cefc9259f9ae09d04134 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 18 Jul 2021 13:12:19 -0700 Subject: [PATCH 02/49] wireframe blanks --- .../commands/wireframe/init.lua | 13 +++++++++++++ .../commands/wireframe/wbox.lua | 0 .../commands/wireframe/wcompass.lua | 0 .../commands/wireframe/wcorner.lua | 0 worldeditadditions_commands/init.lua | 3 +++ 5 files changed, 16 insertions(+) create mode 100644 worldeditadditions_commands/commands/wireframe/init.lua create mode 100644 worldeditadditions_commands/commands/wireframe/wbox.lua create mode 100644 worldeditadditions_commands/commands/wireframe/wcompass.lua create mode 100644 worldeditadditions_commands/commands/wireframe/wcorner.lua diff --git a/worldeditadditions_commands/commands/wireframe/init.lua b/worldeditadditions_commands/commands/wireframe/init.lua new file mode 100644 index 0000000..400a4a3 --- /dev/null +++ b/worldeditadditions_commands/commands/wireframe/init.lua @@ -0,0 +1,13 @@ +-- ██ ██ ██ ██████ ███████ ███████ ██████ █████ ███ ███ ███████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ +-- ██ █ ██ ██ ██████ █████ █████ ██████ ███████ ██ ████ ██ █████ +-- ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ███ ███ ██ ██ ██ ███████ ██ ██ ██ ██ ██ ██ ██ ███████ + +-- 2d and 3d outlines of shapes. + +local we_cm = worldeditadditions_commands.modpath .. "/commands/wireframe/" + +-- dofile(we_cm.."wbox.lua") +-- dofile(we_cm.."wcompass.lua") +dofile(we_cm.."wcorner.lua") diff --git a/worldeditadditions_commands/commands/wireframe/wbox.lua b/worldeditadditions_commands/commands/wireframe/wbox.lua new file mode 100644 index 0000000..e69de29 diff --git a/worldeditadditions_commands/commands/wireframe/wcompass.lua b/worldeditadditions_commands/commands/wireframe/wcompass.lua new file mode 100644 index 0000000..e69de29 diff --git a/worldeditadditions_commands/commands/wireframe/wcorner.lua b/worldeditadditions_commands/commands/wireframe/wcorner.lua new file mode 100644 index 0000000..e69de29 diff --git a/worldeditadditions_commands/init.lua b/worldeditadditions_commands/init.lua index 441da46..fd6b958 100644 --- a/worldeditadditions_commands/init.lua +++ b/worldeditadditions_commands/init.lua @@ -49,6 +49,9 @@ dofile(we_c.modpath.."/commands/selectors/init.lua") -- Measure Tools dofile(we_c.modpath.."/commands/measure/init.lua") +-- Wireframe +dofile(we_c.modpath.."/commands/wireframe/init.lua") + dofile(we_c.modpath.."/commands/extra/saplingaliases.lua") dofile(we_c.modpath.."/commands/extra/basename.lua") From d94ebd7e54940cf0e757dfdf2f2675a0c15eb98e Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 18 Jul 2021 13:12:45 -0700 Subject: [PATCH 03/49] separate init for meta commands --- .../commands/meta/init.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 worldeditadditions_commands/commands/meta/init.lua diff --git a/worldeditadditions_commands/commands/meta/init.lua b/worldeditadditions_commands/commands/meta/init.lua new file mode 100644 index 0000000..5216dc7 --- /dev/null +++ b/worldeditadditions_commands/commands/meta/init.lua @@ -0,0 +1,16 @@ +-- ███ ███ ███████ ████████ █████ +-- ████ ████ ██ ██ ██ ██ +-- ██ ████ ██ █████ ██ ███████ +-- ██ ██ ██ ██ ██ ██ ██ +-- ██ ██ ███████ ██ ██ ██ + +-- Commands that work on other commands. + +local we_cm = worldeditadditions_commands.modpath .. "/commands/meta/" + +dofile(we_cm.."airapply.lua") +dofile(we_cm.."elipsoidapply.lua") +dofile(we_cm.."many.lua") +dofile(we_cm.."multi.lua") +dofile(we_cm.."subdivide.lua") +-- dofile(we_cm.."for.lua") From 7f9c8796d0582cc704d281ac740626034144a5a0 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 18 Jul 2021 17:27:21 -0700 Subject: [PATCH 04/49] meta link fix --- worldeditadditions_commands/commands/meta/init.lua | 2 +- worldeditadditions_commands/init.lua | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/worldeditadditions_commands/commands/meta/init.lua b/worldeditadditions_commands/commands/meta/init.lua index 5216dc7..2085112 100644 --- a/worldeditadditions_commands/commands/meta/init.lua +++ b/worldeditadditions_commands/commands/meta/init.lua @@ -9,7 +9,7 @@ local we_cm = worldeditadditions_commands.modpath .. "/commands/meta/" dofile(we_cm.."airapply.lua") -dofile(we_cm.."elipsoidapply.lua") +dofile(we_cm.."ellipsoidapply.lua") dofile(we_cm.."many.lua") dofile(we_cm.."multi.lua") dofile(we_cm.."subdivide.lua") diff --git a/worldeditadditions_commands/init.lua b/worldeditadditions_commands/init.lua index fd6b958..28c9ea6 100644 --- a/worldeditadditions_commands/init.lua +++ b/worldeditadditions_commands/init.lua @@ -37,11 +37,8 @@ dofile(we_c.modpath.."/commands/walls.lua") dofile(we_c.modpath.."/commands/count.lua") -dofile(we_c.modpath.."/commands/meta/multi.lua") -dofile(we_c.modpath.."/commands/meta/many.lua") -dofile(we_c.modpath.."/commands/meta/subdivide.lua") -dofile(we_c.modpath.."/commands/meta/ellipsoidapply.lua") -dofile(we_c.modpath.."/commands/meta/airapply.lua") +-- Meta Commands +dofile(we_c.modpath.."/commands/meta/init.lua") -- Selection Tools dofile(we_c.modpath.."/commands/selectors/init.lua") From f7323afe1031a551ed292a958370e583e9688e23 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 18 Jul 2021 17:27:37 -0700 Subject: [PATCH 05/49] wireframe corner --- .../lib/wireframe/corner_set.lua | 32 +++++++++++++++++++ .../commands/wireframe/wcorner.lua | 30 +++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 worldeditadditions/lib/wireframe/corner_set.lua diff --git a/worldeditadditions/lib/wireframe/corner_set.lua b/worldeditadditions/lib/wireframe/corner_set.lua new file mode 100644 index 0000000..822c7e1 --- /dev/null +++ b/worldeditadditions/lib/wireframe/corner_set.lua @@ -0,0 +1,32 @@ +-- ██████ ██████ ██████ ███ ██ ███████ ██████ ███████ ███████ ████████ +-- ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ +-- ██ ██ ██ ██████ ██ ██ ██ █████ ██████ ███████ █████ ██ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██████ ██████ ██ ██ ██ ████ ███████ ██ ██ ███████ ███████ ██ + +--- Puts a node at each corner of selection box. +-- @param {Position} pos1 The 1st position defining the WorldEdit selection +-- @param {Position} pos2 The 2nd positioon defining the WorldEdit selection +-- @param {string} node Name of the node to place +function worldeditadditions.corner_set(pos1,pos2,node) + local node_id_replace = minetest.get_content_id(node) + + -- Fetch the nodes in the specified area + local manip, area = worldedit.manip_helpers.init(pos1, pos2) + local data = manip:get_data() + + -- z y x is the preferred loop order (because CPU cache I'd guess, since then we're iterating linearly through the data array) + local counts = { replaced = 0 } + for k,z in pairs({pos1.z,pos2.z}) do + for k,y in pairs({pos1.y,pos2.y}) do + for k,x in pairs({pos1.x,pos2.x}) do + data[area:index(x, y, z)] = node_id_replace + counts.replaced = counts.replaced + 1 + end + end + end + -- Save the modified nodes back to disk & return + worldedit.manip_helpers.finish(manip, data) + + return true, counts.replaced +end diff --git a/worldeditadditions_commands/commands/wireframe/wcorner.lua b/worldeditadditions_commands/commands/wireframe/wcorner.lua index e69de29..fb66d60 100644 --- a/worldeditadditions_commands/commands/wireframe/wcorner.lua +++ b/worldeditadditions_commands/commands/wireframe/wcorner.lua @@ -0,0 +1,30 @@ +-- ██ ██ ██████ ██████ ██████ ███ ██ ███████ ██████ +-- ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ +-- ██ █ ██ ██ ██ ██ ██████ ██ ██ ██ █████ ██████ +-- ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ███ ███ ██████ ██████ ██ ██ ██ ████ ███████ ██ ██ +local wea = worldeditadditions +worldedit.register_command("wcorner", { + params = "", + description = "Set the corners of the current selection to ", + privs = {worldedit=true}, + require_pos = 2, + parse = function(param) + local node = worldedit.normalize_nodename(param) + if not node then + return false, "invalid node name: " .. param + end + return true, node + end, + nodes_needed = function(name) + local p1, p2, total = worldedit.pos1[name], worldedit.pos2[name], 1 + for k,v in pairs({"x","y","z"}) do + if p1[v] ~= p2[v] then total = total*2 end + end + return total + end, + func = function(name, node) + local _, count = wea.corner_set(worldedit.pos1[name], worldedit.pos2[name], node) + return _, count .. " nodes set" + end, +}) From 9420be389624b87cf2887c4d0bd4fef73d0f7a95 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 18 Jul 2021 19:24:57 -0700 Subject: [PATCH 06/49] untangle init.lua --- worldeditadditions/init.lua | 57 ++----------------------------------- 1 file changed, 2 insertions(+), 55 deletions(-) diff --git a/worldeditadditions/init.lua b/worldeditadditions/init.lua index e118c9f..5672e41 100644 --- a/worldeditadditions/init.lua +++ b/worldeditadditions/init.lua @@ -6,64 +6,11 @@ -- @author Starbeamrainbowlabs worldeditadditions = {} -worldeditadditions.modpath = minetest.get_modpath("worldeditadditions") -dofile(worldeditadditions.modpath.."/utils/vector.lua") -worldeditadditions.Set = dofile(worldeditadditions.modpath.."/utils/set.lua") -worldeditadditions.Vector3 = dofile(worldeditadditions.modpath.."/utils/vector3.lua") -worldeditadditions.Mesh, -worldeditadditions.Face = dofile(worldeditadditions.modpath.."/utils/mesh.lua") - -worldeditadditions.Queue = dofile(worldeditadditions.modpath.."/utils/queue.lua") -worldeditadditions.LRU = dofile(worldeditadditions.modpath.."/utils/lru.lua") - - -dofile(worldeditadditions.modpath.."/utils/strings/init.lua") -dofile(worldeditadditions.modpath.."/utils/format/init.lua") -dofile(worldeditadditions.modpath.."/utils/parse/init.lua") -dofile(worldeditadditions.modpath.."/utils/tables/init.lua") - -dofile(worldeditadditions.modpath.."/utils/numbers.lua") -dofile(worldeditadditions.modpath.."/utils/nodes.lua") -dofile(worldeditadditions.modpath.."/utils/node_identification.lua") -dofile(worldeditadditions.modpath.."/utils/terrain.lua") -dofile(worldeditadditions.modpath.."/utils/raycast_adv.lua") -- For the farwand -dofile(worldeditadditions.modpath.."/utils/axes.lua") - -dofile(worldeditadditions.modpath.."/lib/compat/saplingnames.lua") - -dofile(worldeditadditions.modpath.."/lib/floodfill.lua") -dofile(worldeditadditions.modpath.."/lib/overlay.lua") -dofile(worldeditadditions.modpath.."/lib/layers.lua") -dofile(worldeditadditions.modpath.."/lib/fillcaves.lua") -dofile(worldeditadditions.modpath.."/lib/ellipsoid.lua") -dofile(worldeditadditions.modpath.."/lib/torus.lua") -dofile(worldeditadditions.modpath.."/lib/line.lua") -dofile(worldeditadditions.modpath.."/lib/walls.lua") -dofile(worldeditadditions.modpath.."/lib/replacemix.lua") -dofile(worldeditadditions.modpath.."/lib/maze2d.lua") -dofile(worldeditadditions.modpath.."/lib/maze3d.lua") -dofile(worldeditadditions.modpath.."/lib/hollow.lua") -dofile(worldeditadditions.modpath.."/lib/scale_up.lua") -dofile(worldeditadditions.modpath.."/lib/scale_down.lua") -dofile(worldeditadditions.modpath.."/lib/scale.lua") -dofile(worldeditadditions.modpath.."/lib/conv/conv.lua") -dofile(worldeditadditions.modpath.."/lib/erode/erode.lua") -dofile(worldeditadditions.modpath.."/lib/noise/init.lua") - -dofile(worldeditadditions.modpath.."/lib/count.lua") - -dofile(worldeditadditions.modpath.."/lib/bonemeal.lua") -dofile(worldeditadditions.modpath.."/lib/forest.lua") - -dofile(worldeditadditions.modpath.."/lib/ellipsoidapply.lua") -dofile(worldeditadditions.modpath.."/lib/airapply.lua") - -dofile(worldeditadditions.modpath.."/lib/subdivide.lua") -dofile(worldeditadditions.modpath.."/lib/selection/stack.lua") -dofile(worldeditadditions.modpath.."/lib/selection/cloud.lua") local wea = worldeditadditions wea.modpath = minetest.get_modpath("worldeditadditions") +wea.Set = dofile(wea.modpath.."/utils/set.lua") + wea.Vector3 = dofile(wea.modpath.."/utils/vector3.lua") wea.Mesh, wea.Face = dofile(wea.modpath.."/utils/mesh.lua") From dbab2e4a0d5b2722f38ef5b779c1dadf7b9be5d8 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 18 Jul 2021 19:29:17 -0700 Subject: [PATCH 07/49] added wireframe stuff --- worldeditadditions/init.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/worldeditadditions/init.lua b/worldeditadditions/init.lua index 5672e41..10f6d71 100644 --- a/worldeditadditions/init.lua +++ b/worldeditadditions/init.lua @@ -65,3 +65,6 @@ dofile(wea.modpath.."/lib/airapply.lua") dofile(wea.modpath.."/lib/subdivide.lua") dofile(wea.modpath.."/lib/selection/stack.lua") dofile(wea.modpath.."/lib/selection/cloud.lua") + +dofile(wea.modpath.."/lib/wireframe/corner_set.lua") +dofile(wea.modpath.."/lib/wireframe/wire_box.lua") From 2c42e0495cc0880686ef6701ccf52d1b38ed150e Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Mon, 19 Jul 2021 07:42:47 -0700 Subject: [PATCH 08/49] cornerset broken --- .../lib/wireframe/corner_set.lua | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/worldeditadditions/lib/wireframe/corner_set.lua b/worldeditadditions/lib/wireframe/corner_set.lua index 822c7e1..bebb20d 100644 --- a/worldeditadditions/lib/wireframe/corner_set.lua +++ b/worldeditadditions/lib/wireframe/corner_set.lua @@ -11,22 +11,38 @@ function worldeditadditions.corner_set(pos1,pos2,node) local node_id_replace = minetest.get_content_id(node) - -- Fetch the nodes in the specified area - local manip, area = worldedit.manip_helpers.init(pos1, pos2) - local data = manip:get_data() - -- z y x is the preferred loop order (because CPU cache I'd guess, since then we're iterating linearly through the data array) local counts = { replaced = 0 } for k,z in pairs({pos1.z,pos2.z}) do for k,y in pairs({pos1.y,pos2.y}) do for k,x in pairs({pos1.x,pos2.x}) do - data[area:index(x, y, z)] = node_id_replace + minetest.setnode(vector.new(x,y,z), node_id_replace) counts.replaced = counts.replaced + 1 end end end - -- Save the modified nodes back to disk & return - worldedit.manip_helpers.finish(manip, data) return true, counts.replaced end +-- function worldeditadditions.corner_set(pos1,pos2,node) +-- local node_id_replace = minetest.get_content_id(node) +-- +-- -- Fetch the nodes in the specified area +-- local manip, area = worldedit.manip_helpers.init(pos1, pos2) +-- local data = manip:get_data() +-- +-- -- z y x is the preferred loop order (because CPU cache I'd guess, since then we're iterating linearly through the data array) +-- local counts = { replaced = 0 } +-- for k,z in pairs({pos1.z,pos2.z}) do +-- for k,y in pairs({pos1.y,pos2.y}) do +-- for k,x in pairs({pos1.x,pos2.x}) do +-- data[area:index(x, y, z)] = node_id_replace +-- counts.replaced = counts.replaced + 1 +-- end +-- end +-- end +-- -- Save the modified nodes back to disk & return +-- worldedit.manip_helpers.finish(manip, data) +-- +-- return true, counts.replaced +-- end From 1e7ab670f72493bc2bdff3fea667279643c60762 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Mon, 19 Jul 2021 07:47:22 -0700 Subject: [PATCH 09/49] fix typo --- worldeditadditions/lib/wireframe/corner_set.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldeditadditions/lib/wireframe/corner_set.lua b/worldeditadditions/lib/wireframe/corner_set.lua index bebb20d..d19625b 100644 --- a/worldeditadditions/lib/wireframe/corner_set.lua +++ b/worldeditadditions/lib/wireframe/corner_set.lua @@ -16,7 +16,7 @@ function worldeditadditions.corner_set(pos1,pos2,node) for k,z in pairs({pos1.z,pos2.z}) do for k,y in pairs({pos1.y,pos2.y}) do for k,x in pairs({pos1.x,pos2.x}) do - minetest.setnode(vector.new(x,y,z), node_id_replace) + minetest.set_node(vector.new(x,y,z), node_id_replace) counts.replaced = counts.replaced + 1 end end From 1a78e61c3171e83ece44078fcd8dd709b9af44b7 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Mon, 19 Jul 2021 08:55:28 -0700 Subject: [PATCH 10/49] selector aliases to init --- worldeditadditions_commands/commands/selectors/init.lua | 3 +++ worldeditadditions_commands/init.lua | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/worldeditadditions_commands/commands/selectors/init.lua b/worldeditadditions_commands/commands/selectors/init.lua index 8e9ac32..f774c85 100644 --- a/worldeditadditions_commands/commands/selectors/init.lua +++ b/worldeditadditions_commands/commands/selectors/init.lua @@ -19,3 +19,6 @@ dofile(we_cm.."spop.lua") dofile(we_cm.."spush.lua") dofile(we_cm.."srect.lua") dofile(we_cm.."sstack.lua") + +-- Aliases +worldedit.alias_command("sfac", "sfactor") diff --git a/worldeditadditions_commands/init.lua b/worldeditadditions_commands/init.lua index 28c9ea6..611cbf0 100644 --- a/worldeditadditions_commands/init.lua +++ b/worldeditadditions_commands/init.lua @@ -81,9 +81,6 @@ worldedit.alias_command("naturalize", "layers") worldedit.alias_command("flora", "bonemeal") --- Selection Tools -worldedit.alias_command("sfac", "sfactor") - -- Measure Tools worldedit.alias_command("mcount", "count") worldedit.alias_command("mfacing", "mface") From 0c9987c7459704b615d89e915f43c182f81ad37c Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Mon, 19 Jul 2021 08:55:39 -0700 Subject: [PATCH 11/49] corner set working --- worldeditadditions/lib/wireframe/corner_set.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/worldeditadditions/lib/wireframe/corner_set.lua b/worldeditadditions/lib/wireframe/corner_set.lua index d19625b..1eae789 100644 --- a/worldeditadditions/lib/wireframe/corner_set.lua +++ b/worldeditadditions/lib/wireframe/corner_set.lua @@ -9,14 +9,13 @@ -- @param {Position} pos2 The 2nd positioon defining the WorldEdit selection -- @param {string} node Name of the node to place function worldeditadditions.corner_set(pos1,pos2,node) - local node_id_replace = minetest.get_content_id(node) -- z y x is the preferred loop order (because CPU cache I'd guess, since then we're iterating linearly through the data array) local counts = { replaced = 0 } for k,z in pairs({pos1.z,pos2.z}) do for k,y in pairs({pos1.y,pos2.y}) do for k,x in pairs({pos1.x,pos2.x}) do - minetest.set_node(vector.new(x,y,z), node_id_replace) + minetest.set_node(vector.new(x,y,z), {name=node}) counts.replaced = counts.replaced + 1 end end From 7b17c3675aa1d74cfad74b0a86df74acd0deafb5 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Mon, 19 Jul 2021 09:50:10 -0700 Subject: [PATCH 12/49] Update corner_set.lua --- .../lib/wireframe/corner_set.lua | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/worldeditadditions/lib/wireframe/corner_set.lua b/worldeditadditions/lib/wireframe/corner_set.lua index 1eae789..b9a1a41 100644 --- a/worldeditadditions/lib/wireframe/corner_set.lua +++ b/worldeditadditions/lib/wireframe/corner_set.lua @@ -23,25 +23,3 @@ function worldeditadditions.corner_set(pos1,pos2,node) return true, counts.replaced end --- function worldeditadditions.corner_set(pos1,pos2,node) --- local node_id_replace = minetest.get_content_id(node) --- --- -- Fetch the nodes in the specified area --- local manip, area = worldedit.manip_helpers.init(pos1, pos2) --- local data = manip:get_data() --- --- -- z y x is the preferred loop order (because CPU cache I'd guess, since then we're iterating linearly through the data array) --- local counts = { replaced = 0 } --- for k,z in pairs({pos1.z,pos2.z}) do --- for k,y in pairs({pos1.y,pos2.y}) do --- for k,x in pairs({pos1.x,pos2.x}) do --- data[area:index(x, y, z)] = node_id_replace --- counts.replaced = counts.replaced + 1 --- end --- end --- end --- -- Save the modified nodes back to disk & return --- worldedit.manip_helpers.finish(manip, data) --- --- return true, counts.replaced --- end From d7d96ae2636d39f1c4d3c6892441b8ea93d69fef Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Tue, 20 Jul 2021 12:52:19 -0700 Subject: [PATCH 13/49] //wbox added --- worldeditadditions/lib/wireframe/wire_box.lua | 55 +++++++++++++++++++ .../commands/wireframe/init.lua | 2 +- .../commands/wireframe/wbox.lua | 36 ++++++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 worldeditadditions/lib/wireframe/wire_box.lua diff --git a/worldeditadditions/lib/wireframe/wire_box.lua b/worldeditadditions/lib/wireframe/wire_box.lua new file mode 100644 index 0000000..6e52a2c --- /dev/null +++ b/worldeditadditions/lib/wireframe/wire_box.lua @@ -0,0 +1,55 @@ +-- ██ ██ ██ ██████ ███████ ██████ ██████ ██ ██ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ █ ██ ██ ██████ █████ ██████ ██ ██ ███ +-- ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ███ ███ ██ ██ ██ ███████ ██████ ██████ ██ ██ + +--- Fills the edges of the selection box with nodes. +-- @param {Position} pos1 The 1st position defining the WorldEdit selection +-- @param {Position} pos2 The 2nd positioon defining the WorldEdit selection +-- @param {string} node Name of the node to place +local v3 = worldeditadditions.Vector3 +function worldeditadditions.wire_box(pos1,pos2,node) + local node_id_replace = minetest.get_content_id(node) + local ps1, ps2 = v3.sort(pos1,pos2) + + -- Fetch the nodes in the specified area + local manip, area = worldedit.manip_helpers.init(pos1, pos2) + local data = manip:get_data() + + -- Using three loops to reduce the number of nodes processed + local counts = { replaced = 0 } + + for z = ps1.z,ps2.z do + for k,y in pairs({pos1.y,pos2.y}) do + for k,x in pairs({pos1.x,pos2.x}) do + data[area:index(x, y, z)] = node_id_replace + counts.replaced = counts.replaced + 1 + end + end + end + if math.abs(ps2.y-ps1.y) > 1 then + for k,z in pairs({pos1.z,pos2.z}) do + for y = pos1.y+1,pos2.y-1 do + for k,x in pairs({pos1.x,pos2.x}) do + data[area:index(x, y, z)] = node_id_replace + counts.replaced = counts.replaced + 1 + end + end + end + end + if math.abs(ps2.x-ps1.x) > 1 then + for k,z in pairs({pos1.z,pos2.z}) do + for k,y in pairs({pos1.y,pos2.y}) do + for x = pos1.x+1,pos2.x-1 do + data[area:index(x, y, z)] = node_id_replace + counts.replaced = counts.replaced + 1 + end + end + end + end + -- Save the modified nodes back to disk & return + worldedit.manip_helpers.finish(manip, data) + + return true, counts.replaced +end diff --git a/worldeditadditions_commands/commands/wireframe/init.lua b/worldeditadditions_commands/commands/wireframe/init.lua index 400a4a3..185cfa3 100644 --- a/worldeditadditions_commands/commands/wireframe/init.lua +++ b/worldeditadditions_commands/commands/wireframe/init.lua @@ -8,6 +8,6 @@ local we_cm = worldeditadditions_commands.modpath .. "/commands/wireframe/" --- dofile(we_cm.."wbox.lua") +dofile(we_cm.."wbox.lua") -- dofile(we_cm.."wcompass.lua") dofile(we_cm.."wcorner.lua") diff --git a/worldeditadditions_commands/commands/wireframe/wbox.lua b/worldeditadditions_commands/commands/wireframe/wbox.lua index e69de29..56a01ce 100644 --- a/worldeditadditions_commands/commands/wireframe/wbox.lua +++ b/worldeditadditions_commands/commands/wireframe/wbox.lua @@ -0,0 +1,36 @@ +-- ██ ██ ██████ ██████ ██ ██ +-- ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ █ ██ ██████ ██ ██ ███ +-- ██ ███ ██ ██ ██ ██ ██ ██ ██ +-- ███ ███ ██████ ██████ ██ ██ +local wea = worldeditadditions +local v3 = worldeditadditions.Vector3 +worldedit.register_command("wbox", { + params = "", + description = "Set the corners of the current selection to ", + privs = {worldedit=true}, + require_pos = 2, + parse = function(param) + local node = worldedit.normalize_nodename(param) + if not node then + return false, "invalid node name: " .. param + end + return true, node + end, + nodes_needed = function(name) + local delta = v3.subtract(worldedit.pos2[name], worldedit.pos1[name]):abs():add(1) + local total, mult, axes = 1, 4, {"x","y","z"} + for k,v in pairs(axes) do + if worldedit.pos1[name] ~= worldedit.pos2[name] then total = total*2 + else mult = mult/2 end + end + for k,v in pairs(axes) do + if delta[v] > 2 then total = total + (delta[v] - 2)*mult end + end + return total + end, + func = function(name, node) + local _, count = wea.wire_box(worldedit.pos1[name], worldedit.pos2[name], node) + return _, count .. " nodes set" + end, +}) From 4b3514204408a1f9b454275f02fcf9ce2b8014b1 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Thu, 22 Jul 2021 13:29:29 -0700 Subject: [PATCH 14/49] params to params_text --- worldeditadditions_commands/commands/wireframe/wbox.lua | 6 +++--- worldeditadditions_commands/commands/wireframe/wcorner.lua | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/worldeditadditions_commands/commands/wireframe/wbox.lua b/worldeditadditions_commands/commands/wireframe/wbox.lua index 56a01ce..bf8b98a 100644 --- a/worldeditadditions_commands/commands/wireframe/wbox.lua +++ b/worldeditadditions_commands/commands/wireframe/wbox.lua @@ -10,10 +10,10 @@ worldedit.register_command("wbox", { description = "Set the corners of the current selection to ", privs = {worldedit=true}, require_pos = 2, - parse = function(param) - local node = worldedit.normalize_nodename(param) + parse = function(params_text) + local node = worldedit.normalize_nodename(params_text) if not node then - return false, "invalid node name: " .. param + return false, "invalid node name: " .. params_text end return true, node end, diff --git a/worldeditadditions_commands/commands/wireframe/wcorner.lua b/worldeditadditions_commands/commands/wireframe/wcorner.lua index fb66d60..5de03a3 100644 --- a/worldeditadditions_commands/commands/wireframe/wcorner.lua +++ b/worldeditadditions_commands/commands/wireframe/wcorner.lua @@ -9,10 +9,10 @@ worldedit.register_command("wcorner", { description = "Set the corners of the current selection to ", privs = {worldedit=true}, require_pos = 2, - parse = function(param) - local node = worldedit.normalize_nodename(param) + parse = function(params_text) + local node = worldedit.normalize_nodename(params_text) if not node then - return false, "invalid node name: " .. param + return false, "invalid node name: " .. params_text end return true, node end, From ce1ba2772847bc93c3136694b280fd04d7d5bceb Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Thu, 22 Jul 2021 13:29:41 -0700 Subject: [PATCH 15/49] new split function --- worldeditadditions/utils/strings/split.lua | 29 +++++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/worldeditadditions/utils/strings/split.lua b/worldeditadditions/utils/strings/split.lua index 69e5518..3b5a994 100644 --- a/worldeditadditions/utils/strings/split.lua +++ b/worldeditadditions/utils/strings/split.lua @@ -42,16 +42,37 @@ function worldeditadditions.gsplit(text, pattern, plain) end --- Split a string into substrings separated by a pattern. +--- Split a string into substrings separated by a pattern. -- @param text string The string to iterate over -- @param pattern string The separator pattern -- @param plain boolean If true (or truthy), pattern is interpreted as a -- plain string, not a Lua pattern -- @returns table A sequence table containing the substrings -function worldeditadditions.split(text, pattern, plain) +-- function worldeditadditions.split(text, pattern, plain) +-- local ret = {} +-- for match in worldeditadditions.gsplit(text, pattern, plain) do +-- table.insert(ret, match) +-- end +-- return ret +-- end + +--- Split a string into substrings separated by a pattern. +-- @param str string The string to iterate over +-- @param dlm string The delimiter (separator) pattern +-- @param plain boolean If true (or truthy), pattern is interpreted as a +-- plain string, not a Lua pattern +-- @returns table A sequence table containing the substrings +function worldeditadditions.split (str,dlm,plain) + local pos, ins = 0, 0 local ret = {} - for match in worldeditadditions.gsplit(text, pattern, plain) do - table.insert(ret, match) + repeat + ins = str:find(dlm,pos,plain) + table.insert(ret,str:sub(pos,ins - 1)) + pos = ins + #dlm + until not str:find(dlm,pos,plain) + print(pos..","..#str) + if str:sub(pos,#str) ~= "" then + table.insert(ret,str:sub(pos,#str)) end return ret end From 72513b350acd1f8155ba151497b4fc65bbf33660 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Fri, 23 Jul 2021 10:46:23 -0700 Subject: [PATCH 16/49] revert to fsplit --- worldeditadditions/utils/strings/split.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/worldeditadditions/utils/strings/split.lua b/worldeditadditions/utils/strings/split.lua index 3b5a994..73af851 100644 --- a/worldeditadditions/utils/strings/split.lua +++ b/worldeditadditions/utils/strings/split.lua @@ -48,13 +48,13 @@ end -- @param plain boolean If true (or truthy), pattern is interpreted as a -- plain string, not a Lua pattern -- @returns table A sequence table containing the substrings --- function worldeditadditions.split(text, pattern, plain) --- local ret = {} --- for match in worldeditadditions.gsplit(text, pattern, plain) do --- table.insert(ret, match) --- end --- return ret --- end +function worldeditadditions.split(text, pattern, plain) + local ret = {} + for match in worldeditadditions.gsplit(text, pattern, plain) do + table.insert(ret, match) + end + return ret +end --- Split a string into substrings separated by a pattern. -- @param str string The string to iterate over @@ -62,7 +62,7 @@ end -- @param plain boolean If true (or truthy), pattern is interpreted as a -- plain string, not a Lua pattern -- @returns table A sequence table containing the substrings -function worldeditadditions.split (str,dlm,plain) +function worldeditadditions.fsplit (str,dlm,plain) local pos, ins = 0, 0 local ret = {} repeat From 8718e592066dda05d52cc7e954f2ccaa40abb62c Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Fri, 23 Jul 2021 12:09:40 -0700 Subject: [PATCH 17/49] added wcompass --- worldeditadditions/init.lua | 1 + .../lib/wireframe/make_compass.lua | 35 ++++++++++++++++++ .../commands/wireframe/init.lua | 2 +- .../commands/wireframe/wcompass.lua | 36 +++++++++++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 worldeditadditions/lib/wireframe/make_compass.lua diff --git a/worldeditadditions/init.lua b/worldeditadditions/init.lua index 10f6d71..a01356e 100644 --- a/worldeditadditions/init.lua +++ b/worldeditadditions/init.lua @@ -67,4 +67,5 @@ dofile(wea.modpath.."/lib/selection/stack.lua") dofile(wea.modpath.."/lib/selection/cloud.lua") dofile(wea.modpath.."/lib/wireframe/corner_set.lua") +dofile(wea.modpath.."/lib/wireframe/make_compass.lua") dofile(wea.modpath.."/lib/wireframe/wire_box.lua") diff --git a/worldeditadditions/lib/wireframe/make_compass.lua b/worldeditadditions/lib/wireframe/make_compass.lua new file mode 100644 index 0000000..372de86 --- /dev/null +++ b/worldeditadditions/lib/wireframe/make_compass.lua @@ -0,0 +1,35 @@ +-- ███ ███ █████ ██ ██ ███████ ██████ ██████ ███ ███ ██████ █████ ███████ ███████ +-- ████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ ██ ██ ██ ██ ██ +-- ██ ████ ██ ███████ █████ █████ ██ ██ ██ ██ ████ ██ ██████ ███████ ███████ ███████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ ██ ██ ██ ██ ██ ███████ ██████ ██████ ██ ██ ██ ██ ██ ███████ ███████ + +--- Makes a compass with a bead pointing north (+Z). +-- @param {Position} pos1 The 1st position defining the WorldEdit selection +-- @param {string} node1 Name of the node to place +-- @param {string} node2 Name of the node of the bead +function worldeditadditions.make_compass(pos1,node1,node2) + local debug, ret = "", {} + minetest.set_node(vector.add(pos1,vector.new(0,1,3)), {name=node2}) + local counts = { replaced = 1 } + -- z y x is the preferred loop order (because CPU cache I'd guess, since then we're iterating linearly through the data array) + for z = -3,3 do + if z ~= 0 then + for k,x in pairs({math.floor(-3/math.abs(z)),0,math.ceil(3/math.abs(z))}) do + minetest.set_node(vector.new(pos1.x+x,pos1.y,pos1.z+z), {name=node1}) + counts.replaced = counts.replaced + 1 + table.insert(ret,x) + end + else + for x = -3,3 do + minetest.set_node(vector.new(pos1.x+x,pos1.y,pos1.z), {name=node1}) + counts.replaced = counts.replaced + 1 + table.insert(ret,pos1.x+x) + end + end + debug = debug..z.." -- "..table.concat(ret,", ").."\n" + ret={} + end + + return true, debug..counts.replaced +end diff --git a/worldeditadditions_commands/commands/wireframe/init.lua b/worldeditadditions_commands/commands/wireframe/init.lua index 185cfa3..337a710 100644 --- a/worldeditadditions_commands/commands/wireframe/init.lua +++ b/worldeditadditions_commands/commands/wireframe/init.lua @@ -9,5 +9,5 @@ local we_cm = worldeditadditions_commands.modpath .. "/commands/wireframe/" dofile(we_cm.."wbox.lua") --- dofile(we_cm.."wcompass.lua") +dofile(we_cm.."wcompass.lua") dofile(we_cm.."wcorner.lua") diff --git a/worldeditadditions_commands/commands/wireframe/wcompass.lua b/worldeditadditions_commands/commands/wireframe/wcompass.lua index e69de29..5a62b1e 100644 --- a/worldeditadditions_commands/commands/wireframe/wcompass.lua +++ b/worldeditadditions_commands/commands/wireframe/wcompass.lua @@ -0,0 +1,36 @@ +-- ██ ██ ██████ ██████ ███ ███ ██████ █████ ███████ ███████ +-- ██ ██ ██ ██ ██ ████ ████ ██ ██ ██ ██ ██ ██ +-- ██ █ ██ ██ ██ ██ ██ ████ ██ ██████ ███████ ███████ ███████ +-- ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ███ ███ ██████ ██████ ██ ██ ██ ██ ██ ███████ ███████ +local wea = worldeditadditions +worldedit.register_command("wcompass", { + params = " []", + description = "Creates a compass around pos1 with a single node bead pointing north (+Z).", + privs = {worldedit=true}, + require_pos = 1, + parse = function(params_text) + local parts = wea.split(params_text," ",true) + local node1 = worldedit.normalize_nodename(parts[1]) + local node2 = worldedit.normalize_nodename(parts[2]) + if not node1 then + return false, "Invalid : " .. parts[1] + elseif parts[2] and not node2 then + return false, "Invalid : " .. parts[2] + elseif not parts[2] then + node2 = node1 + end + return true, node1, node2 + end, + nodes_needed = function(name) + local p1, p2, total = worldedit.pos1[name], worldedit.pos2[name], 1 + for k,v in pairs({"x","y","z"}) do + if p1[v] ~= p2[v] then total = total*2 end + end + return total + end, + func = function(name, node1, node2) + local _, count = wea.make_compass(worldedit.pos1[name], node1, node2) + return _, count .. " nodes set" + end, +}) From 24569c37d39431a450206acc35c5ae627677f7da Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Fri, 23 Jul 2021 13:13:47 -0700 Subject: [PATCH 18/49] fixed single nodename crash --- .../commands/wireframe/wcompass.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/worldeditadditions_commands/commands/wireframe/wcompass.lua b/worldeditadditions_commands/commands/wireframe/wcompass.lua index 5a62b1e..ba012c8 100644 --- a/worldeditadditions_commands/commands/wireframe/wcompass.lua +++ b/worldeditadditions_commands/commands/wireframe/wcompass.lua @@ -11,23 +11,22 @@ worldedit.register_command("wcompass", { require_pos = 1, parse = function(params_text) local parts = wea.split(params_text," ",true) + if not parts[1] then + return false, "Error: too few arguments! Expected: \" []\"" + elseif not parts[2] then + parts[2] = parts[1] + end local node1 = worldedit.normalize_nodename(parts[1]) local node2 = worldedit.normalize_nodename(parts[2]) if not node1 then return false, "Invalid : " .. parts[1] - elseif parts[2] and not node2 then + elseif not node2 then return false, "Invalid : " .. parts[2] - elseif not parts[2] then - node2 = node1 end return true, node1, node2 end, nodes_needed = function(name) - local p1, p2, total = worldedit.pos1[name], worldedit.pos2[name], 1 - for k,v in pairs({"x","y","z"}) do - if p1[v] ~= p2[v] then total = total*2 end - end - return total + return 26 end, func = function(name, node1, node2) local _, count = wea.make_compass(worldedit.pos1[name], node1, node2) From f6ed5241b4f96ad8f9083c20173d7d16254eccd9 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Fri, 23 Jul 2021 14:12:20 -0700 Subject: [PATCH 19/49] documentation for wireframe stuff --- CHANGELOG.md | 2 +- Chat-Command-Reference.md | 25 +++++++++++++++++++ .../commands/wireframe/wbox.lua | 7 ++++-- .../commands/wireframe/wcorner.lua | 4 +-- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6d2d61..28eeafa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ Note to self: See the bottom of this file for the release template text. - Add `//sfactor` (_selection factor_) - Selection Tools by @VorTechnix are finished for now. - Add `mface` (_measure facing_), `midpos` (_measure middle position_), `msize` (_measure size_), `mtrig` (_measure trigonometry_) - Measuring Tools implemented by @VorTechnix. - Add `//airapply` for applying commands only to air nodes in the defined region - + - Add `wcorner` (_wireframe corners_), `wbox` (_wireframe box_), `wcompass` (_wireframe compass_) - Wireframes implemented by @VorTechnix. ## v1.12: The selection tools update (26th June 2021) - Add `//spush`, `//spop`, and `//sstack` diff --git a/Chat-Command-Reference.md b/Chat-Command-Reference.md index 142343e..1a0692a 100644 --- a/Chat-Command-Reference.md +++ b/Chat-Command-Reference.md @@ -253,6 +253,31 @@ Creates vertical walls of `` around the inside edges of the define //walls goldblock ``` +## `//wbox ` +Sets the edges of the current selection to ``to create an outline of a rectangular prism. Useful for roughing in walls. + +```weacmd +//wbox silver_sandstone +//wbox dirt +``` + +## `//wcompass []` +Creates a compass around pos1 with a single node bead pointing north (+Z). + +```weacmd +//wcompass meselamp +//wcompass desert_cobble torch +//wcompass gold diamond +``` + +## `//wcorner ` +Set the corners of the current selection to ``. Useful for outlining building sites and setting boundaries. + +```weacmd +//wcorner glass +//wcorner stone_with_iron +``` + ## `//scale | [ [ ` Advanced version of [`//stretch` from WorldEdit](https://github.com/Uberi/Minetest-WorldEdit/blob/master/ChatCommands.md#stretch-stretchx-stretchy-stretchz) that can scale both up and down at the same time by transparently splitting it into 2 different operations. Scaling up is *always* done before scaling down. diff --git a/worldeditadditions_commands/commands/wireframe/wbox.lua b/worldeditadditions_commands/commands/wireframe/wbox.lua index bf8b98a..c2bd9c4 100644 --- a/worldeditadditions_commands/commands/wireframe/wbox.lua +++ b/worldeditadditions_commands/commands/wireframe/wbox.lua @@ -6,11 +6,14 @@ local wea = worldeditadditions local v3 = worldeditadditions.Vector3 worldedit.register_command("wbox", { - params = "", - description = "Set the corners of the current selection to ", + params = "", + description = "Sets the edges of the current selection to ", privs = {worldedit=true}, require_pos = 2, parse = function(params_text) + if params_text == "" then + return false, "Error: too few arguments! Expected: \"\"" + end local node = worldedit.normalize_nodename(params_text) if not node then return false, "invalid node name: " .. params_text diff --git a/worldeditadditions_commands/commands/wireframe/wcorner.lua b/worldeditadditions_commands/commands/wireframe/wcorner.lua index 5de03a3..af08d6f 100644 --- a/worldeditadditions_commands/commands/wireframe/wcorner.lua +++ b/worldeditadditions_commands/commands/wireframe/wcorner.lua @@ -5,8 +5,8 @@ -- ███ ███ ██████ ██████ ██ ██ ██ ████ ███████ ██ ██ local wea = worldeditadditions worldedit.register_command("wcorner", { - params = "", - description = "Set the corners of the current selection to ", + params = "", + description = "Set the corners of the current selection to ", privs = {worldedit=true}, require_pos = 2, parse = function(params_text) From 6e3b9d99e91404e91e6d8997d9fc68ac1a055805 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Fri, 23 Jul 2021 16:21:58 -0700 Subject: [PATCH 20/49] removed tests --- Chat-Command-Reference.md | 3 ++- worldeditadditions/lib/wireframe/make_compass.lua | 9 +++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Chat-Command-Reference.md b/Chat-Command-Reference.md index 1a0692a..7bae456 100644 --- a/Chat-Command-Reference.md +++ b/Chat-Command-Reference.md @@ -371,6 +371,7 @@ This command is best explained with examples: The above functions just like `//replace` - nothing special going on here. It replaces all `dirt` nodes with `stone`. + Let's make it more interesting: ```weacmd @@ -722,7 +723,7 @@ Short for _select relative_. Sets the pos2 at set distances along 3 axes relativ //srel front 5 //srel y 12 right -2 //srel left 3 up 5 -front 7 -//scube -z 12 -y -2 x -2 +//srel -z 12 -y -2 x -2 ``` diff --git a/worldeditadditions/lib/wireframe/make_compass.lua b/worldeditadditions/lib/wireframe/make_compass.lua index 372de86..a272df7 100644 --- a/worldeditadditions/lib/wireframe/make_compass.lua +++ b/worldeditadditions/lib/wireframe/make_compass.lua @@ -9,27 +9,24 @@ -- @param {string} node1 Name of the node to place -- @param {string} node2 Name of the node of the bead function worldeditadditions.make_compass(pos1,node1,node2) - local debug, ret = "", {} + minetest.set_node(vector.add(pos1,vector.new(0,1,3)), {name=node2}) local counts = { replaced = 1 } + -- z y x is the preferred loop order (because CPU cache I'd guess, since then we're iterating linearly through the data array) for z = -3,3 do if z ~= 0 then for k,x in pairs({math.floor(-3/math.abs(z)),0,math.ceil(3/math.abs(z))}) do minetest.set_node(vector.new(pos1.x+x,pos1.y,pos1.z+z), {name=node1}) counts.replaced = counts.replaced + 1 - table.insert(ret,x) end else for x = -3,3 do minetest.set_node(vector.new(pos1.x+x,pos1.y,pos1.z), {name=node1}) counts.replaced = counts.replaced + 1 - table.insert(ret,pos1.x+x) end end - debug = debug..z.." -- "..table.concat(ret,", ").."\n" - ret={} end - return true, debug..counts.replaced + return true, counts.replaced end From af07a158a82fabfe9dacacf8e0576c8b494cc6d4 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Fri, 23 Jul 2021 18:05:54 -0700 Subject: [PATCH 21/49] shaved some milliseconds off split --- worldeditadditions/utils/strings/split.lua | 31 ++++++++++++++-------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/worldeditadditions/utils/strings/split.lua b/worldeditadditions/utils/strings/split.lua index 73af851..c271aef 100644 --- a/worldeditadditions/utils/strings/split.lua +++ b/worldeditadditions/utils/strings/split.lua @@ -42,13 +42,13 @@ function worldeditadditions.gsplit(text, pattern, plain) end ---- Split a string into substrings separated by a pattern. +--- Split a string into substrings separated by a pattern. -- Deprecated -- @param text string The string to iterate over -- @param pattern string The separator pattern -- @param plain boolean If true (or truthy), pattern is interpreted as a -- plain string, not a Lua pattern -- @returns table A sequence table containing the substrings -function worldeditadditions.split(text, pattern, plain) +function worldeditadditions.dsplit(text, pattern, plain) local ret = {} for match in worldeditadditions.gsplit(text, pattern, plain) do table.insert(ret, match) @@ -62,15 +62,24 @@ end -- @param plain boolean If true (or truthy), pattern is interpreted as a -- plain string, not a Lua pattern -- @returns table A sequence table containing the substrings -function worldeditadditions.fsplit (str,dlm,plain) - local pos, ins = 0, 0 - local ret = {} - repeat - ins = str:find(dlm,pos,plain) - table.insert(ret,str:sub(pos,ins - 1)) - pos = ins + #dlm - until not str:find(dlm,pos,plain) - print(pos..","..#str) +function worldeditadditions.split (str,dlm,plain) + local pos, ret = 0, {} + local ins, i = str:find(dlm,pos,plain) + -- if plain shaves off some time in the while statement + if plain then + while ins do + table.insert(ret,str:sub(pos,ins - 1)) + pos = ins + #dlm + ins = str:find(dlm,pos,true) + end + else + while ins do + table.insert(ret,str:sub(pos,ins - 1)) + pos = i + 1 + ins, i = str:find(dlm,pos) + end + end + -- print(pos..","..#str) if str:sub(pos,#str) ~= "" then table.insert(ret,str:sub(pos,#str)) end From b4d07e9d75463d95ba900a30600b0525ebb9698d Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Mon, 26 Jul 2021 16:29:01 -0700 Subject: [PATCH 22/49] Update CONTRIBUTING.md with template --- CONTRIBUTING.md | 35 +++++++++++++++++++++++++++++++++++ README.md | 2 ++ 2 files changed, 37 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 427c273..b02dc46 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,6 +16,41 @@ Additionally, every command should be implemented in its own file. This helps ke Don't forget to update `init.lua` to `dofile()` the new file(s) you create in each submod :-) +## Chat command template + +```lua +-- ███ ██ █████ ███ ███ ███████ +-- ████ ██ ██ ██ ████ ████ ██ +-- ██ ██ ██ ███████ ██ ████ ██ █████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ ████ ██ ██ ██ ██ ███████ +local wea = worldeditadditions +worldedit.register_command("{name}", { + params = " [ ...] | [ []]", + description = "A **brief** description of what this command does", + privs = { worldedit = true }, + require_pos = 0, -- Optional | (0|1|2) + parse = function(params_text) + -- Do stuff with params_text + return true, param1, param2 + end, + nodes_needed = function(name) --Optional + return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) + end, + func = function(name, param1, param2) + -- Start a timer + local start_time = wea.get_ms_time() + -- Do stuff + + -- Finish timer + local time_taken = wea.get_ms_time() - start_time + + minetest.log("This is a logged message!") + return true, "Completed command in " .. wea.format.human_time(time_taken) + end +}) +``` + ## Guidelines When actually implementing stuff, here are a few guidelines that I recommend to summarise everything: diff --git a/README.md b/README.md index 58a7adc..37f4fdf 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,8 @@ Contributions are welcome! Please state in your pull request(s) that you release Please also make sure that the logic for every new command has it's own file. For example, the logic for `//floodfill` goes in `worldeditadditions/floodfill.lua`, the logic for `//overlay` goes in `worldeditadditions/overlay.lua`, etc. +For more information check out [CONTRIBUTING.md](CONTRIBUTING.md). + I, Starbeamrainbowlabs (@sbrl), have the ultimate final say. From 9ee24cf32fa49227c11ecf8cdc8130dd94915174 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Mon, 26 Jul 2021 18:12:20 -0700 Subject: [PATCH 23/49] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index ff616f6..9bc9379 100644 --- a/README.md +++ b/README.md @@ -140,8 +140,6 @@ Contributions are welcome! Please state in your pull request(s) that you release Please also make sure that the logic for every new command has it's own file. For example, the logic for `//floodfill` goes in `worldeditadditions/floodfill.lua`, the logic for `//overlay` goes in `worldeditadditions/overlay.lua`, etc. More contributing help can be found in [the contributing guide](CONTRIBUTING.md). -For more information check out [CONTRIBUTING.md](CONTRIBUTING.md). - I, Starbeamrainbowlabs (@sbrl), have the ultimate final say. From 415f36013fe4c9de8dfeb855b32be7cc6f133046 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Tue, 27 Jul 2021 19:56:29 -0700 Subject: [PATCH 24/49] comment tweak --- worldeditadditions/utils/strings/split.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldeditadditions/utils/strings/split.lua b/worldeditadditions/utils/strings/split.lua index c271aef..738b56f 100644 --- a/worldeditadditions/utils/strings/split.lua +++ b/worldeditadditions/utils/strings/split.lua @@ -65,7 +65,7 @@ end function worldeditadditions.split (str,dlm,plain) local pos, ret = 0, {} local ins, i = str:find(dlm,pos,plain) - -- if plain shaves off some time in the while statement + -- "if plain" shaves off some time in the while statement if plain then while ins do table.insert(ret,str:sub(pos,ins - 1)) From 1436974e9ba94200be4188d008947352e510ef56 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Tue, 27 Jul 2021 19:56:45 -0700 Subject: [PATCH 25/49] added //for --- .../commands/meta/for.lua | 57 +++++++++++++++++++ .../commands/meta/init.lua | 2 +- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 worldeditadditions_commands/commands/meta/for.lua diff --git a/worldeditadditions_commands/commands/meta/for.lua b/worldeditadditions_commands/commands/meta/for.lua new file mode 100644 index 0000000..bbc6e4f --- /dev/null +++ b/worldeditadditions_commands/commands/meta/for.lua @@ -0,0 +1,57 @@ +-- ███████ ██████ ██████ +-- ██ ██ ██ ██ ██ +-- █████ ██ ██ ██████ +-- ██ ██ ██ ██ ██ +-- ██ ██████ ██ ██ +-- Process: +-- 1: Split `params_text` into two vars with unpack(wea.split(params_text,"%sdo%s")) +-- 2: Further split the two vars into two tables, one of values and the other of {command, args} sub tables +-- 3: For each entry in the values table execute each {command, args} sub table using gsub to replace "%%" in the args with the current value + +-- Specs: +-- Command cluster support using () +-- ?Basename support for values +-- ?Comma deliniation support for values + +local wea = worldeditadditions +worldedit.register_command("for", { + params = " ... do // %% ", + description = "Executes a chat command for each value before \" do \" replacing any instances of \"%%\" with those values. The forward slashes at the beginning of the chat command must be the same as if you were executing it normally.", + privs = { worldedit = true }, + parse = function(params_text) + if not params_text:match("%sdo%s") then + return false, "Error: \"do\" argument is not present." + end + local parts = wea.split(params_text,"%sdo%s") + if not parts[1] == "" then + return false, "Error: No values specified." + end + if not parts[2] then + return false, "Error: No command specified." + end + local values = wea.split(parts[1],"%s") + local command, args = parts[2]:match("/([^%s]+)%s*(.*)$") + if not args then args = "" + else args = wea.trim(args) end + + return true, values, command, args + end, + func = function(name, values, command, args) + local cmd = minetest.chatcommands[command] + if not cmd then + return false, "Error: "..command.." isn't a valid command." + end + if not minetest.check_player_privs(name, cmd.privs) then + return false, "Your privileges are insufficient to run \""..command.."\"." + end + -- Start a timer + local start_time = wea.get_ms_time() + for _,v in pairs(values) do + cmd.func(name, args:gsub("%%+",v)) + end + -- Finish timer + local time_taken = wea.get_ms_time() - start_time + + return true, "For "..table.concat(values,", ")..", command completed in " .. wea.format.human_time(time_taken) + end +}) diff --git a/worldeditadditions_commands/commands/meta/init.lua b/worldeditadditions_commands/commands/meta/init.lua index 2085112..82b9a65 100644 --- a/worldeditadditions_commands/commands/meta/init.lua +++ b/worldeditadditions_commands/commands/meta/init.lua @@ -10,7 +10,7 @@ local we_cm = worldeditadditions_commands.modpath .. "/commands/meta/" dofile(we_cm.."airapply.lua") dofile(we_cm.."ellipsoidapply.lua") +dofile(we_cm.."for.lua") dofile(we_cm.."many.lua") dofile(we_cm.."multi.lua") dofile(we_cm.."subdivide.lua") --- dofile(we_cm.."for.lua") From 57369099a7b8e5a978810275776e8050cff22525 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Wed, 28 Jul 2021 10:15:03 -0700 Subject: [PATCH 26/49] Update basename.lua --- worldeditadditions_commands/commands/extra/basename.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldeditadditions_commands/commands/extra/basename.lua b/worldeditadditions_commands/commands/extra/basename.lua index 39d92b5..6d247bb 100644 --- a/worldeditadditions_commands/commands/extra/basename.lua +++ b/worldeditadditions_commands/commands/extra/basename.lua @@ -15,6 +15,6 @@ worldedit.register_command("basename", { end, func = function(name, params_text) if name == nil then return end - worldedit.player_notify(name, worldedit.normalize_nodename(params_text) or 'Error 404: "'..params_text..'" not found!') + return true, worldedit.normalize_nodename(params_text) or 'Error 404: "'..params_text..'" not found!' end }) From 43a59b68ff21a46db1bb58839e6075c49b572d4c Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Wed, 28 Jul 2021 13:35:52 -0700 Subject: [PATCH 27/49] converted //for to step function --- .../commands/meta/for.lua | 47 +++++++++++++++---- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/worldeditadditions_commands/commands/meta/for.lua b/worldeditadditions_commands/commands/meta/for.lua index bbc6e4f..14deaa8 100644 --- a/worldeditadditions_commands/commands/meta/for.lua +++ b/worldeditadditions_commands/commands/meta/for.lua @@ -14,6 +14,37 @@ -- ?Comma deliniation support for values local wea = worldeditadditions +local function step(params) + -- Initialize additional params on first call + if not params.first then + params.i = 1 -- Iteration number + params.time = 0 -- Total execution time + params.first = true + end + + -- Load current value to use + local v = params.values[params.i] + + -- Start a timer + local start_time = wea.get_ms_time() + -- Execute command + params.cmd.func(params.player_name, params.args:gsub("%%+",v)) + -- Finish timer and add to total + params.time = params.time + wea.get_ms_time() - start_time + -- Increment iteration state + params.i = params.i + 1 + + if params.i <= #params.values then + -- If we haven't run out of values call function again + minetest.after(0, step, params) + else + worldedit.player_notify(params.player_name, "For ".. + table.concat(params.values,", ").. + ", /"..params.cmd_name.." completed in " .. + wea.format.human_time(params.time)) + end +end + worldedit.register_command("for", { params = " ... do // %% ", description = "Executes a chat command for each value before \" do \" replacing any instances of \"%%\" with those values. The forward slashes at the beginning of the chat command must be the same as if you were executing it normally.", @@ -44,14 +75,14 @@ worldedit.register_command("for", { if not minetest.check_player_privs(name, cmd.privs) then return false, "Your privileges are insufficient to run \""..command.."\"." end - -- Start a timer - local start_time = wea.get_ms_time() - for _,v in pairs(values) do - cmd.func(name, args:gsub("%%+",v)) - end - -- Finish timer - local time_taken = wea.get_ms_time() - start_time - return true, "For "..table.concat(values,", ")..", command completed in " .. wea.format.human_time(time_taken) + step({ + player_name = name, + cmd_name = command, + values = values, + cmd = cmd, + args = args + }) + end }) From 82251995205b7ffe510a30b90e4187d67d4448fd Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Wed, 28 Jul 2021 18:06:10 -0700 Subject: [PATCH 28/49] renamed axes.lua to player.lua --- worldeditadditions/init.lua | 2 +- worldeditadditions/utils/{axes.lua => player.lua} | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) rename worldeditadditions/utils/{axes.lua => player.lua} (85%) diff --git a/worldeditadditions/init.lua b/worldeditadditions/init.lua index a01356e..ce7924d 100644 --- a/worldeditadditions/init.lua +++ b/worldeditadditions/init.lua @@ -31,7 +31,7 @@ dofile(wea.modpath.."/utils/nodes.lua") dofile(wea.modpath.."/utils/node_identification.lua") dofile(wea.modpath.."/utils/terrain.lua") dofile(wea.modpath.."/utils/raycast_adv.lua") -- For the farwand -dofile(wea.modpath.."/utils/axes.lua") +dofile(wea.modpath.."/utils/player.lua") -- Player info functions dofile(wea.modpath.."/lib/compat/saplingnames.lua") diff --git a/worldeditadditions/utils/axes.lua b/worldeditadditions/utils/player.lua similarity index 85% rename from worldeditadditions/utils/axes.lua rename to worldeditadditions/utils/player.lua index dd7b3a6..a402fb1 100644 --- a/worldeditadditions/utils/axes.lua +++ b/worldeditadditions/utils/player.lua @@ -1,8 +1,14 @@ +-- Returns the player's position (at leg level). +-- @param name string The name of the player to return facing direction of. +-- @return Returns position. +function worldeditadditions.player_vector(name) + return minetest.get_player_by_name(name):get_pos() +end -- Returns the player's facing direction on the horizontal axes only. -- @param name string The name of the player to return facing direction of. -- @return Returns axis name and sign multiplier. function worldeditadditions.player_axis2d(name) - -- minetest.get_player_by_name("singleplayer"): + -- minetest.get_player_by_name("singleplayer"): local dir = minetest.get_player_by_name(name):get_look_dir() local x, z= math.abs(dir.x), math.abs(dir.z) if x > z then return "x", dir.x > 0 and 1 or -1 From 0ecd6233adf4ae80e69c2aad2a752cfdfa71a83f Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Wed, 28 Jul 2021 18:06:26 -0700 Subject: [PATCH 29/49] Update for.lua --- worldeditadditions_commands/commands/meta/for.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldeditadditions_commands/commands/meta/for.lua b/worldeditadditions_commands/commands/meta/for.lua index 14deaa8..7db3029 100644 --- a/worldeditadditions_commands/commands/meta/for.lua +++ b/worldeditadditions_commands/commands/meta/for.lua @@ -73,7 +73,7 @@ worldedit.register_command("for", { return false, "Error: "..command.." isn't a valid command." end if not minetest.check_player_privs(name, cmd.privs) then - return false, "Your privileges are insufficient to run \""..command.."\"." + return false, "Your privileges are insufficient to run /\""..command.."\"." end step({ From ebae1cd84447634011663c6b9a33819f5b4fd596 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Wed, 28 Jul 2021 18:08:22 -0700 Subject: [PATCH 30/49] update to use player_vector --- worldeditadditions_commands/commands/selectors/srel.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldeditadditions_commands/commands/selectors/srel.lua b/worldeditadditions_commands/commands/selectors/srel.lua index cc4b3ce..4377d38 100644 --- a/worldeditadditions_commands/commands/selectors/srel.lua +++ b/worldeditadditions_commands/commands/selectors/srel.lua @@ -36,7 +36,7 @@ worldedit.register_command("srel", { if not _ then return false, vec end if not worldedit.pos1[name] then - local pos = vector.add(minetest.get_player_by_name(name):get_pos(), vector.new(0.5,-0.5,0.5)) + local pos = vector.add(wea.player_vector(name), vector.new(0.5,-0.5,0.5)) wea.vector.floor(pos) worldedit.pos1[name] = pos worldedit.mark_pos1(name) From 5757ef892dbb340be6d281405ba389a5ab569d5b Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Wed, 28 Jul 2021 18:13:15 -0700 Subject: [PATCH 31/49] added //macro --- .../commands/meta/init.lua | 1 + .../commands/meta/macro.lua | 122 ++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 worldeditadditions_commands/commands/meta/macro.lua diff --git a/worldeditadditions_commands/commands/meta/init.lua b/worldeditadditions_commands/commands/meta/init.lua index 82b9a65..536fb43 100644 --- a/worldeditadditions_commands/commands/meta/init.lua +++ b/worldeditadditions_commands/commands/meta/init.lua @@ -11,6 +11,7 @@ local we_cm = worldeditadditions_commands.modpath .. "/commands/meta/" dofile(we_cm.."airapply.lua") dofile(we_cm.."ellipsoidapply.lua") dofile(we_cm.."for.lua") +dofile(we_cm.."macro.lua") dofile(we_cm.."many.lua") dofile(we_cm.."multi.lua") dofile(we_cm.."subdivide.lua") diff --git a/worldeditadditions_commands/commands/meta/macro.lua b/worldeditadditions_commands/commands/meta/macro.lua new file mode 100644 index 0000000..435d45a --- /dev/null +++ b/worldeditadditions_commands/commands/meta/macro.lua @@ -0,0 +1,122 @@ +-- ███ ███ █████ ██████ ██████ ██████ +-- ████ ████ ██ ██ ██ ██ ██ ██ ██ +-- ██ ████ ██ ███████ ██ ██████ ██ ██ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ ██ ██ ██ ██████ ██ ██ ██████ +local wea = worldeditadditions +local v3 = worldeditadditions.Vector3 +local function step(params) + -- Initialize additional params on first call + if not params.first then + params.i = 1 -- Iteration number + params.time = 0 -- Total execution time + params.first = true + end + + -- Load current command string to use + local command, args = params.commands[params.i]:match("/([^%s]+)%s*(.*)$") + if not args then args = "" + else args = wea.trim(args) end + -- Get command and test privs + local cmd = minetest.chatcommands[command] + if not cmd then + return false, "Error: "..command.." isn't a valid command." + end + if not minetest.check_player_privs(params.player_name, cmd.privs) then + return false, "Your privileges are insufficient to run /\""..command.."\"." + end + + -- Start a timer + local start_time = wea.get_ms_time() + -- Execute command + cmd.func(params.player_name, args) + -- Finish timer and add to total + params.time = params.time + wea.get_ms_time() - start_time + -- Increment iteration state + params.i = params.i + 1 + + if params.i <= #params.commands then + -- If we haven't run out of values call function again + minetest.after(0, step, params) + else + worldedit.player_notify(params.player_name, "The macro \"".. + params.file.."\" was completed in " .. + wea.format.human_time(params.time)) + end +end + +worldedit.register_command("macro", { + params = "", + description = "Load commands from \"(world folder)/macros/[.weamac | .wmac]\" with position 1 of the current WorldEdit region as the origin", + privs = {worldedit=true}, + require_pos = 0, + parse = function(params_text) + if params_text == "" then + return false + end + if params_text:match("[!\"#%%&'%(%)%*%+,/:;<=>%?%[\\]%^`{|}]") then + return false, "Disallowed file name: " .. params_text + end + return true, wea.trim(params_text) + end, + func = function(name, file_name) + if not worldedit.pos1[name] then + worldedit.pos1[name] = v3.add(wea.player_vector(name), v3.new(0.5,-0.5,0.5)):floor() + worldedit.mark_pos1(name) + end + worldedit.pos2[name] = worldedit.pos1[name] + + -- Find the file in the world path + local testpaths = { + minetest.get_worldpath() .. "/macros/" .. file_name, + minetest.get_worldpath() .. "/macros/" .. file_name .. ".weamac", + minetest.get_worldpath() .. "/macros/" .. file_name .. ".wmac", + } + local file, err + for index, path in ipairs(testpaths) do + file, err = io.open(path, "rb") + if not err then break end + end + -- Check if file exists + if err then + return false, "Error: File \"" .. file_name .. "\" does not exist or is corrupt." + end + local value = file:read("*a") + file:close() + + step({ + player_name = name, + file = file_name:match("^[^%.]+"), + commands = wea.split(value,"[\n\r]+") + }) + + end, +}) + +-- Make default macro +local function default_macro() + local path = minetest.get_worldpath() .. "/macros" + -- Create directory if it does not already exist + minetest.mkdir(path) + local writer, err = io.open(path.."/fixlight.weamac", "ab") + if not writer then return false end + writer:write("//multi //1 //2 //outset 50 //fixlight //y") + writer:flush() + writer:close() + return true +end + +-- Check for default macro +local function chk_default_macro() + local path = minetest.get_worldpath() .. "/macros/fixlight.weamac" + local file, err = io.open(path, "rb") + if err then return false + else + file:close() + return true + end +end + +if not chk_default_macro() then + default_macro() +end From b795f3b169b8d0956050996ea54365d17f4685f2 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Thu, 29 Jul 2021 15:49:37 -0700 Subject: [PATCH 32/49] dissabled macros -- too buggy --- .../commands/meta/init.lua | 2 +- .../commands/meta/macro.lua | 30 +++++++++++++------ worldeditadditions_core/register/register.lua | 19 ++++++++++-- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/worldeditadditions_commands/commands/meta/init.lua b/worldeditadditions_commands/commands/meta/init.lua index 536fb43..c4e20de 100644 --- a/worldeditadditions_commands/commands/meta/init.lua +++ b/worldeditadditions_commands/commands/meta/init.lua @@ -11,7 +11,7 @@ local we_cm = worldeditadditions_commands.modpath .. "/commands/meta/" dofile(we_cm.."airapply.lua") dofile(we_cm.."ellipsoidapply.lua") dofile(we_cm.."for.lua") -dofile(we_cm.."macro.lua") +-- dofile(we_cm.."macro.lua") -- Async bug dofile(we_cm.."many.lua") dofile(we_cm.."multi.lua") dofile(we_cm.."subdivide.lua") diff --git a/worldeditadditions_commands/commands/meta/macro.lua b/worldeditadditions_commands/commands/meta/macro.lua index 435d45a..9bd8141 100644 --- a/worldeditadditions_commands/commands/meta/macro.lua +++ b/worldeditadditions_commands/commands/meta/macro.lua @@ -16,7 +16,7 @@ local function step(params) -- Load current command string to use local command, args = params.commands[params.i]:match("/([^%s]+)%s*(.*)$") if not args then args = "" - else args = wea.trim(args) end + else args = args:match("^%s*(.*)%s*$") end -- Get command and test privs local cmd = minetest.chatcommands[command] if not cmd then @@ -37,7 +37,7 @@ local function step(params) if params.i <= #params.commands then -- If we haven't run out of values call function again - minetest.after(0, step, params) + minetest.after(params.delay, step, params) -- Time is in seconds else worldedit.player_notify(params.player_name, "The macro \"".. params.file.."\" was completed in " .. @@ -46,20 +46,31 @@ local function step(params) end worldedit.register_command("macro", { - params = "", - description = "Load commands from \"(world folder)/macros/[.weamac | .wmac]\" with position 1 of the current WorldEdit region as the origin", + params = " []", + description = "Load commands from \"(world folder)/macros/[.weamac | .wmac]\" with position 1 of the current WorldEdit region as the origin.", privs = {worldedit=true}, require_pos = 0, parse = function(params_text) - if params_text == "" then - return false + local parts = wea.split(params_text,"%s") + local file_name, delay -- = params_text:match("^(.-)%s*(%d*%.?%d*)$") + -- Check for params and delay + if not parts[1] then + return false, "Error: Insufficient arguments. Expected: \" []\"" + elseif not parts[#parts]:match("[^%d%.]") then + delay = table.remove(parts,#parts) + file_name = table.concat(parts," ") + else + delay = 0 + file_name = table.concat(parts," ") end - if params_text:match("[!\"#%%&'%(%)%*%+,/:;<=>%?%[\\]%^`{|}]") then + -- Check file name + if file_name:match("[!\"#%%&'%(%)%*%+,/:;<=>%?%[\\]%^`{|}]") then return false, "Disallowed file name: " .. params_text end - return true, wea.trim(params_text) + + return true, file_name, delay end, - func = function(name, file_name) + func = function(name, file_name, delay) if not worldedit.pos1[name] then worldedit.pos1[name] = v3.add(wea.player_vector(name), v3.new(0.5,-0.5,0.5)):floor() worldedit.mark_pos1(name) @@ -87,6 +98,7 @@ worldedit.register_command("macro", { step({ player_name = name, file = file_name:match("^[^%.]+"), + delay = delay, commands = wea.split(value,"[\n\r]+") }) diff --git a/worldeditadditions_core/register/register.lua b/worldeditadditions_core/register/register.lua index 2a93120..2d1dccb 100644 --- a/worldeditadditions_core/register/register.lua +++ b/worldeditadditions_core/register/register.lua @@ -1,9 +1,10 @@ local we_c = worldeditadditions_core function we_c.register_command(name, def) - local success, def = we_c.check(def) + local def = table.copy(def) + local success, err = we_c.check_command(name, def) if not success then - return false, def + return false, err end minetest.register_chatcommand("/" .. name, { @@ -16,3 +17,17 @@ function we_c.register_command(name, def) }) worldedit.registered_commands[name] = def end + +function we_c.alias_command(alias, original) + if not worldedit.registered_commands[original] then + minetest.log("error", "worldedit_shortcommands: original " .. original .. " does not exist") + return + end + if minetest.chatcommands["/" .. alias] then + minetest.log("error", "worldedit_shortcommands: alias " .. alias .. " already exists") + return + end + + minetest.register_chatcommand("/" .. alias, minetest.chatcommands["/" .. original]) + worldedit.registered_commands[alias] = worldedit.registered_commands[original] +end From bd84979393f1ba096b195a217d1f2e20b00dcd61 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Fri, 30 Jul 2021 14:02:46 -0700 Subject: [PATCH 33/49] //sshift added --- Chat-Command-Reference.md | 11 +++- .../commands/selectors/init.lua | 1 + .../commands/selectors/sshift.lua | 51 +++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 worldeditadditions_commands/commands/selectors/sshift.lua diff --git a/Chat-Command-Reference.md b/Chat-Command-Reference.md index 7bae456..3cde615 100644 --- a/Chat-Command-Reference.md +++ b/Chat-Command-Reference.md @@ -372,6 +372,7 @@ This command is best explained with examples: The above functions just like `//replace` - nothing special going on here. It replaces all `dirt` nodes with `stone`. + Let's make it more interesting: ```weacmd @@ -715,7 +716,6 @@ Short for _select center_. Sets pos1 and pos2 to the centre point(s) of the curr //scentre ``` - ## `//srel [ [ ]]` Short for _select relative_. Sets the pos2 at set distances along 3 axes relative to pos1. If pos1 is not set it will default to the node directly under the player. The axis arguments accept `x, y, z` as well as `up, down, left, right, front, back`. Left, right, front and back are relative to player facing direction. Negative (`-`) can be applied to the axis, the length or both. Implementation thanks to @VorTechnix. @@ -726,6 +726,15 @@ Short for _select relative_. Sets the pos2 at set distances along 3 axes relativ //srel -z 12 -y -2 x -2 ``` +## `//sshift [ [ ]]` +Short for _selection shift_. Shifts the WorldEdit region along 3 axes. The axis arguments accept `x, y, z` as well as `up, down, left, right, front, back`. Left, right, front and back are relative to player facing direction. Negative (`-`) can be applied to the axis, the length or both. Implementation thanks to @VorTechnix. + +```weacmd +//sshift back 4 +//sshift right -2 up 2 +//sshift -left 2 z -7 -y -4 +//sshift -z 12 -y -2 x -2 +``` ## `//smake [ []]` Short for _selection make_. Modifies existing selection by moving pos2. Allows you to make the selection an odd or even length on one or more axes or set two or more axes equal to each other or the longest, shortest or average of them. Implementation thanks to @VorTechnix. diff --git a/worldeditadditions_commands/commands/selectors/init.lua b/worldeditadditions_commands/commands/selectors/init.lua index f774c85..fd60556 100644 --- a/worldeditadditions_commands/commands/selectors/init.lua +++ b/worldeditadditions_commands/commands/selectors/init.lua @@ -18,6 +18,7 @@ dofile(we_cm.."smake.lua") dofile(we_cm.."spop.lua") dofile(we_cm.."spush.lua") dofile(we_cm.."srect.lua") +dofile(we_cm.."sshift.lua") dofile(we_cm.."sstack.lua") -- Aliases diff --git a/worldeditadditions_commands/commands/selectors/sshift.lua b/worldeditadditions_commands/commands/selectors/sshift.lua new file mode 100644 index 0000000..8414145 --- /dev/null +++ b/worldeditadditions_commands/commands/selectors/sshift.lua @@ -0,0 +1,51 @@ +-- ███████ ███████ ██ ██ ██ ███████ ████████ +-- ██ ██ ██ ██ ██ ██ ██ +-- ███████ ███████ ███████ ██ █████ ██ +-- ██ ██ ██ ██ ██ ██ ██ +-- ███████ ███████ ██ ██ ██ ██ ██ +local wea = worldeditadditions +local v3 = worldeditadditions.Vector3 +local function parse_with_name(name,args) + local vec, tmp = v3.new(0, 0, 0), {} + local find, _, i = {}, 0, 0 + repeat + _, i, tmp.proc = args:find("([%l%s+-]+%d+)%s*", i) + if tmp.proc:match("[xyz]") then + tmp.ax = tmp.proc:match("[xyz]") + tmp.dir = tonumber(tmp.proc:match("[+-]?%d+")) * (tmp.proc:match("-%l+") and -1 or 1) + else + tmp.ax, _ = wea.dir_to_xyz(name, tmp.proc:match("%l+")) + if not tmp.ax then return false, _ end + tmp.dir = tonumber(tmp.proc:match("[+-]?%d+")) * (tmp.proc:match("-%l+") and -1 or 1) * _ + end + vec[tmp.ax] = tmp.dir + until not args:find("([%l%s+-]+%d+)%s*", i) + return true, vec +end +worldedit.register_command("sshift", { + params = " [ [ ]]", + description = "Shift the WorldEdit region in 3 dimensions.", + privs = { worldedit = true }, + require_pos = 2, + parse = function(params_text) + if params_text:match("([%l%s+-]+%d+)") then return true, params_text + else return false, "No acceptable params found" end + end, + func = function(name, params_text) + local _, vec = parse_with_name(name,params_text) + if not _ then return false, vec end + + local pos1 = vec:add(worldedit.pos1[name]) + worldedit.pos1[name] = pos1 + worldedit.mark_pos1(name) + + local pos2 = vec:add(worldedit.pos2[name]) + worldedit.pos2[name] = pos2 + worldedit.mark_pos2(name) + + return true, "Region shifted by " .. (vec.x + vec.y + vec.z) .. " nodes." + end, +}) + +-- Tests +-- //srel front 5 left 3 y 2 From f0cd689049c2a9cebf2deae318ac0df15df541e9 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Fri, 30 Jul 2021 14:30:21 -0700 Subject: [PATCH 34/49] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28eeafa..9ec70d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,11 @@ Note to self: See the bottom of this file for the release template text. ## v1.13: Untitled update (unreleased) - Add `//sfactor` (_selection factor_) - Selection Tools by @VorTechnix are finished for now. - - Add `mface` (_measure facing_), `midpos` (_measure middle position_), `msize` (_measure size_), `mtrig` (_measure trigonometry_) - Measuring Tools implemented by @VorTechnix. + - Add `//mface` (_measure facing_), `//midpos` (_measure middle position_), `//msize` (_measure size_), `//mtrig` (_measure trigonometry_) - Measuring Tools implemented by @VorTechnix. - Add `//airapply` for applying commands only to air nodes in the defined region - - Add `wcorner` (_wireframe corners_), `wbox` (_wireframe box_), `wcompass` (_wireframe compass_) - Wireframes implemented by @VorTechnix. + - Add `//wcorner` (_wireframe corners_), `//wbox` (_wireframe box_), `//compass` (_wireframe compass_) - Wireframes implemented by @VorTechnix. + - Add `//for` for executing commands while changing their arguments - Implemented by @VorTechnix. + - Add `//sshift` (_selection shift_) - WorldEdit cuboid manipulator replacements implemented by @VorTechnix. ## v1.12: The selection tools update (26th June 2021) - Add `//spush`, `//spop`, and `//sstack` From 9669e46ff83fdaac0d1c09d21473ffec76f8b604 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 1 Aug 2021 10:37:13 -0700 Subject: [PATCH 35/49] added conventions header and DIR details --- Chat-Command-Reference.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Chat-Command-Reference.md b/Chat-Command-Reference.md index 3cde615..2edbdcd 100644 --- a/Chat-Command-Reference.md +++ b/Chat-Command-Reference.md @@ -11,6 +11,22 @@ Other useful links: **Note:** If anything in this reference isn't clear, that's a bug. Please [open an issue](https://github.com/sbrl/Minetest-WorldEditAdditions/issues/new) (or even better a PR improving it) to let me know precisely which bit you don't understand and why. +## Conventions + +Conventions for command syntax. + +### DIR +WorldEditAdditions uses the `DIR` system in some of its selection modifier commands. `Dir`s are relative to the axis the player is facing and are defined as follows: + +|Name|Definition| +|---|---| +`front`|The horizontal axis (X or Z) which the player is mostly facing toward and the multiplier (1 or -1) corresponding to whether the value of the player's position vector corresponding to that axis would increase or decrease if they moved in the direction they are facing. +`back`|Same axis as `front` but the multiplier is inverted (m * -1). +`left`|The horizontal axis (X or Z) perpendicular to the player with the opposite multiplier to `front` if the front axis is Z or the same multiplier as `front` if the front axis is X. +`right`|Same axis as `left` but the multiplier is inverted (m * -1). +`up`|The Y axis with the multiplier 1. +`down`|The Y axis with the multiplier -1. + ## `//floodfill [ []]` Floods all connected nodes of the same type starting at _pos1_ with (which defaults to `water_source`), in a sphere with a radius of (which defaults to 50). @@ -373,6 +389,7 @@ The above functions just like `//replace` - nothing special going on here. It re + Let's make it more interesting: ```weacmd @@ -709,6 +726,7 @@ Short for _select point cloud_. Sets pos1 and pos2 to include the nodes you punc ``` + ## `//scentre` Short for _select center_. Sets pos1 and pos2 to the centre point(s) of the current selection area. 1, 2, 4 or 8 nodes may be selected depending on what parts of the original selection are even in distance. Implementation thanks to @VorTechnix. From af1640c4daee9bbf924132c52cf8a7471a8916d3 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 1 Aug 2021 10:41:52 -0700 Subject: [PATCH 36/49] Revert "added conventions header and DIR details" This reverts commit 9669e46ff83fdaac0d1c09d21473ffec76f8b604. --- Chat-Command-Reference.md | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/Chat-Command-Reference.md b/Chat-Command-Reference.md index 2edbdcd..3cde615 100644 --- a/Chat-Command-Reference.md +++ b/Chat-Command-Reference.md @@ -11,22 +11,6 @@ Other useful links: **Note:** If anything in this reference isn't clear, that's a bug. Please [open an issue](https://github.com/sbrl/Minetest-WorldEditAdditions/issues/new) (or even better a PR improving it) to let me know precisely which bit you don't understand and why. -## Conventions - -Conventions for command syntax. - -### DIR -WorldEditAdditions uses the `DIR` system in some of its selection modifier commands. `Dir`s are relative to the axis the player is facing and are defined as follows: - -|Name|Definition| -|---|---| -`front`|The horizontal axis (X or Z) which the player is mostly facing toward and the multiplier (1 or -1) corresponding to whether the value of the player's position vector corresponding to that axis would increase or decrease if they moved in the direction they are facing. -`back`|Same axis as `front` but the multiplier is inverted (m * -1). -`left`|The horizontal axis (X or Z) perpendicular to the player with the opposite multiplier to `front` if the front axis is Z or the same multiplier as `front` if the front axis is X. -`right`|Same axis as `left` but the multiplier is inverted (m * -1). -`up`|The Y axis with the multiplier 1. -`down`|The Y axis with the multiplier -1. - ## `//floodfill [ []]` Floods all connected nodes of the same type starting at _pos1_ with (which defaults to `water_source`), in a sphere with a radius of (which defaults to 50). @@ -389,7 +373,6 @@ The above functions just like `//replace` - nothing special going on here. It re - Let's make it more interesting: ```weacmd @@ -726,7 +709,6 @@ Short for _select point cloud_. Sets pos1 and pos2 to include the nodes you punc ``` - ## `//scentre` Short for _select center_. Sets pos1 and pos2 to the centre point(s) of the current selection area. 1, 2, 4 or 8 nodes may be selected depending on what parts of the original selection are even in distance. Implementation thanks to @VorTechnix. From 325f1cc11e4eac8656df8b8336b50059475fe1bd Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Mon, 2 Aug 2021 13:29:55 -0700 Subject: [PATCH 37/49] added init for lib/selectors --- worldeditadditions/init.lua | 4 ++-- worldeditadditions/lib/selection/cloud.lua | 1 - worldeditadditions/lib/selection/init.lua | 8 ++++++++ worldeditadditions/lib/selection/resize_helpers.lua | 0 4 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 worldeditadditions/lib/selection/init.lua create mode 100644 worldeditadditions/lib/selection/resize_helpers.lua diff --git a/worldeditadditions/init.lua b/worldeditadditions/init.lua index ce7924d..bae09b6 100644 --- a/worldeditadditions/init.lua +++ b/worldeditadditions/init.lua @@ -63,8 +63,8 @@ dofile(wea.modpath.."/lib/ellipsoidapply.lua") dofile(wea.modpath.."/lib/airapply.lua") dofile(wea.modpath.."/lib/subdivide.lua") -dofile(wea.modpath.."/lib/selection/stack.lua") -dofile(wea.modpath.."/lib/selection/cloud.lua") + +dofile(wea.modpath.."/lib/selection/init.lua") -- Helpers for selections dofile(wea.modpath.."/lib/wireframe/corner_set.lua") dofile(wea.modpath.."/lib/wireframe/make_compass.lua") diff --git a/worldeditadditions/lib/selection/cloud.lua b/worldeditadditions/lib/selection/cloud.lua index 35c261c..1d41fde 100644 --- a/worldeditadditions/lib/selection/cloud.lua +++ b/worldeditadditions/lib/selection/cloud.lua @@ -4,7 +4,6 @@ -- ██ ██ ██ ██ ██ ██ ██ ██ -- ██████ ███████ ██████ ██████ ██████ worldeditadditions.add_pos = {} -worldeditadditions.selection = {} function worldeditadditions.selection.add_point(name, pos) if pos ~= nil then -- print("[set_pos1]", name, "("..pos.x..", "..pos.y..", "..pos.z..")") diff --git a/worldeditadditions/lib/selection/init.lua b/worldeditadditions/lib/selection/init.lua new file mode 100644 index 0000000..28e3e9b --- /dev/null +++ b/worldeditadditions/lib/selection/init.lua @@ -0,0 +1,8 @@ +local wea = worldeditadditions +local wea_m = wea.modpath .. "/lib/selection/" + +wea.selection = {} + +dofile(wea_m.."cloud.lua") +dofile(wea_m.."resize_helpers.lua") +dofile(wea_m.."stack.lua") diff --git a/worldeditadditions/lib/selection/resize_helpers.lua b/worldeditadditions/lib/selection/resize_helpers.lua new file mode 100644 index 0000000..e69de29 From 74ba9cc36f56cec5c17690b7a908ae9f37cdbfaa Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Mon, 2 Aug 2021 16:01:02 -0700 Subject: [PATCH 38/49] more lib/selector refactoring --- worldeditadditions/lib/selection/cloud.lua | 37 -------------- worldeditadditions/lib/selection/init.lua | 5 +- .../lib/selection/resize_helpers.lua | 0 .../lib/selection/selection.lua | 49 +++++++++++++++++++ 4 files changed, 51 insertions(+), 40 deletions(-) delete mode 100644 worldeditadditions/lib/selection/cloud.lua delete mode 100644 worldeditadditions/lib/selection/resize_helpers.lua create mode 100644 worldeditadditions/lib/selection/selection.lua diff --git a/worldeditadditions/lib/selection/cloud.lua b/worldeditadditions/lib/selection/cloud.lua deleted file mode 100644 index 1d41fde..0000000 --- a/worldeditadditions/lib/selection/cloud.lua +++ /dev/null @@ -1,37 +0,0 @@ --- ██████ ██ ██████ ██ ██ ██████ --- ██ ██ ██ ██ ██ ██ ██ ██ --- ██ ██ ██ ██ ██ ██ ██ ██ --- ██ ██ ██ ██ ██ ██ ██ ██ --- ██████ ███████ ██████ ██████ ██████ -worldeditadditions.add_pos = {} -function worldeditadditions.selection.add_point(name, pos) - if pos ~= nil then - -- print("[set_pos1]", name, "("..pos.x..", "..pos.y..", "..pos.z..")") - if not worldedit.pos1[name] then worldedit.pos1[name] = vector.new(pos) end - if not worldedit.pos2[name] then worldedit.pos2[name] = vector.new(pos) end - - worldedit.marker_update(name) - - local volume_before = worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) - - worldedit.pos1[name], worldedit.pos2[name] = worldeditadditions.vector.expand_region(worldedit.pos1[name], worldedit.pos2[name], pos) - - local volume_after = worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) - - local volume_difference = volume_after - volume_before - - worldedit.marker_update(name) - worldedit.player_notify(name, "Expanded region by "..volume_difference.." nodes") - else - worldedit.player_notify(name, "Error: Too far away (try raising your maxdist with //farwand maxdist )") - -- print("[set_pos1]", name, "nil") - end -end -function worldeditadditions.selection.clear_points(name) - worldedit.pos1[name] = nil - worldedit.pos2[name] = nil - worldedit.marker_update(name) - worldedit.set_pos[name] = nil - - worldedit.player_notify(name, "Region cleared") -end diff --git a/worldeditadditions/lib/selection/init.lua b/worldeditadditions/lib/selection/init.lua index 28e3e9b..ce3fedf 100644 --- a/worldeditadditions/lib/selection/init.lua +++ b/worldeditadditions/lib/selection/init.lua @@ -1,8 +1,7 @@ local wea = worldeditadditions local wea_m = wea.modpath .. "/lib/selection/" -wea.selection = {} +wea.add_pos = {} -dofile(wea_m.."cloud.lua") -dofile(wea_m.."resize_helpers.lua") +wea.selection = dofile(wea_m.."selection.lua") dofile(wea_m.."stack.lua") diff --git a/worldeditadditions/lib/selection/resize_helpers.lua b/worldeditadditions/lib/selection/resize_helpers.lua deleted file mode 100644 index e69de29..0000000 diff --git a/worldeditadditions/lib/selection/selection.lua b/worldeditadditions/lib/selection/selection.lua new file mode 100644 index 0000000..299fe1b --- /dev/null +++ b/worldeditadditions/lib/selection/selection.lua @@ -0,0 +1,49 @@ +-- ███████ ███████ ██ ███████ ██████ ████████ ██ ██████ ███ ██ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ +-- ███████ █████ ██ █████ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ███████ ███████ ███████ ███████ ██████ ██ ██ ██████ ██ ████ + +---Selection helpers and modifiers +local selection = {} + +--- Additively adds a point to the current selection or +-- makes a selection from the provided point. +-- @param name string Player name. +-- @param pos vector The position to include. +function selection.add_point(name, pos) + if pos ~= nil then + -- print("[set_pos1]", name, "("..pos.x..", "..pos.y..", "..pos.z..")") + if not worldedit.pos1[name] then worldedit.pos1[name] = vector.new(pos) end + if not worldedit.pos2[name] then worldedit.pos2[name] = vector.new(pos) end + + worldedit.marker_update(name) + + local volume_before = worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) + + worldedit.pos1[name], worldedit.pos2[name] = worldeditadditions.vector.expand_region(worldedit.pos1[name], worldedit.pos2[name], pos) + + local volume_after = worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) + + local volume_difference = volume_after - volume_before + + worldedit.marker_update(name) + worldedit.player_notify(name, "Expanded region by "..volume_difference.." nodes") + else + worldedit.player_notify(name, "Error: Too far away (try raising your maxdist with //farwand maxdist )") + -- print("[set_pos1]", name, "nil") + end +end + +--- Clears current selection. +-- @param name string Player name. +function selection.clear_points(name) + worldedit.pos1[name] = nil + worldedit.pos2[name] = nil + worldedit.marker_update(name) + worldedit.set_pos[name] = nil + + worldedit.player_notify(name, "Region cleared") +end + +return selection From 77ffda46f78904ffa050a4c38af454dd8204ba3e Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Mon, 2 Aug 2021 18:16:50 -0700 Subject: [PATCH 39/49] added axis and dir checks --- .../lib/selection/selection.lua | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/worldeditadditions/lib/selection/selection.lua b/worldeditadditions/lib/selection/selection.lua index 299fe1b..e32fc08 100644 --- a/worldeditadditions/lib/selection/selection.lua +++ b/worldeditadditions/lib/selection/selection.lua @@ -8,9 +8,9 @@ local selection = {} --- Additively adds a point to the current selection or --- makes a selection from the provided point. --- @param name string Player name. --- @param pos vector The position to include. +-- makes a selection from the provided point. +-- @param name string Player name. +-- @param pos vector The position to include. function selection.add_point(name, pos) if pos ~= nil then -- print("[set_pos1]", name, "("..pos.x..", "..pos.y..", "..pos.z..")") @@ -36,7 +36,7 @@ function selection.add_point(name, pos) end --- Clears current selection. --- @param name string Player name. +-- @param name string Player name. function selection.clear_points(name) worldedit.pos1[name] = nil worldedit.pos2[name] = nil @@ -46,4 +46,23 @@ function selection.clear_points(name) worldedit.player_notify(name, "Region cleared") end +--- Checks if a string is a valid axis. +-- @param str string String to check (be sure to remove any + or -). +-- @param hv bool Include "h" (general horizontal) and "v" (general vertical). +-- @return bool If string is a valid axis then true. +function selection.check_axis(str,hv) + if hv then + return (str == "x" or str == "y" or str == "z" or str == "h" or str == "v") + else + return (str == "x" or str == "y" or str == "z") + end +end + +--- Checks if a string is a valid dir. +-- @param str string String to check (be sure to remove any + or -). +-- @return bool If string is a valid dir then true. +function selection.check_dir(str) + return (str == "front" or str == "back" or str == "left" or str == "right" or str == "up" or str == "down") +end + return selection From f9ac0e65ecdd1590f7950451adc7ce7faec70310 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Mon, 2 Aug 2021 18:54:18 -0700 Subject: [PATCH 40/49] alias override --- worldeditadditions_core/register/override.lua | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/worldeditadditions_core/register/override.lua b/worldeditadditions_core/register/override.lua index bf7bb4e..0857184 100644 --- a/worldeditadditions_core/register/override.lua +++ b/worldeditadditions_core/register/override.lua @@ -1,9 +1,11 @@ local we_c = worldeditadditions_core function we_c.override_command(name, def) - local success, def = we_c.check(def) + local def = table.copy(def) + local success, err = we_c.check_command(name, def) if not success then - return false, def + error(err) + return false end minetest.override_chatcommand("/" .. name, { @@ -16,3 +18,18 @@ function we_c.override_command(name, def) }) worldedit.registered_commands[name] = def end + +function we_c.alias_override(alias, original) + if not worldedit.registered_commands[original] then + minetest.log("error", "worldedit_shortcommands: original " .. original .. " does not exist") + return + end + if minetest.chatcommands["/" .. alias] then + minetest.override_chatcommand("/" .. alias, minetest.chatcommands["/" .. original]) + worldedit.registered_commands[alias] = worldedit.registered_commands[original] + else + minetest.register_chatcommand("/" .. alias, minetest.chatcommands["/" .. original]) + worldedit.registered_commands[alias] = worldedit.registered_commands[original] + end + +end From e5443bc3ce291df72d6a06dc29125a0e9d5868db Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Mon, 2 Aug 2021 18:54:33 -0700 Subject: [PATCH 41/49] check (maybe working?) --- worldeditadditions_core/register/check.lua | 36 ++++++++++++++-------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/worldeditadditions_core/register/check.lua b/worldeditadditions_core/register/check.lua index 1dfb87b..5c08285 100644 --- a/worldeditadditions_core/register/check.lua +++ b/worldeditadditions_core/register/check.lua @@ -1,14 +1,26 @@ -function worldeditadditions_core.register_command(def) - local def = table.copy(def) - assert(name and #name > 0) - assert(def.privs) - def.require_pos = def.require_pos or 0 - assert(def.require_pos >= 0 and def.require_pos < 3) - if def.params == "" and not def.parse then - def.parse = function(params_text) return true end - else - assert(def.parse) +function worldeditadditions_core.check_command(name, def) + if not (name and #name > 0) then + return false, "Error: No command name." end - assert(def.nodes_needed == nil or type(def.nodes_needed) == "function") - assert(def.func) + if not def.privs then + return false, "Error: privs is nill. Expected table." + end + def.require_pos = def.require_pos or 0 + if not (def.require_pos >= 0 and def.require_pos < 3) then + return false, "Error: require_pos must be greater than -1 and less than 3." + end + if not def.parse then + if def.params == "" then + def.parse = function(params_text) return true end + else + return false, "Error: parse function is invalid." + end + end + if not (def.nodes_needed == nil or type(def.nodes_needed) == "function") then + return false, "Error: nodes_needed must be nil or function." + end + if not def.func then + return false, "Error: main function is invalid." + end + return true end From 533519d31878c31784c5c5b8515a31e14e48d5ff Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Thu, 5 Aug 2021 10:40:36 -0700 Subject: [PATCH 42/49] streamlined getsign --- worldeditadditions/utils/numbers.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/worldeditadditions/utils/numbers.lua b/worldeditadditions/utils/numbers.lua index 2bc93d1..0a6f159 100644 --- a/worldeditadditions/utils/numbers.lua +++ b/worldeditadditions/utils/numbers.lua @@ -82,9 +82,12 @@ end -- @param src string|int Input string. -- @return string|int Returns the signed multiplier (1|-1). function worldeditadditions.getsign(src) - if type(src) == "number" then return src < 0 and -1 or 1 + if type(src) == "number" then + if src < 0 then return -1 else return 1 end elseif type(src) ~= "string" then return 1 - else return src:match('-') and -1 or 1 end + else + if src:match('-') then return -1 else return 1 end + end end --- Clamp a number to ensure it falls within a given range. From 4cf30a0e74e6da047f65d4962edee1eb08ac7c90 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Thu, 5 Aug 2021 10:41:35 -0700 Subject: [PATCH 43/49] updated @return on sort --- worldeditadditions/utils/vector3.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/worldeditadditions/utils/vector3.lua b/worldeditadditions/utils/vector3.lua index 734aabb..ed4f9d9 100644 --- a/worldeditadditions/utils/vector3.lua +++ b/worldeditadditions/utils/vector3.lua @@ -66,11 +66,11 @@ function Vector3.sub(a, b) return Vector3.subtract(a, b) end -- Returns the result as a new vector. -- If 1 of the inputs is a number and the other a vector, then the number will -- be multiplied to each of the components of the vector. --- +-- -- If both of the inputs are vectors, then the components are multiplied -- by each other (NOT the cross product). In other words: -- a.x * b.x, a.y * b.y, a.z * b.z --- +-- -- @param a Vector3|number The first item to multiply. -- @param a Vector3|number The second item to multiply. -- @returns Vector3 The result as a new Vector3 object. @@ -262,7 +262,7 @@ end -- This enables convenient ingesting of positions from outside. -- @param pos1 Vector3 The first vector to operate on. -- @param pos2 Vector3 The second vector to operate on. --- @returns Vector3,Vector3 The 2 sorted vectors. +-- @returns Vector3,Vector3 The 2 sorted vectors (min, max). function Vector3.sort(pos1, pos2) local pos1_new = Vector3.clone(pos1) -- This way we can accept non-Vector3 instances local pos2_new = Vector3.clone(pos2) -- This way we can accept non-Vector3 instances @@ -355,7 +355,7 @@ end -- ██ ██ ██████ █████ ██████ ███████ ██ ██ ██ ██████ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██████ ██ ███████ ██ ██ ██ ██ ██ ██████ ██ ██ --- +-- -- ██████ ██ ██ ███████ ██████ ██████ ██ ██████ ███████ ███████ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ █████ ██████ ██████ ██ ██ ██ █████ ███████ From 551f0c7e1686f3163bead43e854ca73385cff233 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Thu, 5 Aug 2021 20:38:59 -0700 Subject: [PATCH 44/49] player_dir debugged (hopefully) --- worldeditadditions/utils/player.lua | 47 +++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/worldeditadditions/utils/player.lua b/worldeditadditions/utils/player.lua index a402fb1..6eeb38e 100644 --- a/worldeditadditions/utils/player.lua +++ b/worldeditadditions/utils/player.lua @@ -1,12 +1,42 @@ --- Returns the player's position (at leg level). +local wea = worldeditadditions +local v3 = worldeditadditions.Vector3 +--- Returns the player's position (at leg level). -- @param name string The name of the player to return facing direction of. --- @return Returns position. +-- @return vector Returns position. function worldeditadditions.player_vector(name) return minetest.get_player_by_name(name):get_pos() end --- Returns the player's facing direction on the horizontal axes only. + +--- Returns the player's facing info including relative DIRs. -- @param name string The name of the player to return facing direction of. --- @return Returns axis name and sign multiplier. +-- @return table (vector3+) xyz raw values and {axis,sign} tables for facing direction and +-- relative direction keys (front, back, left, right, up, down). +function worldeditadditions.player_dir(name) + local dir = v3.clone(minetest.get_player_by_name(name):get_look_dir()) + local abs = dir:abs() + -- Facing info + if abs.x > abs.z then dir.facing = {axis="x",sign=wea.getsign(dir.x)} + else dir.facing = {axis="z",sign=wea.getsign(dir.z)} end + -- Set front and back + dir.front = dir.facing + dir.back = {axis=dir.facing.axis,sign=dir.facing.sign*-1} + -- Set left and right + if dir.facing.axis == "x" then dir.left = {axis="z", sign=dir.facing.sign} + else dir.left = {axis="x", sign=dir.facing.sign*-1} end + dir.right = {axis=dir.left.axis,sign=dir.left.sign*-1} + -- Set up and down + dir.up = {axis="y",sign=1} + dir.down = {axis="y",sign=-1} + return dir +end +-- /lua print(worldeditadditions.vector.tostring(minetest.get_player_by_name(myname):get_look_dir())) + +--- DEPRICATED ================================================================= +-- TODO: Refactor commands that use the following functions to use player_dir then delete these functions + +--- Returns the player's facing direction on the horizontal axes only. +-- @param name string The name of the player to return facing direction of. +-- @return string,int Returns axis name and sign multiplier. function worldeditadditions.player_axis2d(name) -- minetest.get_player_by_name("singleplayer"): local dir = minetest.get_player_by_name(name):get_look_dir() @@ -15,10 +45,10 @@ function worldeditadditions.player_axis2d(name) else return "z", dir.z > 0 and 1 or -1 end end --- Returns the axis and sign of the axis to the left of the input axis. +--- Returns the axis and sign of the axis to the left of the input axis. -- @param axis string x or z. -- @param sign int Sign multiplier. --- @return Returns axis name and sign multiplier. +-- @return string,int Returns axis name and sign multiplier. function worldeditadditions.axis_left(axis,sign) if not axis:match("[xz]") then return false, "Error: Not a horizontal axis!" elseif axis == "x" then return true, "z", sign @@ -28,7 +58,7 @@ end --- Dehumanize Direction: translates up, down, left, right, front, into xyz based on player orientation. -- @param name string The name of the player to return facing direction of. -- @param dir string Relative direction to translate. --- @return Returns axis name and sign multiplier. +-- @return string Returns axis name and sign multiplier. function worldeditadditions.dir_to_xyz(name, dir) local axfac, drfac = worldeditadditions.player_axis2d(name) local _, axlft, drlft = worldeditadditions.axis_left(axfac,drfac) @@ -40,6 +70,3 @@ function worldeditadditions.dir_to_xyz(name, dir) return "y", dir == "down" and -1 or 1 else return false, "\"" .. dir .. "\" not a recognized direction! Try: (up | down | left | right | front | back)" end end - --- Tests --- /lua print(worldeditadditions.table.unpack(worldeditadditions.player_axis2d(myname))) From bc0658b545acf23812c72a6ce67fc60927db63a6 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 5 Sep 2021 09:35:07 -0700 Subject: [PATCH 45/49] Update init.lua --- worldeditadditions_commands/commands/meta/init.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/worldeditadditions_commands/commands/meta/init.lua b/worldeditadditions_commands/commands/meta/init.lua index c4e20de..7f0d43c 100644 --- a/worldeditadditions_commands/commands/meta/init.lua +++ b/worldeditadditions_commands/commands/meta/init.lua @@ -14,4 +14,5 @@ dofile(we_cm.."for.lua") -- dofile(we_cm.."macro.lua") -- Async bug dofile(we_cm.."many.lua") dofile(we_cm.."multi.lua") +dofile(we_cm.."noiseapply2d.lua") dofile(we_cm.."subdivide.lua") From b72d36816e746ce42e5feeba853d13067178d4a4 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 10 Oct 2021 14:39:30 -0700 Subject: [PATCH 46/49] added to_boolean --- worldeditadditions/utils/strings/init.lua | 1 + worldeditadditions/utils/strings/to_boolean.lua | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 worldeditadditions/utils/strings/to_boolean.lua diff --git a/worldeditadditions/utils/strings/init.lua b/worldeditadditions/utils/strings/init.lua index 32a8454..d5b76c9 100644 --- a/worldeditadditions/utils/strings/init.lua +++ b/worldeditadditions/utils/strings/init.lua @@ -4,3 +4,4 @@ dofile(wea.modpath.."/utils/strings/split.lua") dofile(wea.modpath.."/utils/strings/polyfill.lua") dofile(wea.modpath.."/utils/strings/tochars.lua") wea.split_shell = dofile(wea.modpath.."/utils/strings/split_shell.lua") +wea.to_boolean = dofile(wea.modpath.."/utils/strings/to_boolean.lua") diff --git a/worldeditadditions/utils/strings/to_boolean.lua b/worldeditadditions/utils/strings/to_boolean.lua new file mode 100644 index 0000000..b1fe2d3 --- /dev/null +++ b/worldeditadditions/utils/strings/to_boolean.lua @@ -0,0 +1,12 @@ +--- Converts input to a value of type Boolean. +-- @param arg any Input to convert +-- @returns boolean +local function to_boolean(arg) + local typ = type(arg) + if typ == "boolean" then return arg + elseif typ == number and arg > 0 then return true + elseif arg == "false" or arg == "no" then return false + elseif typ ~= "nil" then return true + else return false end +end +return to_boolean From 191e99f0b55c3bd25ef29143aba11255ae15c2ff Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 10 Oct 2021 14:39:50 -0700 Subject: [PATCH 47/49] refactored table_tosting --- .../utils/tables/table_tostring.lua | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/worldeditadditions/utils/tables/table_tostring.lua b/worldeditadditions/utils/tables/table_tostring.lua index 4a13586..da6778e 100644 --- a/worldeditadditions/utils/tables/table_tostring.lua +++ b/worldeditadditions/utils/tables/table_tostring.lua @@ -2,16 +2,27 @@ -- @param tbl table input table -- @param sep string key value seperator -- @param new_line string key value pair delimiter +-- @param max_depth number max recursion depth (optional) -- @return string concatenated table pairs -local function table_tostring(tbl, sep, new_line) +local function table_tostring(tbl, sep, new_line, max_depth) if type(sep) ~= "string" then sep = ": " end if type(new_line) ~= "string" then new_line = ", " end + if type(max_depth) == "number" then max_depth = {depth=0,max=max_depth} + elseif type(max_depth) ~= "table" then max_depth = {depth=0,max=5} end local ret = {} if type(tbl) ~= "table" then return "Error: input not table!" end for key,value in pairs(tbl) do - table.insert(ret,tostring(key) .. sep .. tostring(value) .. new_line) + if type(value) == "table" and max_depth.depth < max_depth.max then + table.insert(ret,tostring(key) .. sep .. + "{" .. table_tostring(value,sep,new_line,{max_depth.depth+1,max_depth.max}) .. "}") + else + table.insert(ret,tostring(key) .. sep .. tostring(value)) + end end - return table.concat(ret,"") + return table.concat(ret,new_line) end +-- Test: +-- /lua v1 = { x= 0.335, facing= { axis= "z", sign= -1 } }; print(worldeditadditions.table.tostring(v1)) + return table_tostring From f7d4c5c6ac573bb895d49e82a1ad48c5a41e05fc Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 7 Nov 2021 07:04:07 -0800 Subject: [PATCH 48/49] Fix shadowing error --- worldeditadditions/lib/wireframe/wire_box.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/worldeditadditions/lib/wireframe/wire_box.lua b/worldeditadditions/lib/wireframe/wire_box.lua index 6e52a2c..fc24b04 100644 --- a/worldeditadditions/lib/wireframe/wire_box.lua +++ b/worldeditadditions/lib/wireframe/wire_box.lua @@ -21,17 +21,17 @@ function worldeditadditions.wire_box(pos1,pos2,node) local counts = { replaced = 0 } for z = ps1.z,ps2.z do - for k,y in pairs({pos1.y,pos2.y}) do - for k,x in pairs({pos1.x,pos2.x}) do + for _j,y in pairs({pos1.y,pos2.y}) do + for _k,x in pairs({pos1.x,pos2.x}) do data[area:index(x, y, z)] = node_id_replace counts.replaced = counts.replaced + 1 end end end if math.abs(ps2.y-ps1.y) > 1 then - for k,z in pairs({pos1.z,pos2.z}) do + for _j,z in pairs({pos1.z,pos2.z}) do for y = pos1.y+1,pos2.y-1 do - for k,x in pairs({pos1.x,pos2.x}) do + for _k,x in pairs({pos1.x,pos2.x}) do data[area:index(x, y, z)] = node_id_replace counts.replaced = counts.replaced + 1 end @@ -39,8 +39,8 @@ function worldeditadditions.wire_box(pos1,pos2,node) end end if math.abs(ps2.x-ps1.x) > 1 then - for k,z in pairs({pos1.z,pos2.z}) do - for k,y in pairs({pos1.y,pos2.y}) do + for _j,z in pairs({pos1.z,pos2.z}) do + for _k,y in pairs({pos1.y,pos2.y}) do for x = pos1.x+1,pos2.x-1 do data[area:index(x, y, z)] = node_id_replace counts.replaced = counts.replaced + 1 From 54268431b58e3e112d915bb1266dfbf7d0aa54d1 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 7 Nov 2021 07:36:43 -0800 Subject: [PATCH 49/49] added missing quotation marks --- worldeditadditions/utils/strings/to_boolean.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldeditadditions/utils/strings/to_boolean.lua b/worldeditadditions/utils/strings/to_boolean.lua index b1fe2d3..a128226 100644 --- a/worldeditadditions/utils/strings/to_boolean.lua +++ b/worldeditadditions/utils/strings/to_boolean.lua @@ -4,7 +4,7 @@ local function to_boolean(arg) local typ = type(arg) if typ == "boolean" then return arg - elseif typ == number and arg > 0 then return true + elseif typ == "number" and arg > 0 then return true elseif arg == "false" or arg == "no" then return false elseif typ ~= "nil" then return true else return false end