diff --git a/.gitignore b/.gitignore index 6fd0a37..077c2ac 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,5 @@ luac.out *.x86_64 *.hex +# Debug Tools (for now) +*debug/ diff --git a/worldeditadditions/utils/vector.lua b/worldeditadditions/utils/vector.lua index 43ee38d..ebcf4c1 100644 --- a/worldeditadditions/utils/vector.lua +++ b/worldeditadditions/utils/vector.lua @@ -42,6 +42,17 @@ function worldeditadditions.vector.floor(v) if v.z then v.z = math.floor(v.z) end end +--- Rounds the values in a vector up. +-- Warning: This MUTATES the given vector! +-- @param v Vector The vector to operate on +function worldeditadditions.vector.ceil(v) + if v.x then v.x = math.ceil(v.x) end + -- Some vectors are 2d, but on the x / z axes + if v.y then v.y = math.ceil(v.y) end + -- Some vectors are 2d + if v.z then v.z = math.ceil(v.z) end +end + --- Determines if the target point is contained within the defined worldedit region. -- @param pos1 Vector pos1 of the defined region. -- @param pos2 Vector pos2 of the defined region. @@ -74,3 +85,11 @@ function worldeditadditions.vector.expand_region(pos1, pos2, target) return pos1, pos2 end + +--- Returns the mean (average) of 2 positions to give you the centre. +-- @param pos1 Vector pos1 of the defined region. +-- @param pos2 Vector pos2 of the defined region. +-- @param target Vector Centre coordinates. +function worldeditadditions.vector.mean(pos1, pos2) + return vector.new((pos1.x + pos2.x)/2, (pos1.y + pos2.y)/2, (pos1.z + pos2.z)/2) +end diff --git a/worldeditadditions_commands/commands/selectors/scentre.lua b/worldeditadditions_commands/commands/selectors/scentre.lua new file mode 100644 index 0000000..20311d9 --- /dev/null +++ b/worldeditadditions_commands/commands/selectors/scentre.lua @@ -0,0 +1,28 @@ +-- ███████ ██████ ███████ ███ ██ ████████ ███████ ██████ +-- ██ ██ ██ ████ ██ ██ ██ ██ ██ +-- ███████ ██ █████ ██ ██ ██ ██ █████ ██████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ███████ ██████ ███████ ██ ████ ██ ███████ ██ ██ +local wea = worldeditadditions +worldedit.register_command("scentre", { + params = "", + description = "Set WorldEdit region positions 1 and 2 to the centre of the current selection.", + privs = {worldedit=true}, + require_pos = 2, + parse = function(params_text) + return true + end, + func = function(name) + local vecs = {} + vecs.mean = wea.vector.mean(worldedit.pos1[name],worldedit.pos2[name]) + vecs.p1, vecs.p2 = vector.new(vecs.mean), vector.new(vecs.mean) + wea.vector.floor(vecs.p1) + wea.vector.ceil(vecs.p2) + worldedit.pos1[name], worldedit.pos2[name] = vecs.p1, vecs.p2 + worldedit.mark_pos1(name) + worldedit.mark_pos2(name) + return true, "position 1 set to " .. minetest.pos_to_string(vecs.p1) .. ", position 2 set to " .. minetest.pos_to_string(vecs.p2) + end, +}) + +-- lua print(vecs.mean.x..", "..vecs.mean.y..", "..vecs.mean.z) diff --git a/worldeditadditions_commands/depends.txt b/worldeditadditions_commands/depends.txt index 04e364b..db6f73b 100644 --- a/worldeditadditions_commands/depends.txt +++ b/worldeditadditions_commands/depends.txt @@ -2,4 +2,5 @@ worldeditadditions worldedit_commands worldedit_shortcommands worldedit +worldeditadditions_debug? bonemeal? diff --git a/worldeditadditions_commands/init.lua b/worldeditadditions_commands/init.lua index c17fd9e..09bf0fd 100644 --- a/worldeditadditions_commands/init.lua +++ b/worldeditadditions_commands/init.lua @@ -19,20 +19,20 @@ dofile(we_c.modpath.."/player_notify_suppress.lua") -- we_c.safe_region, we_c.check_region, we_c.reset_pending -- = dofile(we_c.modpath.."/safe.lua") -dofile(we_c.modpath.."/commands/floodfill.lua") -dofile(we_c.modpath.."/commands/overlay.lua") -dofile(we_c.modpath.."/commands/layers.lua") -dofile(we_c.modpath.."/commands/fillcaves.lua") -dofile(we_c.modpath.."/commands/ellipsoid.lua") -dofile(we_c.modpath.."/commands/torus.lua") -dofile(we_c.modpath.."/commands/line.lua") -dofile(we_c.modpath.."/commands/walls.lua") -dofile(we_c.modpath.."/commands/maze.lua") -dofile(we_c.modpath.."/commands/replacemix.lua") dofile(we_c.modpath.."/commands/convolve.lua") +dofile(we_c.modpath.."/commands/ellipsoid.lua") dofile(we_c.modpath.."/commands/erode.lua") +dofile(we_c.modpath.."/commands/fillcaves.lua") +dofile(we_c.modpath.."/commands/floodfill.lua") dofile(we_c.modpath.."/commands/hollow.lua") +dofile(we_c.modpath.."/commands/layers.lua") +dofile(we_c.modpath.."/commands/line.lua") +dofile(we_c.modpath.."/commands/maze.lua") +dofile(we_c.modpath.."/commands/overlay.lua") +dofile(we_c.modpath.."/commands/replacemix.lua") dofile(we_c.modpath.."/commands/scale.lua") +dofile(we_c.modpath.."/commands/torus.lua") +dofile(we_c.modpath.."/commands/walls.lua") dofile(we_c.modpath.."/commands/count.lua") @@ -41,13 +41,15 @@ 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/selectors/srel.lua") +dofile(we_c.modpath.."/commands/selectors/scentre.lua") dofile(we_c.modpath.."/commands/selectors/scloud.lua") dofile(we_c.modpath.."/commands/selectors/scol.lua") -dofile(we_c.modpath.."/commands/selectors/srect.lua") dofile(we_c.modpath.."/commands/selectors/scube.lua") -dofile(we_c.modpath.."/commands/selectors/sstack.lua") -dofile(we_c.modpath.."/commands/selectors/spush.lua") dofile(we_c.modpath.."/commands/selectors/spop.lua") +dofile(we_c.modpath.."/commands/selectors/spush.lua") +dofile(we_c.modpath.."/commands/selectors/srect.lua") +dofile(we_c.modpath.."/commands/selectors/sstack.lua") dofile(we_c.modpath.."/commands/extra/saplingaliases.lua") dofile(we_c.modpath.."/commands/extra/basename.lua") @@ -68,3 +70,5 @@ worldedit.alias_command("naturalise", "layers") worldedit.alias_command("naturalize", "layers") worldedit.alias_command("flora", "bonemeal") + +worldedit.alias_command("mcount", "count")