]> git.lizzy.rs Git - worldedit.git/blobdiff - WorldEdit API.md
Fix deserialization of schematics with node names table
[worldedit.git] / WorldEdit API.md
index 41fab6931ac22865555237ae471b38e662b12f66..fc9cf652e0bda75d020d8a9842d9431beefd8f61 100644 (file)
 WorldEdit API\r
--------------\r
+=============\r
+The WorldEdit API is composed of multiple modules, each of which is independent and can be used without the other. Each module is contained within a single file.\r
+\r
+If needed, individual modules such as visualization.lua can be removed without affecting the rest of the program. The only file that cannot be removed is init.lua, which is necessary for the mod to run.\r
+\r
 For more information, see the [README](README.md).\r
 \r
-### worldedit.volume(pos1, pos2)\r
+General\r
+-------\r
 \r
-Determines the volume of the region defined by positions `pos1` and `pos2`.\r
+### value = worldedit.version\r
 \r
-Returns the volume.\r
+Contains the current version of WorldEdit in a table of the form `{major=MAJOR_INTEGER, minor=MINOR_INTEGER}`, where `MAJOR_INTEGER` is the major version (the number before the period) as an integer, and `MINOR_INTEGER` is the minor version (the number after the period) as an integer. This is intended for version checking purposes.\r
 \r
-### worldedit.set(pos1, pos2, nodename)\r
+### value = worldedit.version_string\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
+Contains the current version of WorldEdit in the form of a string `"MAJOR_INTEGER.MINOR_INTEGER"`, where `MAJOR_INTEGER` is the major version (the number before the period) as an integer, and `MINOR_INTEGER` is the minor version (the number after the period) as an integer. This is intended for display purposes.\r
+\r
+Manipulations\r
+-------------\r
+Contained in manipulations.lua, this module allows several node operations to be applied over a region.\r
+\r
+### count = worldedit.set(pos1, pos2, node_name)\r
+\r
+Sets a region defined by positions `pos1` and `pos2` to `node_name`. To clear a region, use "air" as the value of `node_name`.\r
+If `node_name` is a list of nodes, each set node is randomly picked from it.\r
 \r
 Returns the number of nodes set.\r
 \r
-### worldedit.replace(pos1, pos2, searchnode, replacenode)\r
+### `count = worldedit.set_param2(pos1, pos2, param2)`\r
+\r
+Sets the param2 values of all nodes in a region defined by positions `pos1` and `pos2` to `param2`.\r
+\r
+Returns the number of nodes set.\r
+\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
-### worldedit.hollow_sphere = function(pos, radius, nodename)\r
+### count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode)\r
 \r
-Adds a hollow sphere at `pos` with radius `radius`, composed of `nodename`.\r
+Replaces all nodes other than `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`.\r
 \r
-Returns the number of nodes added.\r
+Returns the number of nodes replaced.\r
+\r
+### count = worldedit.copy(pos1, pos2, axis, amount)\r
 \r
