mirror of
https://github.com/Uberi/Minetest-WorldEdit.git
synced 2024-12-24 17:50:40 +01:00
Implement //cubeapply
This commit is contained in:
parent
5e8bfd5166
commit
963a9f6b96
@ -476,3 +476,12 @@ Note that this functionality requires the `worldedit_brush` mod enabled.
|
||||
//brush cube 8 8 8 Cobblestone
|
||||
//brush spr 12 glass
|
||||
//brush none
|
||||
|
||||
### `//cubeapply <size> <command> [parameters]`
|
||||
|
||||
Selects a cube with side length of `<size>` around the WorldEdit position 1 and runs the given `<command>` on the newly selected region.
|
||||
This is mostly useful for brushes since it allows commands such as `//replace` to be ran, but it can also be used standalone.
|
||||
|
||||
//cubeapply 10 replaceinverse air default:water_source
|
||||
//brush cubeapply 15 drain
|
||||
//brush cubeapply 1 deleteblocks
|
||||
|
@ -207,3 +207,49 @@ worldedit.register_command("contract", {
|
||||
return true, "Region contracted by " .. (amount + rev_amount) .. " nodes"
|
||||
end,
|
||||
})
|
||||
|
||||
worldedit.register_command("cubeapply", {
|
||||
params = "<size> <command> [parameters]",
|
||||
description = "Select a cube with side length <size> around position 1 and run <command> on region",
|
||||
privs = {worldedit=true},
|
||||
require_pos = 1,
|
||||
parse = function(param)
|
||||
local found, _, side_length, cmd, args = param:find("^(%d+)%s+([^%s]+)%s*(.*)$")
|
||||
if found == nil then
|
||||
return false
|
||||
end
|
||||
local cmddef = worldedit.registered_commands[cmd]
|
||||
if cmddef == nil or cmddef.require_pos ~= 2 then
|
||||
return false, "invalid usage: //" .. cmd .. " cannot be used with cubeapply"
|
||||
end
|
||||
-- run parsing of target command
|
||||
local parsed = {cmddef.parse(args)}
|
||||
if not table.remove(parsed, 1) then
|
||||
return false, parsed[1]
|
||||
end
|
||||
return true, tonumber(side_length), cmd, parsed
|
||||
end,
|
||||
nodes_needed = function(name, side_length, cmd, parsed)
|
||||
-- its not possible to defer to the target command at this point
|
||||
return side_length * side_length * side_length
|
||||
end,
|
||||
func = function(name, side_length, cmd, parsed)
|
||||
local cmddef = assert(worldedit.registered_commands[cmd])
|
||||
local success, missing_privs = minetest.check_player_privs(name, cmddef.privs)
|
||||
if not success then
|
||||
worldedit.player_notify(name, "Missing privileges: " ..
|
||||
table.concat(missing_privs, ", "))
|
||||
return
|
||||
end
|
||||
|
||||
-- update region to be the cube the user wanted
|
||||
local sizea, sizeb = math.floor(side_length / 2), math.ceil(side_length / 2)
|
||||
local center = worldedit.pos1[name]
|
||||
worldedit.pos1[name] = vector.subtract(center, sizea)
|
||||
worldedit.pos2[name] = vector.add(center, sizeb)
|
||||
worldedit.marker_update(name)
|
||||
|
||||
-- actually run target command
|
||||
return cmddef.func(name, unpack(parsed))
|
||||
end,
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user