-------------\r
Contained in manipulations.lua, this module allows several node operations to be applied over a region.\r
\r
-### worldedit.volume(pos1, pos2)\r
-\r
-Determines the volume of the region defined by positions `pos1` and `pos2`.\r
-\r
-Returns the volume.\r
-\r
-### worldedit.set(pos1, pos2, nodename)\r
+### count = worldedit.set(pos1, pos2, nodename)\r
\r
Sets a region defined by positions `pos1` and `pos2` to `nodename`. To clear to region, use "air" as the value of `nodename`.\r
\r
Returns the number of nodes set.\r
\r
-### worldedit.replace(pos1, pos2, searchnode, replacenode)\r
+### count = worldedit.replace(pos1, pos2, searchnode, replacenode)\r
\r
Replaces all instances of `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`.\r
\r
Returns the number of nodes replaced.\r
\r
-Returns the number of nodes added.\r
-\r
-### worldedit.copy(pos1, pos2, axis, amount)\r
+### count = worldedit.copy(pos1, pos2, axis, amount)\r
\r
Copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes.\r
\r
Returns the number of nodes copied.\r
\r
-### worldedit.move(pos1, pos2, axis, amount)\r
+### count = worldedit.move(pos1, pos2, axis, amount)\r
\r
Moves the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes.\r
\r
Returns the number of nodes moved.\r
\r
-### worldedit.stack(pos1, pos2, axis, count)\r
+### count = worldedit.stack(pos1, pos2, axis, count)\r
\r
Duplicates the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") `count` times.\r
\r
Returns the number of nodes stacked.\r
\r
-### worldedit.transpose(pos1, pos2, axis1, axis2)\r
+### count = worldedit.transpose(pos1, pos2, axis1, axis2)\r
\r
Transposes a region defined by the positions `pos1` and `pos2` between the `axis1` and `axis2` axes ("x" or "y" or "z").\r
\r
Returns the number of nodes transposed.\r
\r
-### worldedit.flip(pos1, pos2, axis)\r
+### count = worldedit.flip(pos1, pos2, axis)\r
\r
Flips a region defined by the positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z").\r
\r
Returns the number of nodes flipped.\r
\r
-### worldedit.rotate(pos1, pos2, angle)\r
+### count = worldedit.rotate(pos1, pos2, angle)\r
\r
Rotates a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise around the y axis (supporting 90 degree increments only).\r
\r
Returns the number of nodes rotated.\r
\r
-### worldedit.dig(pos1, pos2)\r
+### count = worldedit.dig(pos1, pos2)\r
\r
Digs a region defined by positions `pos1` and `pos2`.\r
\r
----------\r
Contained in primitives.lua, this module allows the creation of several geometric primitives.\r
\r
-### worldedit.hollow_sphere = function(pos, radius, nodename)\r
+### count = worldedit.hollow_sphere(pos, radius, nodename)\r
\r
Adds a hollow sphere at `pos` with radius `radius`, composed of `nodename`.\r
\r
Returns the number of nodes added.\r
\r
-### worldedit.sphere = function(pos, radius, nodename)\r
+### count = worldedit.sphere(pos, radius, nodename)\r
\r
Adds a sphere at `pos` with radius `radius`, composed of `nodename`.\r
\r
Returns the number of nodes added.\r
\r
-### worldedit.hollow_cylinder(pos, axis, length, radius, nodename)\r
+### count = worldedit.hollow_cylinder(pos, axis, length, radius, nodename)\r
\r
Adds a hollow cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, composed of `nodename`.\r
\r
Returns the number of nodes added.\r
\r
-### worldedit.cylinder(pos, axis, length, radius, nodename)\r
+### count = worldedit.cylinder(pos, axis, length, radius, nodename)\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`.\r
\r
Returns the number of nodes added.\r
\r
-### worldedit.pyramid(pos, height, nodename)\r
+### count = worldedit.pyramid(pos, height, nodename)\r
\r
Adds a pyramid at `pos` with height `height`.\r
\r
Returns the number of nodes added.\r
\r
-### worldedit.spiral(pos, width, height, spacer, nodename)\r
+### count = worldedit.spiral(pos, width, height, spacer, nodename)\r
\r
Adds a spiral at `pos` with width `width`, height `height`, space between walls `spacer`, composed of `nodename`.\r
\r
-------------\r
Contained in visualization.lua, this module allows nodes to be visualized in different ways.\r
\r
-### worldedit.hide(pos1, pos2)\r
+### volume = worldedit.volume(pos1, pos2)\r
+\r
+Determines the volume of the region defined by positions `pos1` and `pos2`.\r
+\r
+Returns the volume.\r
+\r
+### count = worldedit.hide(pos1, pos2)\r
\r
Hides all nodes in a region defined by positions `pos1` and `pos2` by non-destructively replacing them with invisible nodes.\r
\r
Returns the number of nodes hidden.\r
\r
-### worldedit.suppress(pos1, pos2, nodename)\r
+### count = worldedit.suppress(pos1, pos2, nodename)\r
\r
Suppresses all instances of `nodename` in a region defined by positions `pos1` and `pos2` by non-destructively replacing them with invisible nodes.\r
\r
Returns the number of nodes suppressed.\r
\r
-### worldedit.find(pos1, pos2, nodename)\r
+### count = worldedit.highlight(pos1, pos2, nodename)\r
\r
-Finds all instances of `nodename` in a region defined by positions `pos1` and `pos2` by non-destructively hiding all other nodes.\r
+Highlights all instances of `nodename` in a region defined by positions `pos1` and `pos2` by non-destructively hiding all other nodes.\r
\r
Returns the number of nodes found.\r
\r
-### worldedit.restore(pos1, pos2)\r
+### count = worldedit.restore(pos1, pos2)\r
\r
Restores all nodes hidden with WorldEdit functions in a region defined by positions `pos1` and `pos2`.\r
\r
-------------\r
Contained in serialization.lua, this module allows regions of nodes to be serialized and deserialized to formats suitable for use outside MineTest.\r
\r
-### worldedit.serialize(pos1, pos2)\r
+### data, count = worldedit.serialize(pos1, pos2)\r
\r
Converts the region defined by positions `pos1` and `pos2` into a single string.\r
\r
Returns the serialized data and the number of nodes serialized.\r
\r
-### worldedit.deserialize(originpos, value)\r
+### pos1, pos2, count = worldedit.allocate(originpos, value)\r
+\r
+Determines the volume the nodes represented by string `value` would occupy if deserialized at `originpos`.\r
+\r
+Returns the two corner positions and the number of nodes.\r
+\r
+### count = worldedit.deserialize(originpos, value)\r
\r
Loads the nodes represented by string `value` at position `originpos`.\r
\r
Returns the number of nodes deserialized.\r
\r
-### worldedit.deserialize_old(originpos, value)\r
+### count = worldedit.deserialize_old(originpos, value)\r
\r
Loads the nodes represented by string `value` at position `originpos`, using the older table-based WorldEdit format.\r
\r
\r
Returns the number of nodes deserialized.\r
\r
-### worldedit.metasave(pos1, pos2, file)\r
+### count = worldedit.metasave(pos1, pos2, file)\r
\r
Saves the nodes and meta defined by positions `pos1` and `pos2` into a file.\r
\r
Returns the number of nodes saved.\r
\r
-### worldedit.metaload(pos1, file)\r
+### count = worldedit.metaload(pos1, file)\r
\r
Loads the nodes and meta from `file` to position `pos1`.\r
\r
return result, count\r
end\r
\r
+--determines the volume the nodes represented by string `value` would occupy if deserialized at `originpos`, returning the two corner positions and the number of nodes\r
+worldedit.allocate = function(originpos, value)\r
+ local huge = math.huge\r
+ local pos1 = {x=huge, y=huge, z=huge}\r
+ local pos2 = {x=-huge, y=-huge, z=-huge}\r
+ local originx, originy, originz = originpos.x, originpos.y, originpos.z\r
+ local count = 0\r
+ for x, y, z, name, param1, param2 in value:gmatch("([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)%s+([^%s]+)%s+(%d+)%s+(%d+)[^\r\n]*[\r\n]*") do --match node entries\r
+ x, y, z = originx + tonumber(x), originy + tonumber(y), originz + tonumber(z)\r
+ if x < pos1.x then\r
+ pos1.x = x\r
+ end\r
+ if y < pos1.y then\r
+ pos1.y = y\r
+ end\r
+ if z < pos1.z then\r
+ pos1.z = z\r
+ end\r
+ if x > pos2.x then\r
+ pos2.x = x\r
+ end\r
+ if y > pos2.y then\r
+ pos2.y = y\r
+ end\r
+ if z > pos2.z then\r
+ pos2.z = z\r
+ end\r
+ count = count + 1\r
+ end\r
+ return pos1, pos2, count\r
+end\r
+\r
--loads the nodes represented by string `value` at position `originpos`, returning the number of nodes deserialized\r
worldedit.deserialize = function(originpos, value)\r
local pos = {x=0, y=0, z=0}\r
local node = {name="", param1=0, param2=0}\r
+ local originx, originy, originz = originpos.x, originpos.y, originpos.z\r
local count = 0\r
local env = minetest.env\r
for x, y, z, name, param1, param2 in value:gmatch("([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)%s+([^%s]+)%s+(%d+)%s+(%d+)[^\r\n]*[\r\n]*") do --match node entries\r
- pos.x = originpos.x + tonumber(x)\r
- pos.y = originpos.y + tonumber(y)\r
- pos.z = originpos.z + tonumber(z)\r
+ pos.x = originx + tonumber(x)\r
+ pos.y = originy + tonumber(y)\r
+ pos.z = originz + tonumber(z)\r
node.name = name\r
node.param1 = param1\r
node.param2 = param2\r
end,\r
})\r
\r
-minetest.register_chatcommand("/find", {\r
+minetest.register_chatcommand("/highlight", {\r
params = "<node>",\r
- description = "Find <node> in the current WorldEdit region by hiding everything else non-destructively",\r
+ description = "Highlight <node> in the current WorldEdit region by hiding everything else non-destructively",\r
privs = {worldedit=true},\r
func = function(name, param)\r
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
return\r
end\r
\r
- local count = worldedit.find(pos1, pos2, param)\r
- minetest.chat_send_player(name, count .. " nodes found")\r
+ local count = worldedit.highlight(pos1, pos2, param)\r
+ minetest.chat_send_player(name, count .. " nodes highlighted")\r
end,\r
})\r
\r
end,\r
})\r
\r
+minetest.register_chatcommand("/allocate", {\r
+ params = "<file>",\r
+ description = "Set the region defined by nodes from \"(world folder)/schems/<file>.we\" as the current WorldEdit region",\r
+ privs = {worldedit=true},\r
+ func = function(name, param)\r
+ local pos1 = worldedit.pos1[name]\r
+ if pos1 == nil then\r
+ minetest.chat_send_player(name, "No WorldEdit region selected")\r
+ return\r
+ end\r
+\r
+ if param == "" then\r
+ minetest.chat_send_player(name, "Invalid usage: " .. param)\r
+ return\r
+ end\r
+\r
+ local filename = minetest.get_worldpath() .. "/schems/" .. param .. ".we"\r
+ local file, err = io.open(filename, "rb")\r
+ if err ~= nil then\r
+ minetest.chat_send_player(name, "Could not open file \"" .. filename .. "\"")\r
+ return\r
+ end\r
+ local value = file:read("*a")\r
+ file:close()\r
+\r
+ local nodepos1, nodepos2, count = worldedit.allocate(pos1, value)\r
+\r
+ worldedit.pos1[name] = nodepos1\r
+ worldedit.mark_pos1(name)\r
+ worldedit.pos2[name] = nodepos2\r
+ worldedit.mark_pos2(name)\r
+\r
+ minetest.chat_send_player(name, count .. " nodes allocated")\r
+ end,\r
+})\r
+\r
minetest.register_chatcommand("/load", {\r
params = "<file>",\r
description = "Load nodes from \"(world folder)/schems/<file>.we\" with position 1 of the current WorldEdit region as the origin",\r