Skip to content

Commit 175ac21

Browse files
committedJul 6, 2014
Documentation for //stack2, code style fixes, add author section to README.
1 parent b32aadd commit 175ac21

File tree

4 files changed

+165
-146
lines changed

4 files changed

+165
-146
lines changed
 

‎Chat Commands.md

+11-4
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ Display the volume of the current WorldEdit region.
9898

9999
//volume
100100

101-
### `//set <node>`
101+
### `//set <node1> ...`
102102

103-
Set the current WorldEdit region to `<node>`.
103+
Set the current WorldEdit region to a random mix of `<node1>`, `...`.
104104

105105
//set air
106-
//set cactus
107-
//set Bronze Block
106+
//set cactus stone glass
107+
//set Bronze
108108
//set mesecons:wire_00000000_off
109109

110110
### `//replace <search node> <replace node>`
@@ -219,6 +219,13 @@ Stack the current WorldEdit region along the x/y/z/? axis `<count>` times.
219219
//stack z +5
220220
//stack ? 12
221221

222+
### `//stack2 <count> <x> <y> <z>`
223+
224+
Stack the current WorldEdit region `<count>` times by offset `<x>`, `<y>`, `<z>`.
225+
226+
//stack2 5 3 8 2
227+
//stack2 1 -1 -1 -1
228+
222229
### `//scale <factor>`
223230

224231
Scale the current WorldEdit positions and region by a factor of positive integer `<factor>` with position 1 as the origin.

‎README.md

+15
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,21 @@ The WorldEdit Schematic format is accessed via the WorldEdit API, or WorldEdit s
130130

131131
The second is the Minetest Schematic format (MTS). The details of this format may be found in the Minetest documentation and are out of the scope of this document. Access to this format is done via specialized MTS commands such as `//mtschemcreate` and `//mtschemplace`.
132132

133+
Authors
134+
-------
135+
WorldEdit would not be possible without the contributions of many developers and designers. Below, they are listed alphabetically:
136+
137+
cheapie
138+
cornernote
139+
cyisfor
140+
electricface
141+
kaeza
142+
khonkhortisan
143+
sfan5
144+
ShadowNinja
145+
spillz
146+
Uberi/Temperest
147+
133148
License
134149
-------
135150
Copyright 2013 sfan5, Anthony Zhang (Uberi/Temperest), and Brett O'Donnell (cornernote).

‎worldedit/manipulations.lua

+121-113
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,16 @@ worldedit.set = function(pos1, pos2, nodenames)
4848
for i,v in ipairs(nodenames) do
4949
node_ids[i] = minetest.get_content_id(nodenames[i])
5050
end
51-
for i in area:iterp(pos1, pos2) do
52-
nodes[i] = node_ids[math.random(#node_ids)]
51+
if #node_ids == 1 then --only one type of node
52+
local id = node_ids[1]
53+
for i in area:iterp(pos1, pos2) do
54+
nodes[i] = node_ids[id]
55+
end
56+
else --fill randomly with all types of specified nodes
57+
local id_count, rand = #node_ids, math.random
58+
for i in area:iterp(pos1, pos2) do
59+
nodes[i] = node_ids[rand(id_count)]
60+
end
5361
end
5462

5563
--update map nodes
@@ -173,126 +181,126 @@ worldedit.copy = function(pos1, pos2, axis, amount) --wip: replace the old versi
173181
end
174182

175183
worldedit.copy2 = function(pos1, pos2, direction, volume)
176-
-- the overlap shouldn't matter as long as we
177-
-- 1) start at the furthest separated corner
178-
-- 2) complete an edge before moving inward, either edge works
179-
-- 3) complete a face before moving inward, similarly
180-
--
181-
-- to do this I
182-
-- 1) find the furthest destination in the direction, of each axis
183-
-- 2) call those the furthest separated corner
184-
-- 3) make sure to iterate inward from there
185-
-- 4) nested loop to make sure complete edge, complete face, then complete cube.
186-
184+
-- the overlap shouldn't matter as long as we
185+
-- 1) start at the furthest separated corner
186+
-- 2) complete an edge before moving inward, either edge works
187+
-- 3) complete a face before moving inward, similarly
188+
--
189+
-- to do this I
190+
-- 1) find the furthest destination in the direction, of each axis
191+
-- 2) call those the furthest separated corner
192+
-- 3) make sure to iterate inward from there
193+
-- 4) nested loop to make sure complete edge, complete face, then complete cube.
194+
187195
local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node
188-
local somemeta = get_meta(pos1) -- hax lol
189-
local to_table = somemeta.to_table
190-
local from_table = somemeta.from_table
191-
somemeta = nil
196+
local somemeta = get_meta(pos1) -- hax lol
197+
local to_table = somemeta.to_table
198+
local from_table = somemeta.from_table
199+
somemeta = nil
192200

193201
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
194202
local manip = minetest.get_voxel_manip()
195203
manip:read_from_map(pos1, pos2)
196204

