Clean up command code for //stack, //stack2

This commit is contained in:
sfan5 2019-09-08 22:13:35 +02:00
parent de566d2e3e
commit 0919f7cab3
1 changed files with 25 additions and 17 deletions

View File

@ -819,8 +819,12 @@ minetest.register_chatcommand("/stack", {
axis, sign = worldedit.player_axis(name) axis, sign = worldedit.player_axis(name)
repetitions = repetitions * sign repetitions = repetitions * sign
end end
local count = worldedit.stack(worldedit.pos1[name], worldedit.pos2[name], axis, repetitions)
worldedit.player_notify(name, count .. " nodes stacked") local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
local count = worldedit.volume(pos1, pos2) * math.abs(repetitions)
worldedit.stack(pos1, pos2, axis, repetitions, function()
worldedit.player_notify(name, count .. " nodes stacked")
end)
end, end,
function(name, param) function(name, param)
local found, _, axis, repetitions = param:find("^([xyz%?])%s+([+-]?%d+)$") local found, _, axis, repetitions = param:find("^([xyz%?])%s+([+-]?%d+)$")
@ -828,8 +832,9 @@ minetest.register_chatcommand("/stack", {
worldedit.player_notify(name, "invalid usage: " .. param) worldedit.player_notify(name, "invalid usage: " .. param)
return return
end end
local count = check_region(name, param) local count = check_region(name, param)
if count then return (tonumber(repetitions) + 1) * count end if count then return tonumber(repetitions) * count end
return nil return nil
end), end),
}) })
@ -838,15 +843,9 @@ minetest.register_chatcommand("/stack2", {
params = "<count> <x> <y> <z>", params = "<count> <x> <y> <z>",
description = "Stack the current WorldEdit region <count> times by offset <x>, <y>, <z>", description = "Stack the current WorldEdit region <count> times by offset <x>, <y>, <z>",
privs = {worldedit=true}, privs = {worldedit=true},
func = function(name, param) func = safe_region(function(name, param)
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
if pos1 == nil or pos2 == nil then
worldedit.player_notify(name, "Select a position first!")
return
end
local repetitions, incs = param:match("(%d+)%s*(.+)") local repetitions, incs = param:match("(%d+)%s*(.+)")
if repetitions == nil then if repetitions == nil then
worldedit.player_notify(name, "invalid count: " .. param)
return return
end end
repetitions = tonumber(repetitions) repetitions = tonumber(repetitions)
@ -858,15 +857,24 @@ minetest.register_chatcommand("/stack2", {
end end
x, y, z = tonumber(x), tonumber(y), tonumber(z) x, y, z = tonumber(x), tonumber(y), tonumber(z)
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
local count = worldedit.volume(pos1, pos2) * repetitions local count = worldedit.volume(pos1, pos2) * repetitions
worldedit.stack2(pos1, pos2, {x=x, y=y, z=z}, repetitions, function()
worldedit.player_notify(name, count .. " nodes stacked")
end)
end,
function(name, param)
local repetitions, incs = param:match("(%d+)%s*(.+)")
if repetitions == nil then
worldedit.player_notify(name, "invalid count: " .. param)
return
end
repetitions = tonumber(repetitions)
return safe_region(function() local count = check_region(name, param)
worldedit.stack2(pos1, pos2, {x=x, y=y, z=z}, repetitions, if count then return repetitions * count end
function() worldedit.player_notify(name, count .. " nodes stacked") end) return nil
end, function() end),
return count
end)(name,param) -- more hax --wip: clean this up a little bit
end
}) })