1
0
mirror of https://github.com/Uberi/Minetest-WorldEdit.git synced 2024-12-25 02:00:39 +01:00

Implement //cubeapply with three side lengths

This commit is contained in:
sfan5 2020-04-26 16:01:07 +02:00
parent 34844b2d38
commit 4d08a1cc55
2 changed files with 24 additions and 13 deletions

View File

@ -485,11 +485,13 @@ Note that this functionality requires the `worldedit_brush` mod enabled.
//brush spr 12 glass //brush spr 12 glass
//brush none //brush none
### `//cubeapply <size> <command> [parameters]` ### `//cubeapply <size>/(<sizex> <sizey> <sizez>) <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. Selects a cube with side length of `<size>` around the WorldEdit position 1 and runs the given `<command>` on the newly selected region.
If `<sizex>`, `<sizey>` and `<sizez>` are given, they instead specify the length of the cuboid in X, Y, Z direction.
This is mostly useful for brushes since it allows commands such as `//replace` to be ran, but it can also be used standalone. 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 //cubeapply 10 replaceinverse air default:water_source
//brush cubeapply 15 drain //brush cubeapply 15 drain
//brush cubeapply 12 3 12 drain
//brush cubeapply 1 deleteblocks //brush cubeapply 1 deleteblocks

View File

@ -209,17 +209,25 @@ worldedit.register_command("contract", {
}) })
worldedit.register_command("cubeapply", { worldedit.register_command("cubeapply", {
params = "<size> <command> [parameters]", params = "<size>/(<sizex> <sizey> <sizez>) <command> [parameters]",
description = "Select a cube with side length <size> around position 1 and run <command> on region", description = "Select a cube with side length <size> around position 1 and run <command> on region",
privs = {worldedit=true}, privs = {worldedit=true},
require_pos = 1, require_pos = 1,
parse = function(param) parse = function(param)
local found, _, side_length, cmd, args = param:find("^(%d+)%s+([^%s]+)%s*(.*)$") local found, _, sidex, sidey, sidez, cmd, args =
param:find("^(%d+)%s+(%d+)%s+(%d+)%s+([^%s]+)%s*(.*)$")
if found == nil then if found == nil then
return false found, _, sidex, cmd, args = param:find("^(%d+)%s+([^%s]+)%s*(.*)$")
if found == nil then
return false
end
sidey = sidex
sidez = sidex
end end
side_length = tonumber(side_length) sidex = tonumber(sidex)
if side_length < 1 then sidey = tonumber(sidey)
sidez = tonumber(sidez)
if sidex < 1 or sidey < 1 or sidez < 1 then
return false return false
end end
local cmddef = worldedit.registered_commands[cmd] local cmddef = worldedit.registered_commands[cmd]
@ -231,13 +239,13 @@ worldedit.register_command("cubeapply", {
if not table.remove(parsed, 1) then if not table.remove(parsed, 1) then
return false, parsed[1] return false, parsed[1]
end end
return true, side_length, cmd, parsed return true, sidex, sidey, sidez, cmd, parsed
end, end,
nodes_needed = function(name, side_length, cmd, parsed) nodes_needed = function(name, sidex, sidey, sidez, cmd, parsed)
-- its not possible to defer to the target command at this point -- its not possible to defer to the target command at this point
return side_length * side_length * side_length return sidex * sidey * sidez
end, end,
func = function(name, side_length, cmd, parsed) func = function(name, sidex, sidey, sidez, cmd, parsed)
local cmddef = assert(worldedit.registered_commands[cmd]) local cmddef = assert(worldedit.registered_commands[cmd])
local success, missing_privs = minetest.check_player_privs(name, cmddef.privs) local success, missing_privs = minetest.check_player_privs(name, cmddef.privs)
if not success then if not success then
@ -246,11 +254,12 @@ worldedit.register_command("cubeapply", {
return return
end end
-- update region to be the cube the user wanted -- update region to be the cuboid the user wanted
local sizea, sizeb = math.floor(side_length / 2), math.ceil(side_length / 2) local half = vector.divide(vector.new(sidex, sidey, sidez), 2)
local sizea, sizeb = vector.apply(half, math.floor), vector.apply(half, math.ceil)
local center = worldedit.pos1[name] local center = worldedit.pos1[name]
worldedit.pos1[name] = vector.subtract(center, sizea) worldedit.pos1[name] = vector.subtract(center, sizea)
worldedit.pos2[name] = vector.add(center, sizeb - 1) worldedit.pos2[name] = vector.add(center, vector.subtract(sizeb, 1))
worldedit.marker_update(name) worldedit.marker_update(name)
-- actually run target command -- actually run target command