197-
local sx,sy,sz -- direction sign
198-
local ix,iy,iz -- initial destination
199-
local ex,ey,ez -- final destination
200-
local originalx,originaly,originalz -- source
201-
-- vim -> :'<,'>s/\<\([ioes]\?\)x\>/\1y/g
202-
if direction.x > 0 then
203-
originalx = pos2.x
204-
ix = originalx + direction.x
205-
ex = pos1.x + direction.x
206-
sx = -1
207-
elseif direction.x < 0 then
208-
originalx = pos1.x
209-
ix = originalx + direction.x
210-
ex = pos2.x + direction.x
211-
sx = 1
212-
else
213-
originalx = pos1.x
214-
ix = originalx -- whatever
215-
ex = pos2.x
216-
sx = 1
217-
end
205+
local sx, sy, sz -- direction sign
206+
local ix, iy, iz -- initial destination
207+
local ex, ey, ez -- final destination
208+
local originalx, originaly, originalz -- source
209+
-- vim -> :'<,'>s/\<\([ioes]\?\)x\>/\1y/g
210+
if direction.x > 0 then
211+
originalx = pos2.x
212+
ix = originalx + direction.x
213+
ex = pos1.x + direction.x
214+
sx = -1
215+
elseif direction.x < 0 then
216+
originalx = pos1.x
217+
ix = originalx + direction.x
218+
ex = pos2.x + direction.x
219+
sx = 1
220+
else
221+
originalx = pos1.x
222+
ix = originalx -- whatever
223+
ex = pos2.x
224+
sx = 1
225+
end
218226

219-
if direction.y > 0 then
220-
originaly = pos2.y
221-
iy = originaly + direction.y
222-
ey = pos1.y + direction.y
223-
sy = -1
224-
elseif direction.y < 0 then
225-
originaly = pos1.y
226-
iy = originaly + direction.y
227-
ey = pos2.y + direction.y
228-
sy = 1
229-
else
230-
originaly = pos1.y
231-
iy = originaly -- whatever
232-
ey = pos2.y
233-
sy = 1
234-
end
227+
if direction.y > 0 then
228+
originaly = pos2.y
229+
iy = originaly + direction.y
230+
ey = pos1.y + direction.y
231+
sy = -1
232+
elseif direction.y < 0 then
233+
originaly = pos1.y
234+
iy = originaly + direction.y
235+
ey = pos2.y + direction.y
236+
sy = 1
237+
else
238+
originaly = pos1.y
239+
iy = originaly -- whatever
240+
ey = pos2.y
241+
sy = 1
242+
end
235243

236-
if direction.z > 0 then
237-
originalz = pos2.z
238-
iz = originalz + direction.z
239-
ez = pos1.z + direction.z
240-
sz = -1
241-
elseif direction.z < 0 then
242-
originalz = pos1.z
243-
iz = originalz + direction.z
244-
ez = pos2.z + direction.z
245-
sz = 1
246-
else
247-
originalz = pos1.z
248-
iz = originalz -- whatever
249-
ez = pos2.z
250-
sz = 1
251-
end
252-
-- print('copy',originalx,ix,ex,sx,originaly,iy,ey,sy,originalz,iz,ez,sz)
253-
254-
local ox,oy,oz
255-
256-
ox = originalx
257-
for x = ix,ex,sx do
258-
oy = originaly
259-
for y = iy,ey,sy do
260-
oz = originalz
261-
for z = iz,ez,sz do
262-
-- reusing pos1/pos2 as source/dest here
263-
pos1.x = ox; pos1.y = oy; pos1.z = oz
264-
pos2.x = x; pos2.y = y; pos2.z = z
265-
local node = get_node(pos1)
244+
if direction.z > 0 then
245+
originalz = pos2.z
246+
iz = originalz + direction.z
247+
ez = pos1.z + direction.z
248+
sz = -1
249+
elseif direction.z < 0 then
250+
originalz = pos1.z
251+
iz = originalz + direction.z
252+
ez = pos2.z + direction.z
253+
sz = 1
254+
else
255+
originalz = pos1.z
256+
iz = originalz -- whatever
257+
ez = pos2.z
258+
sz = 1
259+
end
260+
-- print('copy',originalx,ix,ex,sx,originaly,iy,ey,sy,originalz,iz,ez,sz)
261+
262+
local ox,oy,oz
263+
264+
ox = originalx
265+
for x = ix, ex, sx do
266+
oy = originaly
267+
for y = iy, ey, sy do
268+
oz = originalz
269+
for z = iz, ez, sz do
270+
-- reusing pos1/pos2 as source/dest here
271+
pos1.x, pos1.y, pos1.z = ox, oy, oz
272+
pos2.x, pos2.y, pos2.z = x, y, z
273+
local node = get_node(pos1)
266274
local meta = to_table(get_meta(pos1)) --get meta of current node
267-
add_node(pos2,node)
268-
from_table(get_meta(pos2),meta)
269-
oz = oz + sz
270-
end
271-
oy = oy + sy
272-
end
273-
ox = ox + sx
274-
end
275-
end
276-
277-
worldedit.stack2 = function(pos1, pos2, direction, amount, finished)
278-
local i = 0
279-
local translated = {x=0,y=0,z=0}
280-
local function nextone()
281-
if i <= amount then
282-
i = i + 1
283-
translated.x = translated.x + direction.x
284-
translated.y = translated.y + direction.y
285-
translated.z = translated.z + direction.z
286-
worldedit.copy2(pos1,pos2,translated,volume)
287-
minetest.after(0,nextone)
288-
else
289-
if finished then
290-
finished()
291-
end
292-
end
293-
end
294-
nextone()
295-
return nil
275+
add_node(pos2,node)
276+
from_table(get_meta(pos2),meta)
277+
oz = oz + sz
278+
end
279+
oy = oy + sy
280+
end
281+
ox = ox + sx
282+
end
283+
end
284+
285+
worldedit.stack2 = function(pos1, pos2, direction, amount, finished)
286+
local i = 0
287+
local translated = {x=0,y=0,z=0}
288+
local function nextone()
289+
if i <= amount then
290+
i = i + 1
291+
translated.x = translated.x + direction.x
292+
translated.y = translated.y + direction.y
293+
translated.z = translated.z + direction.z
294+
worldedit.copy2(pos1, pos2, translated, volume)
295+
minetest.after(0, nextone)
296+
else
297+
if finished then
298+
finished()
299+
end
300+
end
301+
end
302+
nextone()
303+
return nil
296304
end
297305

