]> git.lizzy.rs Git - worldedit.git/blob - WorldEdit API.md
Always use faster vmanip copying code
[worldedit.git] / WorldEdit API.md
1 WorldEdit API\r
2 =============\r
3 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
4 \r
5 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
6 \r
7 For more information, see the [README](README.md).\r
8 \r
9 General\r
10 -------\r
11 \r
12 ### value = worldedit.version\r
13 \r
14 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
15 \r
16 ### value = worldedit.version_string\r
17 \r
18 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
19 \r
20 Manipulations\r
21 -------------\r
22 Contained in manipulations.lua, this module allows several node operations to be applied over a region.\r
23 \r
24 ### count = worldedit.set(pos1, pos2, node_name)\r
25 \r
26 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
27 If `node_name` is a list of nodes, each set node is randomly picked from it.\r
28 \r
29 Returns the number of nodes set.\r
30 \r
31 ### `count = worldedit.set_param2(pos1, pos2, param2)`\r
32 \r
33 Sets the param2 values of all nodes in a region defined by positions `pos1` and `pos2` to `param2`.\r
34 \r
35 Returns the number of nodes set.\r
36 \r
37 ### count = worldedit.replace(pos1, pos2, searchnode, replacenode)\r
38 \r
39 Replaces all instances of `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`.\r
40 \r
41 Returns the number of nodes replaced.\r
42 \r
43 ### count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode)\r
44 \r
45 Replaces all nodes other than `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`.\r
46 \r
47 Returns the number of nodes replaced.\r
48 \r
49 ### count = worldedit.copy(pos1, pos2, axis, amount)\r
50 \r
51 Copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes.\r
52 \r
53 Returns the number of nodes copied.\r
54 \r
55 ### count = worldedit.copy2(pos1, pos2, off)\r
56 \r
57 Copies the region defined by positions `pos1` and `pos2` by the offset vector `off`.\r
58 Note that the offset needs to be big enough that there is no overlap.\r
59 \r
60 Returns the number of nodes copied.\r
61 \r
62 ### count = worldedit.move(pos1, pos2, axis, amount)\r
63 \r
64 Moves the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes.\r
65 \r
66 Returns the number of nodes moved.\r
67 \r
68 ### count = worldedit.stack(pos1, pos2, axis, count)\r
69 \r
70 Duplicates the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") `count` times.\r
71 \r
72 Returns the number of nodes stacked.\r
73 \r
74 ### count = worldedit.stack2(pos1, pos2, direction, amount)\r
75 \r
76 Duplicates the region defined by positions `pos1` and `pos2` `amount` times with offset vector `direction`.\r
77 \r
78 Returns the number of nodes stacked.\r
79 \r
80 ### count, newpos1, newpos2 = worldedit.stretch(pos1, pos2, stretchx, stretchy, stretchz)\r
81 \r
82 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
83 \r
84 Returns the number of nodes stretched, the new scaled position 1, and the new scaled position 2.\r
85 \r
86 ### count, newpos1, newpos2 = worldedit.transpose(pos1, pos2, axis1, axis2)\r
87 \r
88 Transposes a region defined by the positions `pos1` and `pos2` between the `axis1` and `axis2` axes ("x" or "y" or "z").\r
89 \r
90 Returns the number of nodes transposed, the new transposed position 1, and the new transposed position 2.\r
91 \r
92 ### count = worldedit.flip(pos1, pos2, axis)\r
93 \r
94 Flips a region defined by the positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z").\r
95 \r
96 Returns the number of nodes flipped.\r
97 \r
98 ### count, newpos2, newpos2 = worldedit.rotate(pos1, pos2, angle)\r
99 \r
100 Rotates a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise around the y axis (supporting 90 degree increments only).\r
101 \r
102 Returns the number of nodes rotated, the new position 1, and the new position 2.\r
103 \r
104 ### count = worldedit.orient(pos1, pos2, angle)\r
105 \r
106 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
107 \r
108 Returns the number of nodes oriented.\r
109 \r
110 ### count = worldedit.fixlight(pos1, pos2)\r
111 \r
112 Fixes the lighting in a region defined by positions `pos1` and `pos2`.\r
113 \r
114 Returns the number of nodes updated.\r
115 \r
116 ### count = worldedit.clearobjects(pos1, pos2)\r
117 \r
118 Clears all objects in a region defined by the positions `pos1` and `pos2`.\r
119 \r
120 Returns the number of objects cleared.\r
121 \r
122 Primitives\r
123 ----------\r
124 Contained in primitives.lua, this module allows the creation of several geometric primitives.\r
125 \r
126 ### count = worldedit.cube(pos, width, height, length, node_name, hollow)\r
127 \r
128 Adds a cube with its ground level centered at `pos`, the dimensions `width` x `height` x `length`, composed of `node_name`.\r
129 \r
130 Returns the number of nodes added.\r
131 \r
132 ### count = worldedit.sphere(pos, radius, node_name, hollow)\r
133 \r
134 Adds a sphere centered at `pos` with radius `radius`, composed of `node_name`.\r
135 \r
136 Returns the number of nodes added.\r
137 \r
138 ### count = worldedit.dome(pos, radius, node_name, hollow)\r
139 \r
140 Adds a dome centered at `pos` with radius `radius`, composed of `node_name`.\r
141 \r
142 Returns the number of nodes added.\r
143 \r
144 ### count = worldedit.cylinder(pos, axis, length, radius1, radius2, node_name, hollow)\r
145 \r
146 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
147 \r
148 Returns the number of nodes added.\r
149 \r
150 ### count = worldedit.pyramid(pos, axis, height, node_name, hollow)\r
151 \r
152 Adds a pyramid centered at `pos` along the `axis` axis ("x" or "y" or "z") with height `height`, composed of `node_name`.\r
153 \r
154 Returns the number of nodes added.\r
155 \r
156 ### count = worldedit.spiral(pos, length, height, spacer, node_name)\r
157 \r
158 Adds a spiral centered at `pos` with side length `length`, height `height`, space between walls `spacer`, composed of `node_name`.\r
159 \r
160 Returns the number of nodes added.\r
161 \r
162 Visualization\r
163 -------------\r
164 Contained in visualization.lua, this module allows nodes to be visualized in different ways.\r
165 \r
166 ### volume = worldedit.volume(pos1, pos2)\r
167 \r
168 Determines the volume of the region defined by positions `pos1` and `pos2`.\r
169 \r
170 Returns the volume.\r
171 \r
172 ### count = worldedit.hide(pos1, pos2)\r
173 \r
174 Hides all nodes in a region defined by positions `pos1` and `pos2` by non-destructively replacing them with invisible nodes.\r
175 \r
176 Returns the number of nodes hidden.\r
177 \r
178 ### count = worldedit.suppress(pos1, pos2, node_name)\r
179 \r
180 Suppresses all instances of `node_name` in a region defined by positions `pos1` and `pos2` by non-destructively replacing them with invisible nodes.\r
181 \r
182 Returns the number of nodes suppressed.\r
183 \r
184 ### count = worldedit.highlight(pos1, pos2, node_name)\r
185 \r
186 Highlights all instances of `node_name` in a region defined by positions `pos1` and `pos2` by non-destructively hiding all other nodes.\r
187 \r
188 Returns the number of nodes found.\r
189 \r
190 ### count = worldedit.restore(pos1, pos2)\r
191 \r
192 Restores all nodes hidden with WorldEdit functions in a region defined by positions `pos1` and `pos2`.\r
193 \r
194 Returns the number of nodes restored.\r
195 \r
196 Serialization\r
197 -------------\r
198 Contained in serialization.lua, this module allows regions of nodes to be serialized and deserialized to formats suitable for use outside Minetest.\r
199 \r
200 ### version, extra_fields, content = worldedit.read_header(value)\r
201 \r
202 Reads the header from serialized data `value`.\r
203 \r
204 Returns the version as a positive integer (nil for unknown versions),\r
205 extra header fields (nil if not supported), and the content after the header.\r
206 \r
207 ### data, count = worldedit.serialize(pos1, pos2)\r
208 \r
209 Converts the region defined by positions `pos1` and `pos2` into a single string.\r
210 \r
211 Returns the serialized data and the number of nodes serialized, or nil.\r
212 \r
213 ### pos1, pos2, count = worldedit.allocate(origin_pos, value)\r
214 \r
215 Determines the volume the nodes represented by string `value` would occupy if deserialized at `origin_pos`.\r
216 \r
217 Returns the two corner positions and the number of nodes, or nil.\r
218 \r
219 ### count = worldedit.deserialize(origin_pos, value)\r
220 \r
221 Loads the nodes represented by string `value` at position `origin_pos`.\r
222 \r
223 Returns the number of nodes deserialized or nil.\r
224 \r
225 Code\r
226 ----\r
227 Contained in code.lua, this module allows arbitrary Lua code to be used with WorldEdit.\r
228 \r
229 ### error = worldedit.lua(code)\r
230 \r
231 Executes `code` as a Lua chunk in the global namespace.\r
232 \r
233 Returns an error if the code fails or nil otherwise.\r
234 \r
235 ### error = worldedit.luatransform(pos1, pos2, code)\r
236 \r
237 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
238 \r
239 Returns an error if the code fails or nil otherwise.\r