summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Zhang <azhang9@gmail.com>2013-07-29 12:43:24 -0400
committerAnthony Zhang <azhang9@gmail.com>2013-07-29 12:43:24 -0400
commit49b683f27f54bcdc636c018c7e6c1c4b4462b0bf (patch)
tree891946aaa138d495a2089efcb3254ad5444e6db5
parentc1f3cfc1e43668d07e95271febc261c82478f7aa (diff)
Support negative values to make upside-down domes and pyramids (slight changes to worldedit.pyramid interface for coming changes). Add experimental //clearobjects, make node inspector work per-player.
-rw-r--r--Chat Commands.md14
-rw-r--r--WorldEdit API.md10
-rw-r--r--worldedit/manipulations.lua26
-rw-r--r--worldedit/primitives.lua36
-rw-r--r--worldedit/visualization.lua2
-rw-r--r--worldedit_commands/init.lua84
6 files changed, 127 insertions, 45 deletions
diff --git a/Chat Commands.md b/Chat Commands.md
index f661b8d..d27ebfc 100644
--- a/Chat Commands.md
+++ b/Chat Commands.md
@@ -118,7 +118,7 @@ Add sphere centered at WorldEdit position 1 with radius <radius>, composed of <n
Add hollow dome centered at WorldEdit position 1 with radius <radius>, composed of <node>.
//hollowdome 5 Diamond Block
- //hollowdome 12 glass
+ //hollowdome -12 glass
//hollowdome 17 mesecons:wire_00000000_off
### //dome <radius> <node>
@@ -126,7 +126,7 @@ Add hollow dome centered at WorldEdit position 1 with radius <radius>, composed
Add dome centered at WorldEdit position 1 with radius <radius>, composed of <node>.
//dome 5 Diamond Block
- //dome 12 glass
+ //dome -12 glass
//dome 17 mesecons:wire_00000000_off
### //hollowcylinder x/y/z/? <length> <radius> <node>
@@ -147,9 +147,9 @@ Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length>
//cylinder z -12 3 mesecons:wire_00000000_off
//cylinder ? 2 4 default:stone
-### //pyramid <height> <node>
+### //pyramid x/y/z? <height> <node>
-Add pyramid centered at WorldEdit position 1 with height <height>, composed of <node>.
+Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node>.
//pyramid 8 Diamond Block
//pyramid 5 glass
@@ -323,3 +323,9 @@ After using //mtschemprob start all nodes punched will bring up a text field whe
This mode can be left with //mtschemprob finish. //mtschemprob get will display the probabilities saved for the nodes.
//mtschemprob get
+
+### //clearobjects
+
+Clears all objects within the WorldEdit region.
+
+ //clearobjects
diff --git a/WorldEdit API.md b/WorldEdit API.md
index 1006932..5d7e6d9 100644
--- a/WorldEdit API.md
+++ b/WorldEdit API.md
@@ -82,6 +82,12 @@ Fixes the lighting in a region defined by positions `pos1` and `pos2`.
Returns the number of nodes updated.
+### count = worldedit.clearobjects(pos1, pos2)
+
+Clears all objects in a region defined by the positions `pos1` and `pos2`.
+
+Returns the number of objects cleared.
+
Primitives
----------
Contained in primitives.lua, this module allows the creation of several geometric primitives.
@@ -122,9 +128,9 @@ Adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `
Returns the number of nodes added.
-### count = worldedit.pyramid(pos, height, nodename)
+### count = worldedit.pyramid(pos, axis, height, nodename)
-Adds a pyramid centered at `pos` with height `height`.
+Adds a pyramid centered at `pos` along the `axis` axis ("x" or "y" or "z") with height `height`.
Returns the number of nodes added.
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)
diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua
index 0ecd093..44768a3 100644
--- a/worldedit_commands/init.lua
+++ b/worldedit_commands/init.lua
@@ -1,6 +1,7 @@
minetest.register_privilege("worldedit", "Can use WorldEdit commands")
worldedit.set_pos = {}
+worldedit.inspect = {}
worldedit.pos1 = {}
worldedit.pos2 = {}
@@ -49,19 +50,17 @@ worldedit.player_axis = function(name)
return "z", dir.z > 0 and 1 or -1
end
-worldedit.inspect = true
-
minetest.register_chatcommand("/inspect", {
params = "on/off/1/0/true/false/yes/no/enable/disable",
description = "Enable or disable node inspection",
privs = {worldedit=true},
func = function(name, param)
if param == "on" or param == "1" or param == "true" or param == "yes" or param == "enable" then
- worldedit.inspect = true
- worldedit.player_notify(name, "node inspection is now on")
+ worldedit.inspect[name] = true
+ worldedit.player_notify(name, "node inspection enabled")
elseif param == "off" or param == "0" or param == "false" or param == "no" or param == "disable" then
- worldedit.inspect = false
- worldedit.player_notify(name, "node inspection is now off")
+ worldedit.inspect[name] = nil
+ worldedit.player_notify(name, "node inspection disabled")
else
worldedit.player_notify(name, "invalid usage: " .. param)
end
@@ -69,9 +68,14 @@ minetest.register_chatcommand("/inspect", {
})
minetest.register_on_punchnode(function(pos, node, puncher)
- if worldedit.inspect then
- message = "node inspector: " .. node.name .. " at " .. minetest.pos_to_string(pos) .. " (param1=" .. node.param1 .. ", param2=" .. node.param2 .. ")"
- worldedit.player_notify(puncher:get_player_name(), message)
+ local name = puncher:get_player_name()
+ if worldedit.inspect[name] then
+ if minetest.check_player_privs(name, {worldedit=true}) then
+ message = "inspector: " .. node.name .. " at " .. minetest.pos_to_string(pos) .. " (param1=" .. node.param1 .. ", param2=" .. node.param2 .. ")"
+ else
+ message = "inspector: worldedit privileges required"
+ end
+ worldedit.player_notify(name, message)
end
end)
@@ -408,7 +412,7 @@ minetest.register_chatcommand("/hollowdome", {
return
end
- local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
+ local found, _, radius, nodename = param:find("^([+-]?%d+)%s+(.+)$")
if found == nil then
worldedit.player_notify(name, "invalid usage: " .. param)
return
@@ -439,7 +443,7 @@ minetest.register_chatcommand("/dome", {
return
end
- local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
+ local found, _, radius, nodename = param:find("^([+-]?%d+)%s+(.+)$")
if found == nil then
worldedit.player_notify(name, "invalid usage: " .. param)
return
@@ -475,6 +479,7 @@ minetest.register_chatcommand("/hollowcylinder", {
worldedit.player_notify(name, "invalid usage: " .. param)
return
end
+ length, radius = tonumber(length), tonumber(radius)
if axis == "?" then
axis, sign = worldedit.player_axis(name)
length = length * sign
@@ -489,7 +494,7 @@ minetest.register_chatcommand("/hollowcylinder", {
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
- local count = worldedit.hollow_cylinder(pos, axis, tonumber(length), tonumber(radius), node, tenv)
+ local count = worldedit.hollow_cylinder(pos, axis, length, radius, node, tenv)
worldedit.player_notify(name, count .. " nodes added")
end,
})
@@ -510,6 +515,7 @@ minetest.register_chatcommand("/cylinder", {
worldedit.player_notify(name, "invalid usage: " .. param)
return
end
+ length, radius = tonumber(length), tonumber(radius)
if axis == "?" then
axis, sign = worldedit.player_axis(name)
length = length * sign
@@ -524,14 +530,14 @@ minetest.register_chatcommand("/cylinder", {
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
- local count = worldedit.cylinder(pos, axis, tonumber(length), tonumber(radius), node, tenv)
+ local count = worldedit.cylinder(pos, axis, length, radius, node, tenv)
worldedit.player_notify(name, count .. " nodes added")
end,
})
minetest.register_chatcommand("/pyramid", {
- params = "<height> <node>",
- description = "Add pyramid centered at WorldEdit position 1 with height <height>, composed of <node>",
+ params = "x/y/z/? <height> <node>",
+ description = "Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node>",
privs = {worldedit=true},
func = function(name, param)
local pos = worldedit.pos1[name]
@@ -540,22 +546,23 @@ minetest.register_chatcommand("/pyramid", {
return
end
- local found, _, size, nodename = param:find("(%d+)%s+(.+)$")
+ local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$")
if found == nil then
worldedit.player_notify(name, "invalid usage: " .. param)
return
end
+ height = tonumber(height)
+ if axis == "?" then
+ axis, sign = worldedit.player_axis(name)
+ height = height * sign
+ end
local node = worldedit.normalize_nodename(nodename)
if not node then
worldedit.player_notify(name, "invalid node name: " .. nodename)
return
end
- local tenv = minetest.env
- if worldedit.ENABLE_QUEUE then
- tenv = worldedit.queue_aliasenv
- end
- local count = worldedit.pyramid(pos, tonumber(size), node, tenv)
+ local count = worldedit.pyramid(pos, axis, height, node)
worldedit.player_notify(name, count .. " nodes added")
end,
})
@@ -571,7 +578,7 @@ minetest.register_chatcommand("/spiral", {
return
end
- local found, _, width, height, space, nodename = param:find("(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")
+ local found, _, width, height, space, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")
if found == nil then
worldedit.player_notify(name, "invalid usage: " .. param)
return
@@ -607,6 +614,7 @@ minetest.register_chatcommand("/copy", {
worldedit.player_notify(name, "invalid usage: " .. param)
return
end
+ amount = tonumber(amount)
if axis == "?" then
axis, sign = worldedit.player_axis(name)
amount = amount * sign
@@ -616,7 +624,7 @@ minetest.register_chatcommand("/copy", {
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
- local count = worldedit.copy(pos1, pos2, axis, tonumber(amount), tenv)
+ local count = worldedit.copy(pos1, pos2, axis, amount, tenv)
worldedit.player_notify(name, count .. " nodes copied")
end,
})
@@ -637,6 +645,7 @@ minetest.register_chatcommand("/move", {
worldedit.player_notify(name, "invalid usage: " .. param)
return
end
+ amount = tonumber(amount)
if axis == "?" then
axis, sign = worldedit.player_axis(name)
amount = amount * sign
@@ -646,7 +655,7 @@ minetest.register_chatcommand("/move", {
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
- local count = worldedit.move(pos1, pos2, axis, tonumber(amount), tenv)
+ local count = worldedit.move(pos1, pos2, axis, amount, tenv)
pos1[axis] = pos1[axis] + amount
pos2[axis] = pos2[axis] + amount
@@ -672,6 +681,7 @@ minetest.register_chatcommand("/stack", {
worldedit.player_notify(name, "invalid usage: " .. param)
return
end
+ count = tonumber(count)
if axis == "?" then
axis, sign = worldedit.player_axis(name)
count = count * sign
@@ -681,7 +691,7 @@ minetest.register_chatcommand("/stack", {
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
- local count = worldedit.stack(pos1, pos2, axis, tonumber(count), tenv)
+ local count = worldedit.stack(pos1, pos2, axis, count, tenv)
worldedit.player_notify(name, count .. " nodes stacked")
end,
})
@@ -1125,8 +1135,8 @@ minetest.register_chatcommand("/luatransform", {
if minetest.place_schematic then
minetest.register_chatcommand("/mtschemcreate", {
- params = "<filename>",
- description = "Creates a Minetest schematic of the box defined by position 1 and position 2, and saves it to <filename>",
+ params = "<file>",
+ description = "Save the current WorldEdit region using the Minetest Schematic format to \"(world folder)/schems/<filename>.mts\"",
privs = {worldedit=true},
func = function(name, param)
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
@@ -1154,8 +1164,8 @@ minetest.register_chatcommand("/mtschemcreate", {
})
minetest.register_chatcommand("/mtschemplace", {
- params = "<filename>",
- description = "Places the Minetest schematic identified by <filename> at WorldEdit position 1",
+ params = "<file>",
+ description = "Load nodes from \"(world folder)/schems/<file>.mts\" with position 1 of the current WorldEdit region as the origin",
privs = {worldedit=true},
func = function(name, param)
local pos = worldedit.pos1[name]
@@ -1219,3 +1229,19 @@ minetest.register_on_player_receive_fields(
end
)
end
+
+minetest.register_chatcommand("/clearobjects", {
+ params = "",
+ description = "Clears all objects within the WorldEdit region",
+ privs = {worldedit=true},
+ func = function(name, param)
+ local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
+ if pos1 == nil or pos2 == nil then
+ worldedit.player_notify(name, "no region selected")
+ return
+ end
+
+ local count = worldedit.clearobjects(pos1, pos2)
+ worldedit.player_notify(name, count .. " objects cleared")
+ end,
+})