298306
--copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes, returning the number of nodes copied

‎worldedit_commands/init.lua

+18-29
Original file line numberDiff line numberDiff line change
@@ -279,19 +279,18 @@ minetest.register_chatcommand("/volume", {
279279
})
280280

281281
minetest.register_chatcommand("/set", {
282-
params = "<node>",
283-
description = "Set the current WorldEdit region to <node>",
282+
params = "<node1> ...",
283+
description = "Set the current WorldEdit region to a random mix of <node1>, ...",
284284
privs = {worldedit=true},
285285
func = safe_region(function(name, param)
286286
local nodes = {}
287-
288287
for nodename in param:gmatch("[^%s]+") do
289288
local node = get_node(name, nodename)
290289
if not node then
291-
worldedit.player_notify(name, 'Could not identify node "'..name..'"')
290+
worldedit.player_notify(name, "Could not identify node \"" .. name .. "\"")
292291
return
293292
end
294-
nodes[#nodes+1] = node
293+
nodes[#nodes + 1] = node
295294
end
296295

297296
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
@@ -620,47 +619,37 @@ minetest.register_chatcommand("/stack", {
620619
})
621620

622621
minetest.register_chatcommand("/stack2", {
623-
params = "<count> <x>/<y>/<z>",
624-
description = "Stack the current WorldEdit region <count> times translating each time by x, y and z in the respective directions.",
622+
params = "<count> <x> <y> <z>",
623+
description = "Stack the current WorldEdit region <count> times by offset <x>, <y>, <z>",
625624
privs = {worldedit=true},
626625
func = function(name, param)
627626
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
628627
if pos1 == nil or pos2 == nil then
629-
worldedit.player_notify(name, "Select a position first!")
628+
worldedit.player_notify(name, "Select a position first!")
630629
return
631630
end
632-
local repetitions, incs = param:match("([0-9]+)%s*(.+)")
633-
repetitions = repetitions and tonumber(repetitions)
631+
local repetitions, incs = param:match("(%d+)%s*(.+)")
634632
if repetitions == nil then
635633
worldedit.player_notify(name, "invalid count: " .. param)
636-
return
634+
return
637635
end
636+
repetitions = tonumber(repetitions)
638637

639-
local x,y,z = incs:match("(.+)/(.+)/(.+)")
638+
local x, y, z = incs:match("([+-]?%d+) ([+-]%d+) ([+-]%d+)")
640639
if x == nil then
641640
worldedit.player_notify(name, "invalid increments: " .. param)
642641
return
643642
end
644-
x = tonumber(x)
645-
y = tonumber(y)
646-
z = tonumber(z)
647-
if x == nil or y == nil or z == nil then
648-
worldedit.player_notify(name, "increments must be numbers: " .. param)
649-
return
650-
end
643+
x, y, z = tonumber(x), tonumber(y), tonumber(z)
651644

652-
local count = worldedit.volume(pos1,pos2) * repetitions
645+
local count = worldedit.volume(pos1, pos2) * repetitions
653646

654647
return safe_region(function()
655-
worldedit.stack2(pos1, pos2, {x=x,y=y,z=z}, repetitions,
656-
function()
657-
worldedit.player_notify(name, count .. " nodes stacked")
658-
end)
659-
660-
end,
661-
function()
662-
return count
663-
end)(name,param) -- more hax
648+
worldedit.stack2(pos1, pos2, {x=x, y=y, z=z}, repetitions,
649+
function() worldedit.player_notify(name, count .. " nodes stacked") end)
650+
end, function()
651+
return count
652+
end)(name,param) -- more hax
664653
end
665654
})
666655

0 commit comments

Comments
 (0)
Please sign in to comment.