-### worldedit.sphere = function(pos, radius, nodename)\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
-Adds a sphere at `pos` with radius `radius`, composed of `nodename`.\r
+### count = worldedit.copy2(pos1, pos2, off)\r
+\r
+Copies the region defined by positions `pos1` and `pos2` by the offset vector `off`.\r
+Note that the offset needs to be big enough that there is no overlap.\r
+\r
+Returns the number of nodes copied.\r
+\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
+### 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
+### count = worldedit.stack2(pos1, pos2, direction, amount)\r
+\r
+Duplicates the region defined by positions `pos1` and `pos2` `amount` times with offset vector `direction`.\r
+Note that the offset vector needs to be big enough that there is no overlap.\r
+\r
+Returns the number of nodes stacked.\r
+\r
+### count, newpos1, newpos2 = worldedit.stretch(pos1, pos2, stretchx, stretchy, stretchz)\r
+\r
+Stretches the region defined by positions `pos1` and `pos2` by an factor of positive integers `stretchx`, `stretchy`. and `stretchz` along the X, Y, and Z axes, respectively, with `pos1` as the origin.\r
+\r
+Returns the number of nodes stretched, the new scaled position 1, and the new scaled position 2.\r
+\r
+### count, newpos1, newpos2 = 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, the new transposed position 1, and the new transposed position 2.\r
+\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
+### count, newpos2, newpos2 = 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, the new position 1, and the new position 2.\r
+\r
+### count = worldedit.orient(pos1, pos2, angle)\r
+\r
+Rotates all oriented nodes in a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise (90 degree increment) around the Y axis.\r
+\r
+Returns the number of nodes oriented.\r
+\r
+### count = worldedit.fixlight(pos1, pos2)\r
+\r
+Fixes the lighting in a region defined by positions `pos1` and `pos2`.\r
+\r
+Returns the number of nodes updated.\r
+\r
+### count = worldedit.clearobjects(pos1, pos2)\r
+\r
+Clears all objects in a region defined by the positions `pos1` and `pos2`.\r
+\r
+Returns the number of objects cleared.\r
+\r
+Primitives\r
+----------\r
+Contained in primitives.lua, this module allows the creation of several geometric primitives.\r
+\r
+### count = worldedit.cube(pos, width, height, length, node_name, hollow)\r
+\r
+Adds a cube with its ground level centered at `pos`, the dimensions `width` x `height` x `length`, composed of `node_name`.\r
 \r
 Returns the number of nodes added.\r
 \r
-### worldedit.hollow_cylinder(pos, axis, length, radius, nodename)\r
+### count = worldedit.sphere(pos, radius, node_name, hollow)\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
+Adds a sphere centered at `pos` with radius `radius`, composed of `node_name`.\r
 \r
 Returns the number of nodes added.\r
 \r
-### worldedit.cylinder(pos, axis, length, radius, nodename)\r
+### count = worldedit.dome(pos, radius, node_name, hollow)\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
+Adds a dome centered at `pos` with radius `radius`, composed of `node_name`.\r
 \r
 Returns the number of nodes added.\r
 \r
-### worldedit.pyramid(pos, height, nodename)\r
+### count = worldedit.cylinder(pos, axis, length, radius1, radius2, node_name, hollow)\r
 \r
-Adds a pyramid at `pos` with height `height`.\r
+Adds a cylinder-like at `pos` along the `axis` axis ("x" or "y" or "z") with length `length`, base radius `radius1` and top radius `radius2`, composed of `node_name`.\r
 \r
 Returns the number of nodes added.\r
 \r
-### worldedit.spiral(pos, width, height, spacer, nodename)\r
+### count = worldedit.pyramid(pos, axis, height, node_name, hollow)\r
 \r
-Adds a spiral at `pos` with width `width`, height `height`, space between walls `spacer`, composed of `nodename`.\r
+Adds a pyramid centered at `pos` along the `axis` axis ("x" or "y" or "z") with height `height`, composed of `node_name`.\r
 \r
 Returns the number of nodes added.\r
 \r
-### worldedit.copy(pos1, pos2, axis, amount)\r
+### count = worldedit.spiral(pos, length, height, spacer, node_name)\r
 \r
-Copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes.\r
+Adds a spiral centered at `pos` with side length `length`, height `height`, space between walls `spacer`, composed of `node_name`.\r
 \r
-Returns the number of nodes copied.\r
+Returns the number of nodes added.\r
 \r
-### worldedit.move(pos1, pos2, axis, amount)\r
+Visualization\r
+-------------\r
+Contained in visualization.lua, this module allows nodes to be visualized in different ways.\r
 \r
-Moves the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes.\r
+### volume = worldedit.volume(pos1, pos2)\r
 \r
-Returns the number of nodes moved.\r
+Determines the volume of the region defined by positions `pos1` and `pos2`.\r
 \r
