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