nodes[i] = ignore\r
end\r
\r
+ local miny, maxy = 0, radius\r
+ if radius < 0 then\r
+ radius = -radius\r
+ miny, maxy = -radius, 0\r
+ end\r
+\r
--fill selected area with node\r
local node_id = minetest.get_content_id(nodename)\r
local min_radius, max_radius = radius * (radius - 1), radius * (radius + 1)\r
local count = 0\r
for z = -radius, radius do\r
local newz = (z + offsetz) * zstride + 1 --offset contributed by z plus 1 to make it 1-indexed\r
- for y = 0, radius do\r
+ for y = miny, maxy do\r
local newy = newz + (y + offsety) * ystride\r
for x = -radius, radius do\r
local squared = x * x + y * y + z * z\r
nodes[i] = ignore\r
end\r
\r
+ local miny, maxy = 0, radius\r
+ if radius < 0 then\r
+ radius = -radius\r
+ miny, maxy = -radius, 0\r
+ end\r
+\r
--fill selected area with node\r
local node_id = minetest.get_content_id(nodename)\r
local max_radius = radius * (radius + 1)\r
local count = 0\r
for z = -radius, radius do\r
local newz = (z + offsetz) * zstride + 1 --offset contributed by z plus 1 to make it 1-indexed\r
- for y = 0, radius do\r
+ for y = miny, maxy do\r
local newy = newz + (y + offsety) * ystride\r
for x = -radius, radius do\r
if x * x + y * y + z * z <= max_radius then --position is inside sphere\r
end\r
\r
--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\r
-worldedit.cylinder = function(pos, axis, length, radius, nodename, env)\r
+worldedit.cylinder = function(pos, axis, length, radius, nodename)\r
local other1, other2\r
if axis == "x" then\r
other1, other2 = "y", "z"\r
end\r
\r
--adds a pyramid centered at `pos` with height `height`, composed of `nodename`, returning the number of nodes added\r
-worldedit.pyramid = function(pos, height, nodename, env)\r
+worldedit.pyramid = function(pos, axis, height, nodename)\r
local pos1 = {x=pos.x - height, y=pos.y, z=pos.z - height}\r
local pos2 = {x=pos.x + height, y=pos.y + height, z=pos.z + height}\r
\r
nodes[i] = ignore\r
end\r
\r
+ --handle inverted pyramids\r
+ height = height - 1\r
+ local size = height\r
+ local step = -1\r
+ if height < 0 then\r
+ size = 0\r
+ step = 1\r
+ end\r
+--wip: support arbitrary axes\r
--fill selected area with node\r
local node_id = minetest.get_content_id(nodename)\r
- height = height - 1\r
local offsetx, offsety, offsetz = pos.x - emerged_pos1.x, pos.y - emerged_pos1.y, pos.z - emerged_pos1.z\r
local zstride, ystride = area.zstride, area.ystride\r
local count = 0\r
for y = 0, height do --go through each level of the pyramid\r
local newy = (y + offsety) * ystride + 1 --offset contributed by y plus 1 to make it 1-indexed\r
- for z = -height, height do\r
+ for z = -size, size do\r
local newz = newy + (z + offsetz) * zstride\r
- for x = -height, height do\r
+ for x = -size, size do\r
local i = newz + (x + offsetx)\r
nodes[i] = node_id\r
end\r
end\r
- height = height - 1\r
+ size = size + step\r
count = count + ((height - y) * 2 + 1) ^ 2\r
end\r
\r
minetest.register_privilege("worldedit", "Can use WorldEdit commands")\r
\r
worldedit.set_pos = {}\r
+worldedit.inspect = {}\r
\r
worldedit.pos1 = {}\r
worldedit.pos2 = {}\r
return "z", dir.z > 0 and 1 or -1\r
end\r
\r
-worldedit.inspect = true\r
-\r
minetest.register_chatcommand("/inspect", {\r
params = "on/off/1/0/true/false/yes/no/enable/disable",\r
description = "Enable or disable node inspection",\r
privs = {worldedit=true},\r
func = function(name, param)\r
if param == "on" or param == "1" or param == "true" or param == "yes" or param == "enable" then\r
- worldedit.inspect = true\r
- worldedit.player_notify(name, "node inspection is now on")\r
+ worldedit.inspect[name] = true\r
+ worldedit.player_notify(name, "node inspection enabled")\r
elseif param == "off" or param == "0" or param == "false" or param == "no" or param == "disable" then\r
- worldedit.inspect = false\r
- worldedit.player_notify(name, "node inspection is now off")\r
+ worldedit.inspect[name] = nil\r
+ worldedit.player_notify(name, "node inspection disabled")\r
else\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
end\r
})\r
\r
minetest.register_on_punchnode(function(pos, node, puncher)\r
- if worldedit.inspect then\r
- message = "node inspector: " .. node.name .. " at " .. minetest.pos_to_string(pos) .. " (param1=" .. node.param1 .. ", param2=" .. node.param2 .. ")"\r
- worldedit.player_notify(puncher:get_player_name(), message)\r
+ local name = puncher:get_player_name()\r
+ if worldedit.inspect[name] then\r
+ if minetest.check_player_privs(name, {worldedit=true}) then\r
+ message = "inspector: " .. node.name .. " at " .. minetest.pos_to_string(pos) .. " (param1=" .. node.param1 .. ", param2=" .. node.param2 .. ")"\r
+ else\r
+ message = "inspector: worldedit privileges required"\r
+ end\r
+ worldedit.player_notify(name, message)\r
end\r
end)\r
\r
return\r
end\r
\r
- local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")\r
+ local found, _, radius, nodename = param:find("^([+-]?%d+)%s+(.+)$")\r
if found == nil then\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
return\r
return\r
end\r
\r
- local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")\r
+ local found, _, radius, nodename = param:find("^([+-]?%d+)%s+(.+)$")\r
if found == nil then\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
return\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
return\r
end\r
+ length, radius = tonumber(length), tonumber(radius)\r
if axis == "?" then\r
axis, sign = worldedit.player_axis(name)\r
length = length * sign\r
if worldedit.ENABLE_QUEUE then\r
tenv = worldedit.queue_aliasenv\r
end\r
- local count = worldedit.hollow_cylinder(pos, axis, tonumber(length), tonumber(radius), node, tenv)\r
+ local count = worldedit.hollow_cylinder(pos, axis, length, radius, node, tenv)\r
worldedit.player_notify(name, count .. " nodes added")\r
end,\r
})\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
return\r
end\r
+ length, radius = tonumber(length), tonumber(radius)\r
if axis == "?" then\r
axis, sign = worldedit.player_axis(name)\r
length = length * sign\r
if worldedit.ENABLE_QUEUE then\r
tenv = worldedit.queue_aliasenv\r
end\r
- local count = worldedit.cylinder(pos, axis, tonumber(length), tonumber(radius), node, tenv)\r
+ local count = worldedit.cylinder(pos, axis, length, radius, node, tenv)\r
worldedit.player_notify(name, count .. " nodes added")\r
end,\r
})\r
\r
minetest.register_chatcommand("/pyramid", {\r
- params = "<height> <node>",\r
- description = "Add pyramid centered at WorldEdit position 1 with height <height>, composed of <node>",\r
+ params = "x/y/z/? <height> <node>",\r
+ description = "Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node>",\r
privs = {worldedit=true},\r
func = function(name, param)\r
local pos = worldedit.pos1[name]\r
return\r
end\r
\r
- local found, _, size, nodename = param:find("(%d+)%s+(.+)$")\r
+ local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$")\r
if found == nil then\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
return\r
end\r
+ height = tonumber(height)\r
+ if axis == "?" then\r
+ axis, sign = worldedit.player_axis(name)\r
+ height = height * sign\r
+ end\r
local node = worldedit.normalize_nodename(nodename)\r
if not node then\r
worldedit.player_notify(name, "invalid node name: " .. nodename)\r
return\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.queue_aliasenv\r
- end\r
- local count = worldedit.pyramid(pos, tonumber(size), node, tenv)\r
+ local count = worldedit.pyramid(pos, axis, height, node)\r
worldedit.player_notify(name, count .. " nodes added")\r
end,\r
})\r
return\r
end\r
\r
- local found, _, width, height, space, nodename = param:find("(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")\r
+ local found, _, width, height, space, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")\r
if found == nil then\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
return\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
return\r
end\r
+ amount = tonumber(amount)\r
if axis == "?" then\r
axis, sign = worldedit.player_axis(name)\r
amount = amount * sign\r
if worldedit.ENABLE_QUEUE then\r
tenv = worldedit.queue_aliasenv\r
end\r
- local count = worldedit.copy(pos1, pos2, axis, tonumber(amount), tenv)\r
+ local count = worldedit.copy(pos1, pos2, axis, amount, tenv)\r
worldedit.player_notify(name, count .. " nodes copied")\r
end,\r
})\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
return\r
end\r
+ amount = tonumber(amount)\r
if axis == "?" then\r
axis, sign = worldedit.player_axis(name)\r
amount = amount * sign\r
if worldedit.ENABLE_QUEUE then\r
tenv = worldedit.queue_aliasenv\r
end\r
- local count = worldedit.move(pos1, pos2, axis, tonumber(amount), tenv)\r
+ local count = worldedit.move(pos1, pos2, axis, amount, tenv)\r
\r
pos1[axis] = pos1[axis] + amount\r
pos2[axis] = pos2[axis] + amount\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
return\r
end\r
+ count = tonumber(count)\r
if axis == "?" then\r
axis, sign = worldedit.player_axis(name)\r
count = count * sign\r
if worldedit.ENABLE_QUEUE then\r
tenv = worldedit.queue_aliasenv\r
end\r
- local count = worldedit.stack(pos1, pos2, axis, tonumber(count), tenv)\r
+ local count = worldedit.stack(pos1, pos2, axis, count, tenv)\r
worldedit.player_notify(name, count .. " nodes stacked")\r
end,\r
})\r
\r
if minetest.place_schematic then\r
minetest.register_chatcommand("/mtschemcreate", {\r
- params = "<filename>",\r
- description = "Creates a Minetest schematic of the box defined by position 1 and position 2, and saves it to <filename>",\r
+ params = "<file>",\r
+ description = "Save the current WorldEdit region using the Minetest Schematic format to \"(world folder)/schems/<filename>.mts\"",\r
privs = {worldedit=true},\r
func = function(name, param)\r
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
})\r
\r
minetest.register_chatcommand("/mtschemplace", {\r
- params = "<filename>",\r
- description = "Places the Minetest schematic identified by <filename> at WorldEdit position 1",\r
+ params = "<file>",\r
+ description = "Load nodes from \"(world folder)/schems/<file>.mts\" with position 1 of the current WorldEdit region as the origin",\r
privs = {worldedit=true},\r
func = function(name, param)\r
local pos = worldedit.pos1[name]\r
end\r
)\r
end\r
+\r
+minetest.register_chatcommand("/clearobjects", {\r
+ params = "",\r
+ description = "Clears all objects within the WorldEdit region",\r
+ privs = {worldedit=true},\r
+ func = function(name, param)\r
+ local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
+ if pos1 == nil or pos2 == nil then\r
+ worldedit.player_notify(name, "no region selected")\r
+ return\r
+ end\r
+\r
+ local count = worldedit.clearobjects(pos1, pos2)\r
+ worldedit.player_notify(name, count .. " objects cleared")\r
+ end,\r
+})\r