-### worldedit.stack(pos1, pos2, axis, count)\r
+Returns the volume.\r
 \r
-Duplicates the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") `count` times.\r
+### count = worldedit.hide(pos1, pos2)\r
 \r
-Returns the number of nodes stacked.\r
+Hides all nodes in a region defined by positions `pos1` and `pos2` by non-destructively replacing them with invisible nodes.\r
 \r
-### worldedit.transpose(pos1, pos2, axis1, axis2)\r
+Returns the number of nodes hidden.\r
 \r
-Transposes a region defined by the positions `pos1` and `pos2` between the `axis1` and `axis2` axes ("x" or "y" or "z").\r
+### count = worldedit.suppress(pos1, pos2, node_name)\r
 \r
-Returns the number of nodes transposed.\r
+Suppresses all instances of `node_name` in a region defined by positions `pos1` and `pos2` by non-destructively replacing them with invisible nodes.\r
 \r
-### worldedit.flip(pos1, pos2, axis)\r
+Returns the number of nodes suppressed.\r
 \r
-Flips a region defined by the positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z").\r
+### count = worldedit.highlight(pos1, pos2, node_name)\r
 \r
-Returns the number of nodes flipped.\r
+Highlights all instances of `node_name` in a region defined by positions `pos1` and `pos2` by non-destructively hiding all other nodes.\r
 \r
-### worldedit.rotate(pos1, pos2, angle)\r
+Returns the number of nodes found.\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
+### 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
-Returns the number of nodes rotated.\r
+Returns the number of nodes restored.\r
+\r
+Serialization\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.dig(pos1, pos2)\r
+### version, extra_fields, content = worldedit.read_header(value)\r
 \r
-Digs a region defined by positions `pos1` and `pos2`.\r
+Reads the header from serialized data `value`.\r
 \r
-Returns the number of nodes dug.\r
+Returns the version as a positive integer (nil for unknown versions),\r
+extra header fields (nil if not supported), and the content after the header.\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
+Returns the serialized data and the number of nodes serialized, or nil.\r
 \r
-### worldedit.deserialize(originpos, value)\r
+### pos1, pos2, count = worldedit.allocate(origin_pos, value)\r
 \r
-Loads the nodes represented by string `value` at position `originpos`.\r
+Determines the volume the nodes represented by string `value` would occupy if deserialized at `origin_pos`.\r
 \r
-Returns the number of nodes deserialized.\r
+Returns the two corner positions and the number of nodes, or nil.\r
 \r
-### worldedit.deserialize_old(originpos, value)\r
+### count = worldedit.deserialize(origin_pos, value)\r
 \r
-Loads the nodes represented by string `value` at position `originpos`, using the older table-based WorldEdit format.\r
+Loads the nodes represented by string `value` at position `origin_pos`.\r
 \r
-This function is deprecated, and should not be used unless there is a need to support legacy WorldEdit save files.\r
+Returns the number of nodes deserialized or nil.\r
 \r
-Returns the number of nodes deserialized.\r
+Code\r
+----\r
+Contained in code.lua, this module allows arbitrary Lua code to be used with WorldEdit.\r
 \r
-### worldedit.metasave(pos1, pos2, file)\r
+### error = worldedit.lua(code)\r
 \r
-Saves the nodes and meta defined by positions `pos1` and `pos2` into a file.\r
+Executes `code` as a Lua chunk in the global namespace.\r
 \r
-Returns the number of nodes saved.\r
+Returns an error if the code fails or nil otherwise.\r
 \r
-### worldedit.metaload(pos1, file)\r
+### error = worldedit.luatransform(pos1, pos2, code)\r
 \r
-Loads the nodes and meta from `file` to position `pos1`.\r
+Executes `code` as a Lua chunk in the global namespace with the variable `pos` available, for each node in a region defined by positions `pos1` and `pos2`.\r
 \r
-Returns the number of nodes loaded.
\ No newline at end of file
+Returns an error if the code fails or nil otherwise.\r