summaryrefslogtreecommitdiff
path: root/worldedit
diff options
context:
space:
mode:
Diffstat (limited to 'worldedit')
-rw-r--r--worldedit/manipulations.lua26
-rw-r--r--worldedit/primitives.lua36
-rw-r--r--worldedit/visualization.lua2
3 files changed, 54 insertions, 10 deletions
diff --git a/worldedit/manipulations.lua b/worldedit/manipulations.lua
index 2180cb6..2b34e3c 100644
--- a/worldedit/manipulations.lua
+++ b/worldedit/manipulations.lua
@@ -1,7 +1,6 @@
worldedit = worldedit or {}
local minetest = minetest --local copy of global
---wip: test the entire API again to make sure it works
--wip: remove env parameter where no longer needed in chat commands module
--wip: fix the queue
@@ -492,3 +491,28 @@ worldedit.fixlight = function(pos1, pos2, env)
end
return #nodes
end
+
+--clears all objects in a region defined by the positions `pos1` and `pos2`, returning the number of objects cleared
+worldedit.clearobjects = function(pos1, pos2)
+ local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
+
+ --set up voxel manipulator
+ local manip = minetest.get_voxel_manip()
+ manip:read_from_map(pos1, pos2)
+
+ local pos1x, pos1y, pos1z = pos1.x, pos1.y, pos1.z
+ local pos2x, pos2y, pos2z = pos2.x, pos2.y, pos2.z
+ local center = {x=(pos1x + pos2x + 1) / 2, y=(pos1y + pos2y + 1) / 2, z=(pos1z + pos2z + 1) / 2}
+ local radius = ((center.x - pos1x + 0.5) + (center.y - pos1y + 0.5) + (center.z - pos1z + 0.5)) ^ 0.5
+ local count = 0
+ for _, obj in pairs(minetest.get_objects_inside_radius(center, radius)) do
+ local pos = obj:getpos()
+ if pos.x >= pos1x and pos.x <= pos2x
+ and pos.y >= pos1y and pos.y <= pos2y
+ and pos.z >= pos1z and pos.z <= pos2z then
+ obj:remove()
+ count = count + 1
+ end
+ end
+ return count
+end
diff --git a/worldedit/primitives.lua b/worldedit/primitives.lua
index cdb6e0f..d11596a 100644
--- a/worldedit/primitives.lua
+++ b/worldedit/primitives.lua
@@ -106,6 +106,12 @@ worldedit.hollow_dome = function(pos, radius, nodename)
nodes[i] = ignore
end
+ local miny, maxy = 0, radius
+ if radius < 0 then
+ radius = -radius
+ miny, maxy = -radius, 0
+ end
+
--fill selected area with node
local node_id = minetest.get_content_id(nodename)
local min_radius, max_radius = radius * (radius - 1), radius * (radius + 1)
@@ -114,7 +120,7 @@ worldedit.hollow_dome = function(pos, radius, nodename)
local count = 0
for z = -radius, radius do
local newz = (z + offsetz) * zstride + 1 --offset contributed by z plus 1 to make it 1-indexed
- for y = 0, radius do
+ for y = miny, maxy do
local newy = newz + (y + offsety) * ystride
for x = -radius, radius do
local squared = x * x + y * y + z * z
@@ -151,6 +157,12 @@ worldedit.dome = function(pos, radius, nodename)
nodes[i] = ignore
end
+ local miny, maxy = 0, radius
+ if radius < 0 then
+ radius = -radius
+ miny, maxy = -radius, 0
+ end
+
--fill selected area with node
local node_id = minetest.get_content_id(nodename)
local max_radius = radius * (radius + 1)
@@ -159,7 +171,7 @@ worldedit.dome = function(pos, radius, nodename)
local count = 0
for z = -radius, radius do
local newz = (z + offsetz) * zstride + 1 --offset contributed by z plus 1 to make it 1-indexed
- for y = 0, radius do
+ for y = miny, maxy do
local newy = newz + (y + offsety) * ystride
for x = -radius, radius do
if x * x + y * y + z * z <= max_radius then --position is inside sphere
@@ -248,7 +260,7 @@ worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename) --wip:
end
--adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, composed of `nodename`, returning the number of nodes added
-worldedit.cylinder = function(pos, axis, length, radius, nodename, env)
+worldedit.cylinder = function(pos, axis, length, radius, nodename)
local other1, other2
if axis == "x" then
other1, other2 = "y", "z"
@@ -317,7 +329,7 @@ worldedit.cylinder = function(pos, axis, length, radius, nodename, env)
end
--adds a pyramid centered at `pos` with height `height`, composed of `nodename`, returning the number of nodes added
-worldedit.pyramid = function(pos, height, nodename, env)
+worldedit.pyramid = function(pos, axis, height, nodename)
local pos1 = {x=pos.x - height, y=pos.y, z=pos.z - height}
local pos2 = {x=pos.x + height, y=pos.y + height, z=pos.z + height}
@@ -333,22 +345,30 @@ worldedit.pyramid = function(pos, height, nodename, env)
nodes[i] = ignore
end
+ --handle inverted pyramids
+ height = height - 1
+ local size = height
+ local step = -1
+ if height < 0 then
+ size = 0
+ step = 1
+ end
+--wip: support arbitrary axes
--fill selected area with node
local node_id = minetest.get_content_id(nodename)
- height = height - 1
local offsetx, offsety, offsetz = pos.x - emerged_pos1.x, pos.y - emerged_pos1.y, pos.z - emerged_pos1.z
local zstride, ystride = area.zstride, area.ystride
local count = 0
for y = 0, height do --go through each level of the pyramid
local newy = (y + offsety) * ystride + 1 --offset contributed by y plus 1 to make it 1-indexed
- for z = -height, height do
+ for z = -size, size do
local newz = newy + (z + offsetz) * zstride
- for x = -height, height do
+ for x = -size, size do
local i = newz + (x + offsetx)
nodes[i] = node_id
end
end
- height = height - 1
+ size = size + step
count = count + ((height - y) * 2 + 1) ^ 2
end
diff --git a/worldedit/visualization.lua b/worldedit/visualization.lua
index 7b600d5..dbee5d0 100644
--- a/worldedit/visualization.lua
+++ b/worldedit/visualization.lua
@@ -88,7 +88,7 @@ worldedit.suppress = function(pos1, pos2, nodename)
end
--highlights all instances of `nodename` in a region defined by positions `pos1` and `pos2` by non-destructively hiding all other nodes, returning the number of nodes found
-worldedit.highlight = function(pos1, pos2, nodename) --wip: speed this up with voxmanip get_data to speed up searching
+worldedit.highlight = function(pos1, pos2, nodename)
--make area stay loaded
local manip = minetest.get_voxel_manip()
manip:read_from_map(pos1, pos2)